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 || DOXYGEN
30# include "net/sock/udp.h"
31# define SOCK_HAS_UDP 1
32#endif
33#if MODULE_GNRC_SOCK_TCP || MODULE_LWIP_SOCK_TCP || DOXYGEN
34# include "net/sock/tcp.h"
35# define SOCK_HAS_TCP 1
36#endif
37#ifdef MODULE_SOCK_DTLS
38# include "net/credman.h"
39# include "net/sock/dtls.h"
40#endif
41
42#if MODULE_GNRC_SOCK_UDP || MODULE_LWIP_SOCK_UDP || MODULE_OPENWSN_SOCK_UDP \
43 || MODULE_GNRC_SOCK_TCP || MODULE_LWIP_SOCK_TCP || DOXYGEN
44# define HAVE_SOCK_TL_EP 1
45#endif
46
47#ifdef __cplusplus
48extern "C" {
49#endif
50
71int sock_urlsplit(const char *url, char *hostport, char *urlpath);
72
81const char *sock_urlpath(const char *url);
82
83#if HAVE_SOCK_TL_EP
94int sock_tl_ep_fmt(const struct _sock_tl_ep *endpoint,
95 char *addr_str, uint16_t *port);
96
97#if IS_ACTIVE(SOCK_HAS_TCP) || DOXYGEN
108static inline int sock_tcp_ep_fmt(const sock_tcp_ep_t *endpoint,
109 char *addr_str, uint16_t *port)
110{
111 return sock_tl_ep_fmt(endpoint, addr_str, port);
112}
113#endif
114
115#if IS_ACTIVE(SOCK_HAS_UDP) || DOXYGEN
126static inline int sock_udp_ep_fmt(const sock_udp_ep_t *endpoint,
127 char *addr_str, uint16_t *port)
128{
129 return sock_tl_ep_fmt(endpoint, addr_str, port);
130}
131#endif
132
145int sock_tl_str2ep(struct _sock_tl_ep *ep_out, const char *str);
146
161int sock_tl_name2ep(struct _sock_tl_ep *ep_out, const char *str);
162
163#if IS_ACTIVE(SOCK_HAS_TCP) || DOXYGEN
176static inline int sock_tcp_str2ep(sock_tcp_ep_t *ep_out, const char *str)
177{
178 return sock_tl_str2ep(ep_out, str);
179}
180
195static inline int sock_tcp_name2ep(sock_tcp_ep_t *ep_out, const char *str)
196{
197 return sock_tl_name2ep(ep_out, str);
198}
199#endif
200
201#if IS_ACTIVE(SOCK_HAS_UDP) || DOXYGEN
214static inline int sock_udp_str2ep(sock_udp_ep_t *ep_out, const char *str)
215{
216 return sock_tl_str2ep(ep_out, str);
217}
218
233static inline int sock_udp_name2ep(sock_udp_ep_t *ep_out, const char *str)
234{
235 return sock_tl_name2ep(ep_out, str);
236}
237#endif
238
252bool sock_tl_ep_equal(const struct _sock_tl_ep *a,
253 const struct _sock_tl_ep *b);
254
255#if IS_ACTIVE(SOCK_HAS_TCP) || DOXYGEN
269static inline bool sock_tcp_ep_equal(const sock_tcp_ep_t *a,
270 const sock_tcp_ep_t *b)
271{
272 return sock_tl_ep_equal(a, b);
273}
274#endif
275
276#if IS_ACTIVE(SOCK_HAS_UDP) || DOXYGEN
290static inline bool sock_udp_ep_equal(const sock_udp_ep_t *a,
291 const sock_udp_ep_t *b)
292{
293 return sock_tl_ep_equal(a, b);
294}
295#endif
296#endif
297
298#if defined(MODULE_SOCK_DTLS) || DOXYGEN
317 sock_udp_ep_t *local, const sock_udp_ep_t *remote,
318 void *work_buf, size_t work_buf_len);
319#endif
320
321#ifdef __cplusplus
322}
323#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
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_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.
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:128