sock utility functions¶
sock utility function
-
SOCK_SCHEME_MAXLEN
¶ maximum length of the scheme part for sock_urlsplit.
1
(16U)
Ensures a hard limit on the string iterator
-
SOCK_HOSTPORT_MAXLEN
¶ maximum length of host:port part for
util.h::sock_urlsplit()
1
(64U)
-
SOCK_URLPATH_MAXLEN
¶ maximum length path for
util.h::sock_urlsplit()
1
(64U)
-
int
sock_udp_ep_fmt
(constsock/udp.h::sock_udp_ep_t
* endpoint, char * addr_str, uint16_t * port)¶ Format UDP endpoint to string and port.
Parameters
endpoint: endpoint to format addr_str: where to write address as string port: where to write prt number as uint16_t Return values
- number of bytes written to
addr_str
on success - <0 otherwise
- number of bytes written to
-
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
util.h::SOCK_HOSTPORT_MAXLEN
respectivelyutil.h::SOCK_URLPATH_MAXLEN
bytes. Scheme part of the URL is limited toutil.h::SOCK_SCHEME_MAXLEN
length.Parameters
url: URL to split hostport: where to write host:port urlpath: where to write url path Return values
- 0 on success
- <0 otherwise
-
int
sock_udp_str2ep
(sock/udp.h::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.
Parameters
ep_out: endpoint structure to fill str: string to read from Return values
- 0 on success
- <0 otherwise
-
bool
sock_udp_ep_equal
(constsock/udp.h::sock_udp_ep_t
* a, constsock/udp.h::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.
Parameters
a: Endpoint A b: Endpoint B Return values
- 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