udp.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_UDP_H
269 #define NET_SOCK_UDP_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 
289 typedef struct _sock_tl_ep sock_udp_ep_t;
297 typedef struct sock_udp sock_udp_t;
298 
299 #if defined (__clang__)
300 # pragma clang diagnostic pop
301 #endif
302 
306 typedef struct {
307 #if defined(MODULE_SOCK_AUX_LOCAL) || defined(DOXYGEN)
314 #endif /* MODULE_SOCK_AUX_ENDPOINT */
315 #if defined(MODULE_SOCK_AUX_TIMESTAMP) || defined(DOXYGEN)
321  uint64_t timestamp;
322 #endif /* MODULE_SOCK_AUX_TIMESTAP */
323 #if defined(MODULE_SOCK_AUX_RSSI) || defined(DOXYGEN)
329  int16_t rssi;
330 #endif /* MODULE_SOCK_AUX_RSSI */
333 
337 typedef struct {
338 #if defined(MODULE_SOCK_AUX_LOCAL) || defined(DOXYGEN)
345 #endif /* MODULE_SOCK_AUX_ENDPOINT */
346 #if defined(MODULE_SOCK_AUX_TIMESTAMP) || defined(DOXYGEN)
359  uint64_t timestamp;
360 #endif /* MODULE_SOCK_AUX_TIMESTAP*/
363 
413 int sock_udp_create(sock_udp_t *sock, const sock_udp_ep_t *local,
414  const sock_udp_ep_t *remote, uint16_t flags);
415 
424 
437 
449 
483 ssize_t sock_udp_recv_aux(sock_udp_t *sock, void *data, size_t max_len,
484  uint32_t timeout, sock_udp_ep_t *remote,
485  sock_udp_aux_rx_t *aux);
486 
518 static inline ssize_t sock_udp_recv(sock_udp_t *sock,
519  void *data, size_t max_len,
520  uint32_t timeout, sock_udp_ep_t *remote)
521 {
522  return sock_udp_recv_aux(sock, data, max_len, timeout, remote, NULL);
523 }
524 
569 ssize_t sock_udp_recv_buf_aux(sock_udp_t *sock, void **data, void **buf_ctx,
570  uint32_t timeout, sock_udp_ep_t *remote,
571  sock_udp_aux_rx_t *aux);
572 
615 static inline ssize_t sock_udp_recv_buf(sock_udp_t *sock,
616  void **data, void **buf_ctx,
617  uint32_t timeout,
618  sock_udp_ep_t *remote)
619 {
620  return sock_udp_recv_buf_aux(sock, data, buf_ctx, timeout, remote, NULL);
621 }
622 
657 ssize_t sock_udp_sendv_aux(sock_udp_t *sock, const iolist_t *snips,
658  const sock_udp_ep_t *remote, sock_udp_aux_tx_t *aux);
659 
695 static inline ssize_t sock_udp_send_aux(sock_udp_t *sock,
696  const void *data, size_t len,
697  const sock_udp_ep_t *remote,
698  sock_udp_aux_tx_t *aux)
699 {
700  const iolist_t snip = {
701  NULL,
702  (void *)data,
703  len,
704  };
705 
706  return sock_udp_sendv_aux(sock, &snip, remote, aux);
707 }
708 
742 static inline ssize_t sock_udp_send(sock_udp_t *sock,
743  const void *data, size_t len,
744  const sock_udp_ep_t *remote)
745 {
746  return sock_udp_send_aux(sock, data, len, remote, NULL);
747 }
748 
781 static inline ssize_t sock_udp_sendv(sock_udp_t *sock,
782  const iolist_t *snips,
783  const sock_udp_ep_t *remote)
784 {
785  return sock_udp_sendv_aux(sock, snips, remote, NULL);
786 }
787 
788 #include "sock_types.h"
789 
790 #ifdef __cplusplus
791 }
792 #endif
793 
794 #endif /* NET_SOCK_UDP_H */
ssize_t sock_udp_recv_aux(sock_udp_t *sock, void *data, size_t max_len, uint32_t timeout, sock_udp_ep_t *remote, sock_udp_aux_rx_t *aux)
Receives a UDP message from a remote end point.
int sock_udp_get_local(sock_udp_t *sock, sock_udp_ep_t *ep)
Gets the local end point of a UDP sock object.
int sock_udp_create(sock_udp_t *sock, const sock_udp_ep_t *local, const sock_udp_ep_t *remote, uint16_t flags)
Creates a new UDP sock object.
ssize_t sock_udp_sendv_aux(sock_udp_t *sock, const iolist_t *snips, const sock_udp_ep_t *remote, sock_udp_aux_tx_t *aux)
Sends a UDP message to remote end point with non-continous payload.
static ssize_t sock_udp_recv_buf(sock_udp_t *sock, void **data, void **buf_ctx, uint32_t timeout, sock_udp_ep_t *remote)
Provides stack-internal buffer space containing a UDP message from a remote end point.
Definition: udp.h:615
static ssize_t sock_udp_send_aux(sock_udp_t *sock, const void *data, size_t len, const sock_udp_ep_t *remote, sock_udp_aux_tx_t *aux)
Sends a UDP message to remote end point.
Definition: udp.h:695
int sock_udp_get_remote(sock_udp_t *sock, sock_udp_ep_t *ep)
Gets the remote end point of a UDP sock object.
static ssize_t sock_udp_sendv(sock_udp_t *sock, const iolist_t *snips, const sock_udp_ep_t *remote)
Sends a UDP message to remote end point with non-continous payload.
Definition: udp.h:781
void sock_udp_close(sock_udp_t *sock)
Closes a UDP sock object.
ssize_t sock_udp_recv_buf_aux(sock_udp_t *sock, void **data, void **buf_ctx, uint32_t timeout, sock_udp_ep_t *remote, sock_udp_aux_rx_t *aux)
Provides stack-internal buffer space containing a UDP message from a remote end point.
static ssize_t sock_udp_send(sock_udp_t *sock, const void *data, size_t len, const sock_udp_ep_t *remote)
Sends a UDP message to remote end point.
Definition: udp.h:742
static ssize_t sock_udp_recv(sock_udp_t *sock, void *data, size_t max_len, uint32_t timeout, sock_udp_ep_t *remote)
Receives a UDP message from a remote end point.
Definition: udp.h:518
uint8_t sock_aux_flags_t
Type holding the flags used to request specific auxiliary data.
Definition: sock.h:334
Common sock API definitions.
Common IP-based transport layer end point.
Definition: sock.h:215
iolist structure definition
Definition: iolist.h:39
Auxiliary data provided when receiving using an UDP sock object.
Definition: udp.h:306
sock_udp_ep_t local
The local endpoint the datagram was received on.
Definition: udp.h:313
int16_t rssi
RSSI value of the received frame.
Definition: udp.h:329
uint64_t timestamp
System time the datagram was received.
Definition: udp.h:321
sock_aux_flags_t flags
Flags used request information.
Definition: udp.h:331
Auxiliary data provided when sending using an UDP sock object.
Definition: udp.h:337
uint64_t timestamp
System time the datagram was send.
Definition: udp.h:359
sock_udp_ep_t local
The local endpoint from which the datagram will be sent.
Definition: udp.h:344
sock_aux_flags_t flags
Flags used request information.
Definition: udp.h:361
UDP sock type.
Definition: sock_types.h:128