10#ifndef NETWORK_CORE_ADDRESS_H
11#define NETWORK_CORE_ADDRESS_H
15#include "../../company_type.h"
16#include "../../string_func.h"
65 memset(&this->address, 0,
sizeof(this->address));
85 memset(&this->address, 0,
sizeof(this->address));
86 this->address.ss_family = family;
128 if (r == 0) r = this->address.ss_family -
address.
address.ss_family;
129 if (r == 0) r = memcmp(&this->address, &
address.
address, this->address_length);
std::vector< NetworkAddress > NetworkAddressList
Type for a list of addresses.
ServerAddressType
Types of server addresses we know.
@ SERVER_ADDRESS_INVITE_CODE
Server-address is based on an invite code.
@ SERVER_ADDRESS_DIRECT
Server-address is based on an hostname:port.
std::map< SOCKET, NetworkAddress > SocketList
Type for a mapping between address and socket.
Wrapper for (un)resolved network addresses; there's no reason to transform a numeric IP to a string a...
bool operator!=(NetworkAddress address) const
Compare the address of this class with the address of another.
static NetworkAddress GetPeerAddress(SOCKET sock)
Get the peer address of a socket as NetworkAddress.
NetworkAddress(std::string_view hostname="", uint16_t port=0, int family=AF_UNSPEC)
Create a network address based on a unresolved host and port.
static const char * AddressFamilyAsString(int family)
Convert the address family into a string.
int CompareTo(NetworkAddress &address)
Compare the address of this class with the address of another.
bool resolved
Whether the address has been (tried to be) resolved.
int GetAddressLength()
Get the (valid) length of the address.
bool operator<(NetworkAddress &address)
Compare the address of this class with the address of another.
NetworkAddress(sockaddr *address, int address_length)
Create a network address based on a resolved IP and port.
bool operator==(NetworkAddress &address)
Compare the address of this class with the address of another.
static const char * SocketTypeAsString(int socktype)
Convert the socket type into a string.
sockaddr_storage address
The resolved address.
bool IsFamily(int family)
Checks of this address is of the given family.
bool IsResolved() const
Check whether the IP address has been resolved already.
static const std::string GetPeerName(SOCKET sock)
Get the peer name of a socket in string format.
SOCKET(* LoopProc)(addrinfo *runp)
Helper function to resolve something to a socket.
static NetworkAddress GetSockAddress(SOCKET sock)
Get the local address of a socket as NetworkAddress.
bool IsInNetmask(const std::string &netmask)
Checks whether this IP address is contained by the given netmask.
std::string hostname
The hostname.
uint16_t GetPort() const
Get the port.
void Listen(int socktype, SocketList *sockets)
Make the given socket listen.
SOCKET Resolve(int family, int socktype, int flags, SocketList *sockets, LoopProc func)
Resolve this address into a socket.
void SetPort(uint16_t port)
Set the port.
NetworkAddress(struct sockaddr_storage &address, int address_length)
Create a network address based on a resolved IP and port.
const sockaddr_storage * GetAddress()
Get the address in its internal representation.
const std::string & GetHostname()
Get the hostname; in case it wasn't given the IPv4 dotted representation is given.
int address_length
The length of the resolved address.
std::string GetAddressAsString(bool with_family=true)
Get the address as a string, e.g.
Address to a game server.
std::string connection_string
The connection string for this ServerAddress.
ServerAddress(ServerAddressType type, const std::string &connection_string)
Create a new ServerAddress object.
ServerAddressType type
The type of this ServerAddress.
static ServerAddress Parse(const std::string &connection_string, uint16_t default_port, CompanyID *company_id=nullptr)
Convert a string containing either "hostname", "hostname:port" or invite code to a ServerAddress,...
Owner
Enum for all companies/owners.
Configuration options of the network stuff.
Network stuff has many things that needs to be included and/or implemented by default.