Loading...
Searching...
No Matches
sock utility functions

sock utility function More...

Detailed Description

sock utility function

Files

file  util.h
 sock utility function definitions
 

Functions

int sock_tl_ep_fmt (const struct _sock_tl_ep *endpoint, char *addr_str, uint16_t *port)
 Format common IP-based transport layer endpoint to string and port.
 
static int sock_tcp_ep_fmt (const sock_tcp_ep_t *endpoint, char *addr_str, uint16_t *port)
 Format TCP endpoint to string and port.
 
static int sock_udp_ep_fmt (const sock_udp_ep_t *endpoint, char *addr_str, uint16_t *port)
 Format UDP endpoint to string and port.
 
int sock_urlsplit (const char *url, char *hostport, char *urlpath)
 Split url to host:port and url path.
 
const char * sock_urlpath (const char *url)
 Returns a pointer to the path component in url.
 
int sock_tl_str2ep (struct _sock_tl_ep *ep_out, const char *str)
 Convert string to common IP-based transport layer endpoint.
 
int sock_tl_name2ep (struct _sock_tl_ep *ep_out, const char *str)
 Convert string to common IP-based transport layer endpoint If the sock_dns module is used, this will do a DNS lookup if str is not an IP address.
 
static int sock_tcp_str2ep (sock_tcp_ep_t *ep_out, const char *str)
 Convert string to TCP endpoint.
 
static int sock_tcp_name2ep (sock_tcp_ep_t *ep_out, const char *str)
 Convert string to TCP endpoint If the sock_dns module is used, this will do a DNS lookup if str is not an IP address.
 
static int sock_udp_str2ep (sock_udp_ep_t *ep_out, const char *str)
 Convert string to UDP endpoint.
 
static int sock_udp_name2ep (sock_udp_ep_t *ep_out, const char *str)
 Convert string to UDP endpoint If the sock_dns module is used, this will do a DNS lookup if str is not an IP address.
 
bool sock_tl_ep_equal (const struct _sock_tl_ep *a, const struct _sock_tl_ep *b)
 Compare the two given common IP-based transport layer endpoints.
 
static bool sock_tcp_ep_equal (const sock_tcp_ep_t *a, const sock_tcp_ep_t *b)
 Compare the two given TCP endpoints.
 
static bool sock_udp_ep_equal (const sock_udp_ep_t *a, const sock_udp_ep_t *b)
 Compare the two given UDP endpoints.
 
int sock_dtls_establish_session (sock_udp_t *sock_udp, sock_dtls_t *sock_dtls, sock_dtls_session_t *session, credman_tag_t tag, sock_udp_ep_t *local, const sock_udp_ep_t *remote, void *work_buf, size_t work_buf_len)
 Helper function to establish a DTLS connection.
 

Function Documentation

◆ sock_dtls_establish_session()

int sock_dtls_establish_session ( sock_udp_t sock_udp,
sock_dtls_t sock_dtls,
sock_dtls_session_t session,
credman_tag_t  tag,
sock_udp_ep_t local,
const sock_udp_ep_t remote,
void *  work_buf,
size_t  work_buf_len 
)

Helper function to establish a DTLS connection.

Parameters
[out]sock_udpStruct to store the underlying UDP socket
[out]sock_dtlsStruct for the actual DTLS socket
[out]sessionStruct to store DTLS session information
[in]tagCredential tag to use
[in]localLocal endpoint, must not be NULL
[in]remoteServer endpoint to connect to
[in]work_bufBuffer used to negotiate connection
[in]work_buf_lenSize of work buf. Should be at least 160 bytes for AES_128_CCM_8 with PSK
Returns
0 on success
negative error otherwise (see sock_dtls_recv_aux)

◆ sock_tcp_ep_equal()

static bool sock_tcp_ep_equal ( const sock_tcp_ep_t a,
const sock_tcp_ep_t b 
)
inlinestatic

Compare the two given TCP endpoints.

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

