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 <stdint.h>
272 #include <stdlib.h>
273 #include <sys/types.h>
274 
275 /* net/sock/async/types.h included by net/sock.h needs to re-typedef the
276  * `sock_ip_t` to prevent cyclic includes */
277 #if defined (__clang__)
278 # pragma clang diagnostic push
279 # pragma clang diagnostic ignored "-Wtypedef-redefinition"
280 #endif
281 
282 #include "net/sock.h"
283 
284 #ifdef __cplusplus
285 extern "C" {
286 #endif
287 
288 typedef struct _sock_tl_ep sock_udp_ep_t;
296 typedef struct sock_udp sock_udp_t;
297 
298 #if defined (__clang__)
299 # pragma clang diagnostic pop
300 #endif
301 
305 typedef struct {
306 #if defined(MODULE_SOCK_AUX_LOCAL) || defined(DOXYGEN)
307 
313 #endif /* MODULE_SOCK_AUX_ENDPOINT */
314 #if defined(MODULE_SOCK_AUX_TIMESTAMP) || defined(DOXYGEN)
315 
320  uint64_t timestamp;
321 #endif /* MODULE_SOCK_AUX_TIMESTAP*/
324 
328 typedef struct {
329 #if defined(MODULE_SOCK_AUX_TIMESTAMP) || defined(DOXYGEN)
330 
342  uint64_t timestamp;
343 #endif /* MODULE_SOCK_AUX_TIMESTAP*/
346 
390  const sock_udp_ep_t *remote, uint16_t flags);
391 
399 void sock_udp_close(sock_udp_t *sock);
400 
413 
425 
459 ssize_t sock_udp_recv_aux(sock_udp_t *sock, void *data, size_t max_len,
460  uint32_t timeout, sock_udp_ep_t *remote,
461  sock_udp_aux_rx_t *aux);
462 
494 static inline ssize_t sock_udp_recv(sock_udp_t *sock,
495  void *data, size_t max_len,
496  uint32_t timeout, sock_udp_ep_t *remote)
497 {
498  return sock_udp_recv_aux(sock, data, max_len, timeout, remote, NULL);
499 }
500 
545 ssize_t sock_udp_recv_buf_aux(sock_udp_t *sock, void **data, void **buf_ctx,
546  uint32_t timeout, sock_udp_ep_t *remote,
547  sock_udp_aux_rx_t *aux);
548 
591 static inline ssize_t sock_udp_recv_buf(sock_udp_t *sock,
592  void **data, void **buf_ctx,
593  uint32_t timeout,
594  sock_udp_ep_t *remote)
595 {
596  return sock_udp_recv_buf_aux(sock, data, buf_ctx, timeout, remote, NULL);
597 }
598 
634 ssize_t sock_udp_send_aux(sock_udp_t *sock, const void *data, size_t len,
635  const sock_udp_ep_t *remote, sock_udp_aux_tx_t *aux);
636 
670 static inline ssize_t sock_udp_send(sock_udp_t *sock,
671  const void *data, size_t len,
672  const sock_udp_ep_t *remote)
673 {
674  return sock_udp_send_aux(sock, data, len, remote, NULL);
675 }
676 
677 #include "sock_types.h"
678 
679 #ifdef __cplusplus
680 }
681 #endif
682 
683 #endif /* NET_SOCK_UDP_H */
684 
uint64_t timestamp
System time the datagram was received.
Definition: udp.h:320
sock_aux_flags_t flags
Flags used request information.
Definition: udp.h:344
uint8_t sock_aux_flags_t
Type holding the flags used to request specific auxiliary data.
Definition: sock.h:301
sock_udp_ep_t local
The local endpoint the datagram was received on.
Definition: udp.h:312
int sock_udp_get_remote(sock_udp_t *sock, sock_udp_ep_t *ep)
Gets the remote end point of a UDP sock object.
sock_udp_ep_t remote
remote end-point
Definition: sock_types.h:135
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.
void sock_udp_close(sock_udp_t *sock)
Closes a UDP sock object.
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:494
int sock_udp_get_local(sock_udp_t *sock, sock_udp_ep_t *ep)
Gets the local end point of a UDP sock object.
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.
sock_udp_ep_t local
local end-point
Definition: sock_types.h:134
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.
uint64_t timestamp
System time the datagram was send.
Definition: udp.h:342
Common IP-based transport layer end point.
Definition: sock.h:213
Common sock API definitions.
uint16_t flags
option flags
Definition: sock_types.h:136
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:670
UDP sock type.
Definition: sock_types.h:128
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:591
Auxiliary data provided when sending using an UDP sock object.
Definition: udp.h:328
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.
sock_aux_flags_t flags
Flags used request information.
Definition: udp.h:322
Auxiliary data provided when receiving using an UDP sock object.
Definition: udp.h:305