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
10#pragma once
11
26
27#include <stdbool.h>
28#include <stdint.h>
29
30#include "net/sock/config.h"
31
32#if MODULE_GNRC_SOCK_UDP || MODULE_LWIP_SOCK_UDP || DOXYGEN
33# include "net/sock/udp.h"
34# define SOCK_HAS_UDP 1
35#endif
36#if MODULE_GNRC_SOCK_TCP || MODULE_LWIP_SOCK_TCP || DOXYGEN
37# include "net/sock/tcp.h"
38# define SOCK_HAS_TCP 1
39#endif
40#ifdef MODULE_SOCK_DTLS
41# include "net/credman.h"
42# include "net/sock/dtls.h"
43#endif
44
45#if MODULE_GNRC_SOCK_UDP || MODULE_LWIP_SOCK_UDP ||MODULE_GNRC_SOCK_TCP || MODULE_LWIP_SOCK_TCP || DOXYGEN
46# define HAVE_SOCK_TL_EP 1
47#endif
48
49#ifdef __cplusplus
50extern "C" {
51#endif
52
73int sock_urlsplit(const char *url, char *hostport, char *urlpath);
74
83const char *sock_urlpath(const char *url);
84
85#if HAVE_SOCK_TL_EP
96int sock_tl_ep_fmt(const struct _sock_tl_ep *endpoint,
97 char *addr_str, uint16_t *port);
98
99#if IS_ACTIVE(SOCK_HAS_TCP) || DOXYGEN
110static inline int sock_tcp_ep_fmt(const sock_tcp_ep_t *endpoint,
111 char *addr_str, uint16_t *port)
112{
113 return sock_tl_ep_fmt(endpoint, addr_str, port);
114}
115#endif
116
117#if IS_ACTIVE(SOCK_HAS_UDP) || DOXYGEN
128static inline int sock_udp_ep_fmt(const sock_udp_ep_t *endpoint,
129 char *addr_str, uint16_t *port)
130{
131 return sock_tl_ep_fmt(endpoint, addr_str, port);
132}
133#endif
134
147int sock_tl_str2ep(struct _sock_tl_ep *ep_out, const char *str);
148
163int sock_tl_name2ep(struct _sock_tl_ep *ep_out, const char *str);
164
165#if IS_ACTIVE(SOCK_HAS_TCP) || DOXYGEN
178static inline int sock_tcp_str2ep(sock_tcp_ep_t *ep_out, const char *str)
179{
180 return sock_tl_str2ep(ep_out, str);
181}
182
197static inline int sock_tcp_name2ep(sock_tcp_ep_t *ep_out, const char *str)
198{
199 return sock_tl_name2ep(ep_out, str);
200}
201#endif
202
203#if IS_ACTIVE(SOCK_HAS_UDP) || DOXYGEN
216static inline int sock_udp_str2ep(sock_udp_ep_t *ep_out, const char *str)
217{
218 return sock_tl_str2ep(ep_out, str);
219}
220
235static inline int sock_udp_name2ep(sock_udp_ep_t *ep_out, const char *str)
236{
237 return sock_tl_name2ep(ep_out, str);
238}
239#endif
240
254bool sock_tl_ep_equal(const struct _sock_tl_ep *a,
255 const struct _sock_tl_ep *b);
256
257#if IS_ACTIVE(SOCK_HAS_TCP) || DOXYGEN
271static inline bool sock_tcp_ep_equal(const sock_tcp_ep_t *a,
272 const sock_tcp_ep_t *b)
273{
274 return sock_tl_ep_equal(a, b);
275}
276#endif
277
278#if IS_ACTIVE(SOCK_HAS_UDP) || DOXYGEN
292static inline bool sock_udp_ep_equal(const sock_udp_ep_t *a,
293 const sock_udp_ep_t *b)
294{
295 return sock_tl_ep_equal(a, b);
296}
297#endif
298#endif
299
300#if defined(MODULE_SOCK_DTLS) || DOXYGEN
319 sock_udp_ep_t *local, const sock_udp_ep_t *remote,
320 void *work_buf, size_t work_buf_len);
321#endif
322
323#ifdef __cplusplus
324}
325#endif
(D)TLS credentials management module definitions
uint16_t credman_tag_t
Tag of the credential.
Definition credman.h:95
struct sock_udp sock_udp_t
forward declare for async
Definition types.h:139
struct sock_dtls sock_dtls_t
forward declare for async
Definition types.h:47
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:320
struct _sock_tl_ep sock_udp_ep_t
An end point for a UDP sock object.
Definition udp.h:293
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:214
Information about DTLS sock.
UDP sock type.
Definition sock_types.h:128