OpenTTD Source
20240919-master-gdf0233f4c2
|
Go to the documentation of this file.
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::string hostname
The hostname.
const sockaddr_storage * GetAddress()
Get the address in its internal representation.
int GetAddressLength()
Get the (valid) length of the address.
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.
Owner
Enum for all companies/owners.
uint16_t GetPort() const
Get the port.
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,...
bool IsInNetmask(const std::string &netmask)
Checks whether this IP address is contained by the given netmask.
std::map< SOCKET, NetworkAddress > SocketList
Type for a mapping between address and socket.
static NetworkAddress GetPeerAddress(SOCKET sock)
Get the peer address of a socket as NetworkAddress.
static NetworkAddress GetSockAddress(SOCKET sock)
Get the local address of a socket as NetworkAddress.
ServerAddressType type
The type of this ServerAddress.
static const std::string GetPeerName(SOCKET sock)
Get the peer name of a socket in string format.
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.
NetworkAddress(std::string_view hostname="", uint16_t port=0, int family=AF_UNSPEC)
Create a network address based on a unresolved host and port.
@ SERVER_ADDRESS_DIRECT
Server-address is based on an hostname:port.
int address_length
The length of the resolved address.
ServerAddressType
Types of server addresses we know.
NetworkAddress(struct sockaddr_storage &address, int address_length)
Create a network address based on a resolved IP and port.
std::string GetAddressAsString(bool with_family=true)
Get the address as a string, e.g.
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...
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.
const std::string & GetHostname()
Get the hostname; in case it wasn't given the IPv4 dotted representation is given.
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.
@ SERVER_ADDRESS_INVITE_CODE
Server-address is based on an invite code.
bool IsFamily(int family)
Checks of this address is of the given family.
static const char * AddressFamilyAsString(int family)
Convert the address family into a string.
std::string connection_string
The connection string for this ServerAddress.
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.
Address to a game server.
ServerAddress(ServerAddressType type, const std::string &connection_string)
Create a new ServerAddress object.
void SetPort(uint16_t port)
Set the port.
sockaddr_storage address
The resolved address.