DDraceNetwork Documentation
Loading...
Searching...
No Matches
General networking
Collaboration diagram for General networking:

Classes

struct  NETADDR
struct  NETSTATS

Typedefs

typedef int UNIXSOCKET
typedef struct sockaddr_un UNIXSOCKETADDR
typedef struct NETSOCKET_INTERNALNETSOCKET
typedef struct NETADDR NETADDR
typedef struct NETSTATS NETSTATS

Functions

void net_init ()
int net_host_lookup (const char *hostname, NETADDR *addr, int types)
int net_addr_comp (const NETADDR *a, const NETADDR *b)
int net_addr_comp_noport (const NETADDR *a, const NETADDR *b)
void net_addr_str (const NETADDR *addr, char *string, int max_length, bool add_port)
int net_addr_from_url (NETADDR *addr, const char *string, char *host_buf, size_t host_buf_size)
bool net_addr_is_local (const NETADDR *addr)
int net_addr_from_str (NETADDR *addr, const char *string)
int net_set_non_blocking (NETSOCKET sock)
int net_errno ()
std::string net_error_message ()
int net_would_block ()
int net_socket_read_wait (NETSOCKET sock, std::chrono::nanoseconds nanoseconds)
int net_socket_type (NETSOCKET sock)

Variables

const NETADDR NETADDR_ZEROED

Detailed Description

Typedef Documentation

◆ NETADDR

typedef struct NETADDR NETADDR

◆ NETSOCKET

typedef struct NETSOCKET_INTERNAL* NETSOCKET

◆ NETSTATS

typedef struct NETSTATS NETSTATS

◆ UNIXSOCKET

typedef int UNIXSOCKET

◆ UNIXSOCKETADDR

typedef struct sockaddr_un UNIXSOCKETADDR

Function Documentation

◆ net_addr_comp()

int net_addr_comp ( const NETADDR * a,
const NETADDR * b )

Compares two network addresses.

Parameters
aAddress to compare.
bAddress to compare to.
Returns
< 0 if address a is less than address b.
0 if address a is equal to address b.
> 0 if address a is greater than address b.

◆ net_addr_comp_noport()

int net_addr_comp_noport ( const NETADDR * a,
const NETADDR * b )

Compares two network addresses ignoring port.

Parameters
aAddress to compare.
bAddress to compare to.
Returns
< 0 if address a is less than address b.
0 if address a is equal to address b.
> 0 if address a is greater than address b.

◆ net_addr_from_str()

int net_addr_from_str ( NETADDR * addr,
const char * string )

Turns string into a network address.

Parameters
addrAddress to fill in.
stringString to parse.
Returns
0 on success.

◆ net_addr_from_url()

int net_addr_from_url ( NETADDR * addr,
const char * string,
char * host_buf,
size_t host_buf_size )

Turns url string into a network address struct. The url format is tw-0.6+udp://{ipaddr}[:{port}] ipaddr: can be ipv4 or ipv6 port: is a optional internet protocol port

This format is used for parsing the master server, be careful before changing it.

Examples: tw-0.6+udp://127.0.0.1 tw-0.6+udp://127.0.0.1:8303

Parameters
addrAddress to fill in.
stringString to parse.
host_bufPointer to a buffer to write the host to It will include the port if one is included in the url It can also be set to nullptr then it will be ignored.
host_buf_sizeSize of the host buffer or 0 if no host_buf pointer is given.
Returns
0 on success.
> 0 if the input wasn't a valid DDNet URL,
< 0 if the input is a valid DDNet URL but the host part was not a valid IPv4/IPv6 address

◆ net_addr_is_local()

bool net_addr_is_local ( const NETADDR * addr)

Checks if an address is local.

Parameters
addrAddress to check.
Returns
true if the address is local, false otherwise.

◆ net_addr_str()

void net_addr_str ( const NETADDR * addr,
char * string,
int max_length,
bool add_port )

Turns a network address into a representative string.

Parameters
addrAddress to turn into a string.
stringBuffer to fill with the string.
max_lengthMaximum size of the string.
add_portWhether to add the port to the string.
Remarks
The string will always be null-terminated.

◆ net_errno()

int net_errno ( )

If a network operation failed, the error code.

Returns
The error code.

◆ net_error_message()

std::string net_error_message ( )

If a network operation failed, the platform-specific error code and string.

Returns
The error code and string combined into one string.

◆ net_host_lookup()

int net_host_lookup ( const char * hostname,
NETADDR * addr,
int types )

Looks up the ip of a hostname.

Parameters
hostnameHost name to look up.
addrThe output address to write to.
typesThe type of IP that should be returned.
Returns
0 on success.

◆ net_init()

void net_init ( )

Initiates network functionality.

Remarks
You must call this function before using any other network functions.

◆ net_set_non_blocking()

int net_set_non_blocking ( NETSOCKET sock)

Make a socket not block on operations

Parameters
sockThe socket to set the mode on.
Returns
0 on success.

◆ net_socket_read_wait()

int net_socket_read_wait ( NETSOCKET sock,
std::chrono::nanoseconds nanoseconds )

Waits for a socket to have data available to receive up the specified timeout duration.

Parameters
sockSocket to wait on.
nanosecondsTimeout duration to wait.
Returns
1 if data was received within the timeout duration, 0 otherwise.

◆ net_socket_type()

int net_socket_type ( NETSOCKET sock)

Determine a socket's type.

Parameters
sockSocket whose type should be determined.
Returns
The socket type, a bitset of NETTYPE_IPV4, NETTYPE_IPV6, NETTYPE_WEBSOCKET_IPV4 and NETTYPE_WEBSOCKET_IPV6, or NETTYPE_INVALID if the socket is invalid.

◆ net_would_block()

int net_would_block ( )

Determines whether a network operation would block.

Returns
0 if wouldn't block, 1 if would block.

Variable Documentation

◆ NETADDR_ZEROED

const NETADDR NETADDR_ZEROED
extern