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 __cplusplus
35 extern "C" {
36 #endif
37 
48 int sock_tl_ep_fmt(const struct _sock_tl_ep *endpoint,
49  char *addr_str, uint16_t *port);
50 
61 static inline int sock_tcp_ep_fmt(const sock_tcp_ep_t *endpoint,
62  char *addr_str, uint16_t *port)
63 {
64  return sock_tl_ep_fmt(endpoint, addr_str, port);
65 }
66 
77 static inline int sock_udp_ep_fmt(const sock_udp_ep_t *endpoint,
78  char *addr_str, uint16_t *port)
79 {
80  return sock_tl_ep_fmt(endpoint, addr_str, port);
81 }
82 
103 int sock_urlsplit(const char *url, char *hostport, char *urlpath);
104 
117 int sock_tl_str2ep(struct _sock_tl_ep *ep_out, const char *str);
118 
131 static inline int sock_tcp_str2ep(sock_tcp_ep_t *ep_out, const char *str)
132 {
133  return sock_tl_str2ep(ep_out, str);
134 }
135 
148 static inline int sock_udp_str2ep(sock_udp_ep_t *ep_out, const char *str)
149 {
150  return sock_tl_str2ep(ep_out, str);
151 }
152 
166 bool sock_tl_ep_equal(const struct _sock_tl_ep *a,
167  const struct _sock_tl_ep *b);
168 
182 static inline bool sock_tcp_ep_equal(const sock_tcp_ep_t *a,
183  const sock_tcp_ep_t *b)
184 {
185  return sock_tl_ep_equal(a, b);
186 }
187 
201 static inline bool sock_udp_ep_equal(const sock_udp_ep_t *a,
202  const sock_udp_ep_t *b)
203 {
204  return sock_tl_ep_equal(a, b);
205 }
206 
217 #ifndef CONFIG_SOCK_SCHEME_MAXLEN
218 #define CONFIG_SOCK_SCHEME_MAXLEN (16U)
219 #endif
220 
224 #ifndef CONFIG_SOCK_HOSTPORT_MAXLEN
225 #define CONFIG_SOCK_HOSTPORT_MAXLEN (64U)
226 #endif
227 
231 #ifndef CONFIG_SOCK_URLPATH_MAXLEN
232 #define CONFIG_SOCK_URLPATH_MAXLEN (64U)
233 #endif
234 
236 #ifdef __cplusplus
237 }
238 #endif
239 
240 #endif /* NET_SOCK_UTIL_H */
241 
sock_tcp_ep_fmt
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:61
sock_tcp_str2ep
static int sock_tcp_str2ep(sock_tcp_ep_t *ep_out, const char *str)
Convert string to TCP endpoint.
Definition: util.h:131
udp.h
UDP sock definitions.
sock_tcp_ep_equal
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:182
sock_udp_str2ep
static int sock_udp_str2ep(sock_udp_ep_t *ep_out, const char *str)
Convert string to UDP endpoint.
Definition: util.h:148
tcp.h
TCP sock definitions.
sock_tl_str2ep
int sock_tl_str2ep(struct _sock_tl_ep *ep_out, const char *str)
Convert string to common IP-based transport layer endpoint.
_sock_tl_ep
Common IP-based transport layer end point.
Definition: sock.h:213
sock_tl_ep_fmt
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.
sock_tl_ep_equal
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.
sock_urlsplit
int sock_urlsplit(const char *url, char *hostport, char *urlpath)
Split url to host:port and url path.
sock_udp_ep_equal
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:201
sock_udp_ep_fmt
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:77