sock utility functions

sock utility function More...

Detailed Description

sock utility function


file  util.h
 sock utility function definitions


int sock_udp_ep_fmt (const sock_udp_ep_t *endpoint, char *addr_str, uint16_t *port)
 Format UDP endpoint to string and port. More...
int sock_urlsplit (const char *url, char *hostport, char *urlpath)
 Split url to host:port and url path. More...
int sock_udp_str2ep (sock_udp_ep_t *ep_out, const char *str)
 Convert string to UDP endpoint. More...
bool sock_udp_ep_equal (const sock_udp_ep_t *a, const sock_udp_ep_t *b)
 Compare the two given UDP endpoints. More...

helper definitions

#define SOCK_SCHEME_MAXLEN   (16U)
 maximum length of the scheme part for sock_urlsplit. More...
 maximum length of host:port part for sock_urlsplit()
 maximum length path for sock_urlsplit()

Macro Definition Documentation


#define SOCK_SCHEME_MAXLEN   (16U)

maximum length of the scheme part for sock_urlsplit.

Ensures a hard limit on the string iterator

Definition at line 102 of file util.h.

Function Documentation

◆ sock_udp_ep_equal()

bool sock_udp_ep_equal ( const sock_udp_ep_t a,
const sock_udp_ep_t b 

Compare the two given UDP endpoints.

The given endpoint identifiers are compared by checking their address family, their addresses, and their port value.

[in]aEndpoint A
[in]bEndpoint B
true if given endpoint identifiers point to the same destination
false if given endpoint identifiers do not point to the same destination, or if the address family is unknown

◆ sock_udp_ep_fmt()

int sock_udp_ep_fmt ( const sock_udp_ep_t endpoint,
char *  addr_str,
uint16_t *  port 

Format UDP endpoint to string and port.

[in]endpointendpoint to format
[out]addr_strwhere to write address as string
[out]portwhere to write prt number as uint16_t
number of bytes written to addr_str on success
<0 otherwise

◆ sock_udp_str2ep()

int sock_udp_str2ep ( sock_udp_ep_t ep_out,
const char *  str 

Convert string to UDP endpoint.

Takes eg., "[2001:db8::1]:1234" and converts it into the corresponding UDP endpoint structure.

[out]ep_outendpoint structure to fill
[in]strstring to read from
0 on success
<0 otherwise

◆ sock_urlsplit()

int sock_urlsplit ( const char *  url,
char *  hostport,
char *  urlpath 

Split url to host:port and url path.

Will split e.g., "" into "" and "/url/path".

Caller has to make sure hostport and urlpath can hold the results! Make sure to provide space for SOCK_HOSTPORT_MAXLEN respectively SOCK_URLPATH_MAXLEN bytes. Scheme part of the URL is limited to SOCK_SCHEME_MAXLEN length.
[in]urlURL to split
[out]hostportwhere to write host:port
[out]urlpathwhere to write url path
0 on success
<0 otherwise