sock.h
Go to the documentation of this file.
1 /*
2  * Copyright (C) 2016 Alexander Aring <aar@pengutronix.de>
3  * Freie Universität Berlin
4  * HAW Hamburg
5  * Kaspar Schleiser <kaspar@schleiser.de>
6  *
7  * This file is subject to the terms and conditions of the GNU Lesser
8  * General Public License v2.1. See the file LICENSE in the top level
9  * directory for more details.
10  */
11 
12 #pragma once
13 
104 #include <stdint.h>
105 #include <stddef.h>
106 #include "iolist.h"
107 
108 #ifdef __cplusplus
109 extern "C" {
110 #endif
111 
112 #if defined(DOXYGEN)
118 #define SOCK_HAS_IPV6
124 #define SOCK_HAS_ASYNC
135 #define SOCK_HAS_ASYNC_CTX
137 #endif
138 
145 #define SOCK_FLAGS_REUSE_EP (0x0001)
146 #define SOCK_FLAGS_CONNECT_REMOTE (0x0002)
153 #define SOCK_ADDR_ANY_NETIF (0)
154 
158 #define SOCK_IPV4_EP_ANY { .family = AF_INET, \
159  .netif = SOCK_ADDR_ANY_NETIF }
160 
161 #if defined(SOCK_HAS_IPV6) || defined(DOXYGEN)
165 #define SOCK_IPV6_EP_ANY { .family = AF_INET6, \
166  .netif = SOCK_ADDR_ANY_NETIF }
167 #endif
168 
172 #define SOCK_NO_TIMEOUT (UINT32_MAX)
173 
177 typedef struct {
183  int family;
184 
185  union {
186 #ifdef SOCK_HAS_IPV6
192  uint8_t ipv6[16];
193 #endif
194  uint8_t ipv4[4];
195  uint32_t ipv4_u32;
196  } addr;
208  uint16_t netif;
209 } sock_ip_ep_t;
210 
214 struct _sock_tl_ep {
220  int family;
221 
222  union {
223 #ifdef SOCK_HAS_IPV6
229  uint8_t ipv6[16];
230 #endif
231  uint8_t ipv4[4];
232  uint32_t ipv4_u32;
233  } addr;
245  uint16_t netif;
246  uint16_t port;
247 };
248 
252 enum {
267  SOCK_AUX_GET_LOCAL = (1LU << 0),
305  SOCK_AUX_GET_RSSI = (1LU << 2),
320  SOCK_AUX_SET_LOCAL = (1LU << 3),
335  SOCK_AUX_GET_TTL = (1LU << 4),
336 };
337 
348 typedef uint8_t sock_aux_flags_t;
349 
350 #ifdef __cplusplus
351 }
352 #endif
353 
uint8_t sock_aux_flags_t
Type holding the flags used to request specific auxiliary data.
Definition: sock.h:348
@ SOCK_AUX_GET_TTL
Flag to request the TTL value of received frame.
Definition: sock.h:335
@ SOCK_AUX_SET_LOCAL
Flag to set the local address/endpoint.
Definition: sock.h:320
@ SOCK_AUX_GET_LOCAL
Flag to request the local address/endpoint.
Definition: sock.h:267
@ SOCK_AUX_GET_TIMESTAMP
Flag to request the time stamp of transmission / reception.
Definition: sock.h:289
@ SOCK_AUX_GET_RSSI
Flag to request the RSSI value of received frame.
Definition: sock.h:305
iolist scatter / gather IO
Common IP-based transport layer end point.
Definition: sock.h:214
uint16_t port
transport layer port (in host byte order)
Definition: sock.h:246
int family
family of sock_ip_ep_t::addr
Definition: sock.h:220
uint32_t ipv4_u32
IPv4 address in network byte order
Definition: sock.h:232
uint16_t netif
stack-specific network interface ID
Definition: sock.h:245
uint8_t ipv4[4]
IPv4 address mode.
Definition: sock.h:231
uint8_t ipv6[16]
IPv6 address mode.
Definition: sock.h:229
union _sock_tl_ep::@389 addr
address
Abstract IP end point and end point for a raw IP sock object.
Definition: sock.h:177
uint32_t ipv4_u32
IPv4 address in network byte order
Definition: sock.h:195
uint16_t netif
stack-specific network interface ID
Definition: sock.h:208
int family
family of sock_ip_ep_t::addr
Definition: sock.h:183