Loading...
Searching...
No Matches
util.h
Go to the documentation of this file.
1/*
2 * Copyright (C) 2017 Kaspar Schleiser <kaspar@schleiser.de>
3 * 2018 Freie Universität Berlin
4 *
5 * This file is subject to the terms and conditions of the GNU Lesser
6 * General Public License v2.1. See the file LICENSE in the top level
7 * directory for more details.
8 */
9
25#ifndef NET_SOCK_UTIL_H
26#define NET_SOCK_UTIL_H
27
28#include <stdbool.h>
29#include <stdint.h>
30
31#include "net/sock/udp.h"
32#include "net/sock/tcp.h"
33
34#ifdef MODULE_SOCK_DTLS
35#include "net/credman.h"
36#include "net/sock/dtls.h"
37#endif
38
39#ifdef __cplusplus
40extern "C" {
41#endif
42
53int sock_tl_ep_fmt(const struct _sock_tl_ep *endpoint,
54 char *addr_str, uint16_t *port);
55
66static inline int sock_tcp_ep_fmt(const sock_tcp_ep_t *endpoint,
67 char *addr_str, uint16_t *port)
68{
69 return sock_tl_ep_fmt(endpoint, addr_str, port);
70}
71
82static inline int sock_udp_ep_fmt(const sock_udp_ep_t *endpoint,
83 char *addr_str, uint16_t *port)
84{
85 return sock_tl_ep_fmt(endpoint, addr_str, port);
86}
87
108int sock_urlsplit(const char *url, char *hostport, char *urlpath);
109
118const char *sock_urlpath(const char *url);
119
132int sock_tl_str2ep(struct _sock_tl_ep *ep_out, const char *str);
133
148int sock_tl_name2ep(struct _sock_tl_ep *ep_out, const char *str);
149
162static inline int sock_tcp_str2ep(sock_tcp_ep_t *ep_out, const char *str)
163{
164 return sock_tl_str2ep(ep_out, str);
165}
166
181static inline int sock_tcp_name2ep(sock_tcp_ep_t *ep_out, const char *str)
182{
183 return sock_tl_name2ep(ep_out, str);
184}
185
198static inline int sock_udp_str2ep(sock_udp_ep_t *ep_out, const char *str)
199{
200 return sock_tl_str2ep(ep_out, str);
201}
202
217static inline int sock_udp_name2ep(sock_udp_ep_t *ep_out, const char *str)
218{
219 return sock_tl_name2ep(ep_out, str);
220}
221
235bool sock_tl_ep_equal(const struct _sock_tl_ep *a,
236 const struct _sock_tl_ep *b);
237
251static inline bool sock_tcp_ep_equal(const sock_tcp_ep_t *a,
252 const sock_tcp_ep_t *b)
253{
254 return sock_tl_ep_equal(a, b);
255}
256
270static inline bool sock_udp_ep_equal(const sock_udp_ep_t *a,
271 const sock_udp_ep_t *b)
272{
273 return sock_tl_ep_equal(a, b);
274}
275
276#if defined(MODULE_SOCK_DTLS) || DOXYGEN
295 sock_udp_ep_t *local, const sock_udp_ep_t *remote,
296 void *work_buf, size_t work_buf_len);
297#endif
298
309#ifndef CONFIG_SOCK_SCHEME_MAXLEN
310#define CONFIG_SOCK_SCHEME_MAXLEN (16U)
311#endif
312
316#ifndef CONFIG_SOCK_HOSTPORT_MAXLEN
317#define CONFIG_SOCK_HOSTPORT_MAXLEN (64U)
318#endif
319
323#ifndef CONFIG_SOCK_URLPATH_MAXLEN
324#define CONFIG_SOCK_URLPATH_MAXLEN (64U)
325#endif
331#ifndef CONFIG_SOCK_DTLS_TIMEOUT_MS
332#define CONFIG_SOCK_DTLS_TIMEOUT_MS (1000U)
333#endif
334
338#ifndef CONFIG_SOCK_DTLS_RETRIES
339#define CONFIG_SOCK_DTLS_RETRIES (2)
340#endif
341
342#ifdef __cplusplus
343}
344#endif
345
346#endif /* NET_SOCK_UTIL_H */
(D)TLS credentials management module definitions
uint16_t credman_tag_t
Tag of the credential.
Definition credman.h:96
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 int sock_tcp_ep_fmt(const sock_tcp_ep_t *endpoint, char *addr_str, uint16_t *port)
Format TCP endpoint to string and port.
Definition util.h:66
int sock_tl_str2ep(struct _sock_tl_ep *ep_out, const char *str)
Convert string to common IP-based transport layer 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 no...
Definition util.h:217
static bool sock_udp_ep_equal(const sock_udp_ep_t *a, const sock_udp_ep_t *b)
Compare the two given UDP endpoints.
Definition util.h:270
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,...
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.
Definition util.h:82
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.
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.
int sock_urlsplit(const char *url, char *hostport, char *urlpath)
Split url to host:port and url path.
static int sock_tcp_str2ep(sock_tcp_ep_t *ep_out, const char *str)
Convert string to TCP endpoint.
Definition util.h:162
static bool sock_tcp_ep_equal(const sock_tcp_ep_t *a, const sock_tcp_ep_t *b)
Compare the two given TCP endpoints.
Definition util.h:251
static int sock_udp_str2ep(sock_udp_ep_t *ep_out, const char *str)
Convert string to UDP endpoint.
Definition util.h:198
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 no...
Definition util.h:181
const char * sock_urlpath(const char *url)
Returns a pointer to the path component in url.
DTLS sock definitions.
TCP sock definitions.
UDP sock definitions.
Common IP-based transport layer end point.
Definition sock.h:215
Information about remote client connected to the server.
Information about DTLS sock.
UDP sock type.
Definition sock_types.h:128