sock utility functions

sock utility function More...

Detailed Description

Files

file  util.h
 sock utility function definitions
 

Functions

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

#define SOCK_HOSTPORT_MAXLEN   (64U)
 maximum length of host:port part for sock_urlsplit()
 
#define SOCK_URLPATH_MAXLEN   (64U)
 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 
)
Parameters
[in]endpointendpoint to format
[out]addr_strwhere to write address as string
[out]portwhere to write prt number as uint16_t
Returns
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 
)

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

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

◆ sock_urlsplit()

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

Will split e.g., "https://host.name:1234/url/path" into "host.name:1234" and "/url/path".

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