Go to the documentation of this file.
10 #ifndef NETWORK_CORE_ADDRESS_H
11 #define NETWORK_CORE_ADDRESS_H
15 #include "../../string_func.h"
16 #include "../../core/smallmap_type.hpp"
55 *this->hostname =
'\0';
67 *this->hostname =
'\0';
68 memset(&this->address, 0,
sizeof(this->address));
86 char *tmp = strrchr(this->hostname,
']');
87 if (tmp !=
nullptr) *tmp =
'\0';
89 memset(&this->address, 0,
sizeof(this->address));
90 this->address.ss_family = family;
133 if (r == 0) r = this->address.ss_family -
address.address.ss_family;
134 if (r == 0) r = memcmp(&this->address, &
address.address, this->address_length);
SOCKET Connect()
Connect to the given address.
SmallMap< NetworkAddress, SOCKET > SocketList
Type for a mapping between address and socket.
const sockaddr_storage * GetAddress()
Get the address in its internal representation.
int GetAddressLength()
Get the (valid) length of the address.
void SetPort(uint16 port)
Set the port.
SOCKET Resolve(int family, int socktype, int flags, SocketList *sockets, LoopProc func)
Resolve this address into a socket.
bool resolved
Whether the address has been (tried to be) resolved.
bool IsInNetmask(const char *netmask)
Checks whether this IP address is contained by the given netmask.
bool operator!=(NetworkAddress address) const
Compare the address of this class with the address of another.
std::vector< NetworkAddress > NetworkAddressList
Type for a list of addresses.
const char * GetHostname()
Get the hostname; in case it wasn't given the IPv4 dotted representation is given.
uint16 GetPort() const
Get the port.
int address_length
The length of the resolved address.
static bool StrEmpty(const char *s)
Check if a string buffer is empty.
NetworkAddress(struct sockaddr_storage &address, int address_length)
Create a network address based on a resolved IP and port.
NetworkAddress(const char *hostname="", uint16 port=0, int family=AF_UNSPEC)
Create a network address based on a unresolved host and port.
bool operator==(NetworkAddress &address)
Compare the address of this class with the address of another.
Wrapper for (un)resolved network addresses; there's no reason to transform a numeric IP to a string a...
char hostname[NETWORK_HOSTNAME_LENGTH]
The hostname.
bool IsResolved() const
Check whether the IP address has been resolved already.
int CompareTo(NetworkAddress &address)
Compare the address of this class with the address of another.
SOCKET(* LoopProc)(addrinfo *runp)
Helper function to resolve something to a socket.
NetworkAddress(sockaddr *address, int address_length)
Create a network address based on a resolved IP and port.
static const char * SocketTypeAsString(int socktype)
Convert the socket type into a string.
bool IsFamily(int family)
Checks of this address is of the given family.
static const uint NETWORK_HOSTNAME_LENGTH
The maximum length of the host name, in bytes including '\0'.
char * strecpy(char *dst, const char *src, const char *last)
Copies characters from one buffer to another.
static const char * AddressFamilyAsString(int family)
Convert the address family into a string.
#define lastof(x)
Get the last element of an fixed size array.
bool operator<(NetworkAddress &address)
Compare the address of this class with the address of another.
void Listen(int socktype, SocketList *sockets)
Make the given socket listen.
void GetAddressAsString(char *buffer, const char *last, bool with_family=true)
Get the address as a string, e.g.
sockaddr_storage address
The resolved address.