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 
406 int sock_udp_create(sock_udp_t *sock, const sock_udp_ep_t *local,
407  const sock_udp_ep_t *remote, uint16_t flags);
408 
417 
430 
442 
476 ssize_t sock_udp_recv_aux(sock_udp_t *sock, void *data, size_t max_len,
477  uint32_t timeout, sock_udp_ep_t *remote,
478  sock_udp_aux_rx_t *aux);
479 
511 static inline ssize_t sock_udp_recv(sock_udp_t *sock,
512  void *data, size_t max_len,
513  uint32_t timeout, sock_udp_ep_t *remote)
514 {
515  return sock_udp_recv_aux(sock, data, max_len, timeout, remote, NULL);
516 }
517 
562 ssize_t sock_udp_recv_buf_aux(sock_udp_t *sock, void **data, void **buf_ctx,
563  uint32_t timeout, sock_udp_ep_t *remote,
564  sock_udp_aux_rx_t *aux);
565 
608 static inline ssize_t sock_udp_recv_buf(sock_udp_t *sock,
609  void **data, void **buf_ctx,
610  uint32_t timeout,
611  sock_udp_ep_t *remote)
612 {
613  return sock_udp_recv_buf_aux(sock, data, buf_ctx, timeout, remote, NULL);
614 }
615 
650 ssize_t sock_udp_sendv_aux(sock_udp_t *sock, const iolist_t *snips,
651  const sock_udp_ep_t *remote, sock_udp_aux_tx_t *aux);
652 
688 static inline ssize_t sock_udp_send_aux(sock_udp_t *sock,
689  const void *data, size_t len,
690  const sock_udp_ep_t *remote,
691  sock_udp_aux_tx_t *aux)
692 {
693  const iolist_t snip = {
694  NULL,
695  (void *)data,
696  len,
697  };
698 
699  return sock_udp_sendv_aux(sock, &snip, remote, aux);
700 }
701 
735 static inline ssize_t sock_udp_send(sock_udp_t *sock,
736  const void *data, size_t len,
737  const sock_udp_ep_t *remote)
738 {
739  return sock_udp_send_aux(sock, data, len, remote, NULL);
740 }
741 
774 static inline ssize_t sock_udp_sendv(sock_udp_t *sock,
775  const iolist_t *snips,
776  const sock_udp_ep_t *remote)
777 {
778  return sock_udp_sendv_aux(sock, snips, remote, NULL);
779 }
780 
781 #include "sock_types.h"
782 
783 #ifdef __cplusplus
784 }
785 #endif
786 
787 #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:608
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:688
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:774
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:735
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:511
uint8_t sock_aux_flags_t
Type holding the flags used to request specific auxiliary data.
Definition: sock.h:333
Common sock API definitions.
Common IP-based transport layer end point.
Definition: sock.h:214
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