Loading...
Searching...
No Matches
util.h
Go to the documentation of this file.
1/*
2 * SPDX-FileCopyrightText: 2017 Kaspar Schleiser <kaspar@schleiser.de>
3 * SPDX-FileCopyrightText: 2018 Freie Universität Berlin
4 * SPDX-License-Identifier: LGPL-2.1-only
5 */
6
7#pragma once
8
23
24#include <stdbool.h>
25#include <stdint.h>
26
27#include "net/sock/config.h"
28
29#if MODULE_GNRC_SOCK_UDP || MODULE_LWIP_SOCK_UDP || MODULE_OPENWSN_SOCK_UDP || \
30 TESTING_MOCK_SOCK_UDP || DOXYGEN
31# include "net/sock/udp.h"
32# define SOCK_HAS_UDP 1
33#endif
34#if MODULE_GNRC_SOCK_TCP || MODULE_LWIP_SOCK_TCP || DOXYGEN
35# include "net/sock/tcp.h"
36# define SOCK_HAS_TCP 1
37#endif
38#ifdef MODULE_SOCK_DTLS
39# include "net/credman.h"
40# include "net/sock/dtls.h"
41#endif
42
43#if MODULE_GNRC_SOCK_UDP || MODULE_LWIP_SOCK_UDP || MODULE_OPENWSN_SOCK_UDP || \
44 MODULE_GNRC_SOCK_TCP || MODULE_LWIP_SOCK_TCP || TESTING_MOCK_SOCK_UDP || DOXYGEN
45# define HAVE_SOCK_TL_EP 1
46#endif
47
48#ifdef __cplusplus
49extern "C" {
50#endif
51
72int sock_urlsplit(const char *url, char *hostport, char *urlpath);
73
82const char *sock_urlpath(const char *url);
83
84#if HAVE_SOCK_TL_EP || DOXYGEN
95int sock_tl_ep_fmt(const struct _sock_tl_ep *endpoint,
96 char *addr_str, uint16_t *port);
97
98# if IS_ACTIVE(SOCK_HAS_TCP) || DOXYGEN
109static inline int sock_tcp_ep_fmt(const sock_tcp_ep_t *endpoint,
110 char *addr_str, uint16_t *port)
111{
112 return sock_tl_ep_fmt(endpoint, addr_str, port);
113}
114# endif /* SOCK_HAS_TCP */
115
116# if IS_ACTIVE(SOCK_HAS_UDP) || DOXYGEN
127static inline int sock_udp_ep_fmt(const sock_udp_ep_t *endpoint,
128 char *addr_str, uint16_t *port)
129{
130 return sock_tl_ep_fmt(endpoint, addr_str, port);
131}
132# endif /* SOCK_HAS_UDP */
133
146int sock_tl_str2ep(struct _sock_tl_ep *ep_out, const char *str);
147
162int sock_tl_name2ep(struct _sock_tl_ep *ep_out, const char *str);
163
164# if IS_ACTIVE(SOCK_HAS_TCP) || DOXYGEN
177static inline int sock_tcp_str2ep(sock_tcp_ep_t *ep_out, const char *str)
178{
179 return sock_tl_str2ep(ep_out, str);
180}
181
196static inline int sock_tcp_name2ep(sock_tcp_ep_t *ep_out, const char *str)
197{
198 return sock_tl_name2ep(ep_out, str);
199}
200# endif /* SOCK_HAS_TCP */
201
202# if IS_ACTIVE(SOCK_HAS_UDP) || DOXYGEN
215static inline int sock_udp_str2ep(sock_udp_ep_t *ep_out, const char *str)
216{
217 return sock_tl_str2ep(ep_out, str);
218}
219
234static inline int sock_udp_name2ep(sock_udp_ep_t *ep_out, const char *str)
235{
236 return sock_tl_name2ep(ep_out, str);
237}
238# endif /* SOCK_HAS_UDP */
239
253bool sock_tl_ep_equal(const struct _sock_tl_ep *a,
254 const struct _sock_tl_ep *b);
255
256# if IS_ACTIVE(SOCK_HAS_TCP) || DOXYGEN
270static inline bool sock_tcp_ep_equal(const sock_tcp_ep_t *a,
271 const sock_tcp_ep_t *b)
272{
273 return sock_tl_ep_equal(a, b);
274}
275# endif /* SOCK_HAS_TCP */
276
277# if IS_ACTIVE(SOCK_HAS_UDP) || DOXYGEN
291static inline bool sock_udp_ep_equal(const sock_udp_ep_t *a,
292 const sock_udp_ep_t *b)
293{
294 return sock_tl_ep_equal(a, b);
295}
296# endif /* SOCK_HAS_UDP */
297#endif /* HAVE_SOCK_TL_EP */
298
299#if defined(MODULE_SOCK_DTLS) || DOXYGEN
318 sock_udp_ep_t *local, const sock_udp_ep_t *remote,
319 void *work_buf, size_t work_buf_len);
320#endif /* MODULE_SOCK_DTLS */
321
322#ifdef __cplusplus
323}
324#endif
(D)TLS credentials management module definitions
uint16_t credman_tag_t
Tag of the credential.
Definition credman.h:92
struct sock_udp sock_udp_t
forward declare for async
Definition types.h:136
struct sock_dtls sock_dtls_t
forward declare for async
Definition types.h:44
struct sock_dtls_session sock_dtls_session_t
Information about a created session.
Definition dtls.h:635
struct _sock_tl_ep sock_tcp_ep_t
An end point for a TCP sock object.
Definition tcp.h:319
struct _sock_tl_ep sock_udp_ep_t
An end point for a UDP sock object.
Definition udp.h:292
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:109
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:234
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:291
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:127
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:177
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:270
static int sock_udp_str2ep(sock_udp_ep_t *ep_out, const char *str)
Convert string to UDP endpoint.
Definition util.h:215
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:196
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:211
Information about DTLS sock.
UDP sock type.
Definition sock_types.h:125