ip.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 
268 #ifndef NET_SOCK_IP_H
269 #define NET_SOCK_IP_H
270 
271 #include <errno.h>
272 #include <stdint.h>
273 #include <stdlib.h>
274 #include <sys/types.h>
275 
276 /* net/sock/async/types.h included by net/sock.h needs to re-typedef the
277  * `sock_ip_t` to prevent cyclic includes */
278 #if defined (__clang__)
279 # pragma clang diagnostic push
280 # pragma clang diagnostic ignored "-Wtypedef-redefinition"
281 #endif
282 
283 #include "net/sock.h"
284 
285 #ifdef __cplusplus
286 extern "C" {
287 #endif
288 
295 typedef struct sock_ip sock_ip_t;
296 
297 #if defined (__clang__)
298 # pragma clang diagnostic pop
299 #endif
300 
304 typedef struct {
305 #if defined(MODULE_SOCK_AUX_LOCAL) || defined(DOXYGEN)
312 #endif /* MODULE_SOCK_AUX_ENDPOINT */
313 #if defined(MODULE_SOCK_AUX_TIMESTAMP) || defined(DOXYGEN)
319  uint64_t timestamp;
320 #endif /* MODULE_SOCK_AUX_TIMESTAP */
321 #if defined(MODULE_SOCK_AUX_RSSI) || defined(DOXYGEN)
327  int16_t rssi;
328 #endif /* MODULE_SOCK_AUX_RSSI */
331 
335 typedef struct {
336 #if defined(MODULE_SOCK_AUX_LOCAL) || defined(DOXYGEN)
343 #endif /* MODULE_SOCK_AUX_ENDPOINT */
344 #if defined(MODULE_SOCK_AUX_TIMESTAMP) || defined(DOXYGEN)
357  uint64_t timestamp;
358 #endif /* MODULE_SOCK_AUX_TIMESTAP*/
361 
404 int sock_ip_create(sock_ip_t *sock, const sock_ip_ep_t *local,
405  const sock_ip_ep_t *remote, uint8_t proto, uint16_t flags);
406 
415 
435 
455 
489 ssize_t sock_ip_recv_aux(sock_ip_t *sock, void *data, size_t max_len,
490  uint32_t timeout, sock_ip_ep_t *remote,
491  sock_ip_aux_rx_t *aux);
492 
524 static inline ssize_t sock_ip_recv(sock_ip_t *sock, void *data, size_t max_len,
525  uint32_t timeout, sock_ip_ep_t *remote)
526 {
527  return sock_ip_recv_aux(sock, data, max_len, timeout, remote, NULL);
528 }
529 
574 ssize_t sock_ip_recv_buf_aux(sock_ip_t *sock, void **data, void **buf_ctx,
575  uint32_t timeout, sock_ip_ep_t *remote,
576  sock_ip_aux_rx_t *aux);
577 
620 static inline ssize_t sock_ip_recv_buf(sock_ip_t *sock,
621  void **data, void **buf_ctx,
622  uint32_t timeout, sock_ip_ep_t *remote)
623 {
624  return sock_ip_recv_buf_aux(sock, data, buf_ctx, timeout, remote, NULL);
625 }
626 
661 ssize_t sock_ip_send_aux(sock_ip_t *sock, const void *data, size_t len,
662  uint8_t proto, const sock_ip_ep_t *remote,
663  sock_ip_aux_tx_t *aux);
664 
697 static inline ssize_t sock_ip_send(sock_ip_t *sock,
698  const void *data, size_t len,
699  uint8_t proto, const sock_ip_ep_t *remote)
700 {
701  return sock_ip_send_aux(sock, data, len, proto, remote, NULL);
702 }
703 
704 #include "sock_types.h"
705 
706 #ifdef __cplusplus
707 }
708 #endif
709 
710 #endif /* NET_SOCK_IP_H */
int sock_ip_create(sock_ip_t *sock, const sock_ip_ep_t *local, const sock_ip_ep_t *remote, uint8_t proto, uint16_t flags)
Creates a new raw IPv4/IPv6 sock object.
ssize_t sock_ip_recv_buf_aux(sock_ip_t *sock, void **data, void **buf_ctx, uint32_t timeout, sock_ip_ep_t *remote, sock_ip_aux_rx_t *aux)
Provides stack-internal buffer space containing an IPv4/IPv6 message from remote end point.
int sock_ip_get_remote(sock_ip_t *sock, sock_ip_ep_t *ep)
Gets the remote end point of a raw IPv4/IPv6 sock object.
void sock_ip_close(sock_ip_t *sock)
Closes a raw IPv4/IPv6 sock object.
static ssize_t sock_ip_send(sock_ip_t *sock, const void *data, size_t len, uint8_t proto, const sock_ip_ep_t *remote)
Sends a message over IPv4/IPv6 to remote end point.
Definition: ip.h:697
static ssize_t sock_ip_recv_buf(sock_ip_t *sock, void **data, void **buf_ctx, uint32_t timeout, sock_ip_ep_t *remote)
Provides stack-internal buffer space containing an IPv4/IPv6 message from remote end point.
Definition: ip.h:620
ssize_t sock_ip_recv_aux(sock_ip_t *sock, void *data, size_t max_len, uint32_t timeout, sock_ip_ep_t *remote, sock_ip_aux_rx_t *aux)
Receives a message over IPv4/IPv6 from remote end point.
ssize_t sock_ip_send_aux(sock_ip_t *sock, const void *data, size_t len, uint8_t proto, const sock_ip_ep_t *remote, sock_ip_aux_tx_t *aux)
Sends a message over IPv4/IPv6 to remote end point.
int sock_ip_get_local(sock_ip_t *sock, sock_ip_ep_t *ep)
Gets the local end point of a raw IPv4/IPv6 sock object.
static ssize_t sock_ip_recv(sock_ip_t *sock, void *data, size_t max_len, uint32_t timeout, sock_ip_ep_t *remote)
Receives a message over IPv4/IPv6 from remote end point.
Definition: ip.h:524
uint8_t sock_aux_flags_t
Type holding the flags used to request specific auxiliary data.
Definition: sock.h:334
Common sock API definitions.
Auxiliary data provided when receiving using an IP sock object.
Definition: ip.h:304
int16_t rssi
RSSI value of the received frame.
Definition: ip.h:327
sock_ip_ep_t local
The local address the packet was received on.
Definition: ip.h:311
sock_aux_flags_t flags
Flags used request information.
Definition: ip.h:329
uint64_t timestamp
System time the packet was received.
Definition: ip.h:319
Auxiliary data provided when sending using an IP sock object.
Definition: ip.h:335
uint64_t timestamp
System time the packet was send.
Definition: ip.h:357
sock_aux_flags_t flags
Flags used request information.
Definition: ip.h:359
sock_ip_ep_t local
The local endpoint from which the datagram will be sent.
Definition: ip.h:342
Abstract IP end point and end point for a raw IP sock object.
Definition: sock.h:178
Raw IP sock type.
Definition: sock_types.h:91