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 
12 #pragma once
13 
274 #include <errno.h>
275 #include <stdint.h>
276 #include <stdlib.h>
277 #include <sys/types.h>
278 
279 /* net/sock/async/types.h included by net/sock.h needs to re-typedef the
280  * `sock_ip_t` to prevent cyclic includes */
281 #if defined (__clang__)
282 # pragma clang diagnostic push
283 # pragma clang diagnostic ignored "-Wtypedef-redefinition"
284 #endif
285 
286 #include "net/sock.h"
287 
288 #ifdef __cplusplus
289 extern "C" {
290 #endif
291 
298 typedef struct sock_ip sock_ip_t;
299 
300 #if defined (__clang__)
301 # pragma clang diagnostic pop
302 #endif
303 
307 typedef struct {
308 #if defined(MODULE_SOCK_AUX_LOCAL) || defined(DOXYGEN)
315 #endif /* MODULE_SOCK_AUX_ENDPOINT */
316 #if defined(MODULE_SOCK_AUX_TIMESTAMP) || defined(DOXYGEN)
322  uint64_t timestamp;
323 #endif /* MODULE_SOCK_AUX_TIMESTAP */
324 #if defined(MODULE_SOCK_AUX_RSSI) || defined(DOXYGEN)
330  int16_t rssi;
331 #endif /* MODULE_SOCK_AUX_RSSI */
334 
338 typedef struct {
339 #if defined(MODULE_SOCK_AUX_LOCAL) || defined(DOXYGEN)
346 #endif /* MODULE_SOCK_AUX_ENDPOINT */
347 #if defined(MODULE_SOCK_AUX_TIMESTAMP) || defined(DOXYGEN)
360  uint64_t timestamp;
361 #endif /* MODULE_SOCK_AUX_TIMESTAP*/
364 
407 int sock_ip_create(sock_ip_t *sock, const sock_ip_ep_t *local,
408  const sock_ip_ep_t *remote, uint8_t proto, uint16_t flags);
409 
418 
438 
458 
492 ssize_t sock_ip_recv_aux(sock_ip_t *sock, void *data, size_t max_len,
493  uint32_t timeout, sock_ip_ep_t *remote,
494  sock_ip_aux_rx_t *aux);
495 
527 static inline ssize_t sock_ip_recv(sock_ip_t *sock, void *data, size_t max_len,
528  uint32_t timeout, sock_ip_ep_t *remote)
529 {
530  return sock_ip_recv_aux(sock, data, max_len, timeout, remote, NULL);
531 }
532 
577 ssize_t sock_ip_recv_buf_aux(sock_ip_t *sock, void **data, void **buf_ctx,
578  uint32_t timeout, sock_ip_ep_t *remote,
579  sock_ip_aux_rx_t *aux);
580 
623 static inline ssize_t sock_ip_recv_buf(sock_ip_t *sock,
624  void **data, void **buf_ctx,
625  uint32_t timeout, sock_ip_ep_t *remote)
626 {
627  return sock_ip_recv_buf_aux(sock, data, buf_ctx, timeout, remote, NULL);
628 }
629 
664 ssize_t sock_ip_send_aux(sock_ip_t *sock, const void *data, size_t len,
665  uint8_t proto, const sock_ip_ep_t *remote,
666  sock_ip_aux_tx_t *aux);
667 
700 static inline ssize_t sock_ip_send(sock_ip_t *sock,
701  const void *data, size_t len,
702  uint8_t proto, const sock_ip_ep_t *remote)
703 {
704  return sock_ip_send_aux(sock, data, len, proto, remote, NULL);
705 }
706 
707 #include "sock_types.h"
708 
709 #ifdef __cplusplus
710 }
711 #endif
712 
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:700
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:623
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:527
uint8_t sock_aux_flags_t
Type holding the flags used to request specific auxiliary data.
Definition: sock.h:348
Common sock API definitions.
Auxiliary data provided when receiving using an IP sock object.
Definition: ip.h:307
int16_t rssi
RSSI value of the received frame.
Definition: ip.h:330
sock_ip_ep_t local
The local address the packet was received on.
Definition: ip.h:314
sock_aux_flags_t flags
Flags used request information.
Definition: ip.h:332
uint64_t timestamp
System time the packet was received.
Definition: ip.h:322
Auxiliary data provided when sending using an IP sock object.
Definition: ip.h:338
uint64_t timestamp
System time the packet was send.
Definition: ip.h:360
sock_aux_flags_t flags
Flags used request information.
Definition: ip.h:362
sock_ip_ep_t local
The local endpoint from which the datagram will be sent.
Definition: ip.h:345
Abstract IP end point and end point for a raw IP sock object.
Definition: sock.h:177
Raw IP sock type.
Definition: sock_types.h:91