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...

helper definitions

 maximum length of host:port part for sock_urlsplit()
 maximum length path for sock_urlsplit()

Function Documentation

◆ 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.
[in]urlURL to split
[out]hostportwhere to write host:port
[out]urlpathwhere to write url path
0 on success
<0 otherwise