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)
313 #endif /* MODULE_SOCK_AUX_ENDPOINT */
314 #if defined(MODULE_SOCK_AUX_TIMESTAMP) || defined(DOXYGEN)
320  uint64_t timestamp;
321 #endif /* MODULE_SOCK_AUX_TIMESTAP */
322 #if defined(MODULE_SOCK_AUX_RSSI) || defined(DOXYGEN)
328  int16_t rssi;
329 #endif /* MODULE_SOCK_AUX_RSSI */
332 
336 typedef struct {
337 #if defined(MODULE_SOCK_AUX_TIMESTAMP) || defined(DOXYGEN)
350  uint64_t timestamp;
351 #endif /* MODULE_SOCK_AUX_TIMESTAP*/
354 
397 int sock_udp_create(sock_udp_t *sock, const sock_udp_ep_t *local,
398  const sock_udp_ep_t *remote, uint16_t flags);
399 
408 
421 
433 
467 ssize_t sock_udp_recv_aux(sock_udp_t *sock, void *data, size_t max_len,
468  uint32_t timeout, sock_udp_ep_t *remote,
469  sock_udp_aux_rx_t *aux);
470 
502 static inline ssize_t sock_udp_recv(sock_udp_t *sock,
503  void *data, size_t max_len,
504  uint32_t timeout, sock_udp_ep_t *remote)
505 {
506  return sock_udp_recv_aux(sock, data, max_len, timeout, remote, NULL);
507 }
508 
553 ssize_t sock_udp_recv_buf_aux(sock_udp_t *sock, void **data, void **buf_ctx,
554  uint32_t timeout, sock_udp_ep_t *remote,
555  sock_udp_aux_rx_t *aux);
556 
599 static inline ssize_t sock_udp_recv_buf(sock_udp_t *sock,
600  void **data, void **buf_ctx,
601  uint32_t timeout,
602  sock_udp_ep_t *remote)
603 {
604  return sock_udp_recv_buf_aux(sock, data, buf_ctx, timeout, remote, NULL);
605 }
606 
642 ssize_t sock_udp_send_aux(sock_udp_t *sock, const void *data, size_t len,
643  const sock_udp_ep_t *remote, sock_udp_aux_tx_t *aux);
644 
678 static inline ssize_t sock_udp_send(sock_udp_t *sock,
679  const void *data, size_t len,
680  const sock_udp_ep_t *remote)
681 {
682  return sock_udp_send_aux(sock, data, len, remote, NULL);
683 }
684 
685 #include "sock_types.h"
686 
687 #ifdef __cplusplus
688 }
689 #endif
690 
691 #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.
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:599
int sock_udp_get_remote(sock_udp_t *sock, sock_udp_ep_t *ep)
Gets the remote end point of a UDP sock object.
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:678
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:502
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.
uint8_t sock_aux_flags_t
Type holding the flags used to request specific auxiliary data.
Definition: sock.h:316
Common sock API definitions.
Common IP-based transport layer end point.
Definition: sock.h:212
Auxiliary data provided when receiving using an UDP sock object.
Definition: udp.h:305
sock_udp_ep_t local
The local endpoint the datagram was received on.
Definition: udp.h:312
int16_t rssi
RSSI value of the received frame.
Definition: udp.h:328
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:330
Auxiliary data provided when sending using an UDP sock object.
Definition: udp.h:336
uint64_t timestamp
System time the datagram was send.
Definition: udp.h:350
sock_aux_flags_t flags
Flags used request information.
Definition: udp.h:352
UDP sock type.
Definition: sock_types.h:128