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#include "net/sock/config.h"
34
35#ifdef MODULE_SOCK_DTLS
36#include "net/credman.h"
37#include "net/sock/dtls.h"
38#endif
39
40#ifdef __cplusplus
41extern "C" {
42#endif
43
54int sock_tl_ep_fmt(const struct _sock_tl_ep *endpoint,
55 char *addr_str, uint16_t *port);
56
67static inline int sock_tcp_ep_fmt(const sock_tcp_ep_t *endpoint,
68 char *addr_str, uint16_t *port)
69{
70 return sock_tl_ep_fmt(endpoint, addr_str, port);
71}
72
83static inline int sock_udp_ep_fmt(const sock_udp_ep_t *endpoint,
84 char *addr_str, uint16_t *port)
85{
86 return sock_tl_ep_fmt(endpoint, addr_str, port);
87}
88
109int sock_urlsplit(const char *url, char *hostport, char *urlpath);
110
119const char *sock_urlpath(const char *url);
120
133int sock_tl_str2ep(struct _sock_tl_ep *ep_out, const char *str);
134
149int sock_tl_name2ep(struct _sock_tl_ep *ep_out, const char *str);
150
163static inline int sock_tcp_str2ep(sock_tcp_ep_t *ep_out, const char *str)
164{
165 return sock_tl_str2ep(ep_out, str);
166}
167
182static inline int sock_tcp_name2ep(sock_tcp_ep_t *ep_out, const char *str)
183{
184 return sock_tl_name2ep(ep_out, str);
185}
186
199static inline int sock_udp_str2ep(sock_udp_ep_t *ep_out, const char *str)
200{
201 return sock_tl_str2ep(ep_out, str);
202}
203
218static inline int sock_udp_name2ep(sock_udp_ep_t *ep_out, const char *str)
219{
220 return sock_tl_name2ep(ep_out, str);
221}
222
236bool sock_tl_ep_equal(const struct _sock_tl_ep *a,
237 const struct _sock_tl_ep *b);
238
252static inline bool sock_tcp_ep_equal(const sock_tcp_ep_t *a,
253 const sock_tcp_ep_t *b)
254{
255 return sock_tl_ep_equal(a, b);
256}
257
271static inline bool sock_udp_ep_equal(const sock_udp_ep_t *a,
272 const sock_udp_ep_t *b)
273{
274 return sock_tl_ep_equal(a, b);
275}
276
277#if defined(MODULE_SOCK_DTLS) || DOXYGEN
296 sock_udp_ep_t *local, const sock_udp_ep_t *remote,
297 void *work_buf, size_t work_buf_len);
298#endif
299
300#ifdef __cplusplus
301}
302#endif
303
304#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:67
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:218
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:271
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:83
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:163
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:252
static int sock_udp_str2ep(sock_udp_ep_t *ep_out, const char *str)
Convert string to UDP endpoint.
Definition util.h:199
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:182
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