Parameters
[in]aEndpoint A
[in]bEndpoint B
Returns
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

Definition at line 252 of file util.h.

◆ sock_tcp_ep_fmt()

static int sock_tcp_ep_fmt ( const sock_tcp_ep_t endpoint,
char *  addr_str,
uint16_t *  port 
)
inlinestatic

Format TCP endpoint to string and port.

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

Definition at line 67 of file util.h.

◆ sock_tcp_name2ep()

static int sock_tcp_name2ep ( sock_tcp_ep_t ep_out,
const char *  str 
)
inlinestatic

Convert string to TCP endpoint If the sock_dns module is used, this will do a DNS lookup if str is not an IP address.

Takes eg., "exampl.com:80" or "[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

Definition at line 182 of file util.h.

◆ sock_tcp_str2ep()

static int sock_tcp_str2ep ( sock_tcp_ep_t ep_out,
const char *  str 
)
inlinestatic

Convert string to TCP endpoint.

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

Definition at line 163 of file util.h.

◆ sock_tl_ep_equal()

bool sock_tl_ep_equal ( const struct _sock_tl_ep a,
const struct _sock_tl_ep b 
)

Compare the two given common IP-based transport layer endpoints.

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

Parameters
[in]aEndpoint A
[in]bEndpoint B
Returns
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_tl_ep_fmt()

int sock_tl_ep_fmt ( const struct _sock_tl_ep endpoint,
char *  addr_str,
uint16_t *  port 
)

Format common IP-based transport layer endpoint to string and port.

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

◆ sock_tl_name2ep()

int sock_tl_name2ep ( struct _sock_tl_ep ep_out,
const char *  str 
)

Convert string to common IP-based transport layer endpoint If the sock_dns module is used, this will do a DNS lookup if str is not an IP address.

Takes eg., "riot-os.org:1234" and converts it into the corresponding endpoint structure.

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

◆ sock_tl_str2ep()

int sock_tl_str2ep ( struct _sock_tl_ep ep_out,
const char *  str 
)

Convert string to common IP-based transport layer endpoint.

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_udp_ep_equal()

static bool sock_udp_ep_equal ( const sock_udp_ep_t a,
const sock_udp_ep_t b 
)
inlinestatic

Compare the two given UDP endpoints.

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

Parameters
[in]aEndpoint A
[in]bEndpoint B
Returns
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

Definition at line 271 of file util.h.

◆ sock_udp_ep_fmt()

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

Format UDP endpoint to string and port.

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

Definition at line 83 of file util.h.

◆ sock_udp_name2ep()

static int sock_udp_name2ep ( sock_udp_ep_t ep_out,
const char *  str 
)
inlinestatic

Convert string to UDP endpoint If the sock_dns module is used, this will do a DNS lookup if str is not an IP address.

Takes eg., "exampl.com:80" or "[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

Definition at line 218 of file util.h.

◆ sock_udp_str2ep()

static int sock_udp_str2ep ( sock_udp_ep_t ep_out,
const char *  str 
)
inlinestatic

Convert string to UDP endpoint.

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

Definition at line 199 of file util.h.

◆ sock_urlpath()

const char * sock_urlpath ( const char *  url)

Returns a pointer to the path component in url.

Parameters
[in]urlURL to examine. Must not be NULL.
Returns
pointer to the start of the path component in url
NULL if url is invalid

◆ sock_urlsplit()

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

Split url to host:port and url path.

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 CONFIG_SOCK_HOSTPORT_MAXLEN respectively CONFIG_SOCK_URLPATH_MAXLEN bytes, if pointers are not NULL. Scheme part of the URL is limited to CONFIG_SOCK_SCHEME_MAXLEN length.
Precondition
url != NULL
Parameters
[in]urlURL to split. Must not be NULL.
[out]hostportwhere to write host:port. Can be NULL.
[out]urlpathwhere to write url path. Can be NULL.
Returns
0 on success
<0 otherwise