udp.h
5.2 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
/*
* Copyright (C) 2015 Martine Lenders <mlenders@inf.fu-berlin.de>
*
* This file is subject to the terms and conditions of the GNU Lesser
* General Public License v2.1. See the file LICENSE in the top level
* directory for more details.
*/
/**
* @defgroup net_conn_udp UDP connections
* @ingroup net_conn
* @deprecated Please use @ref net_sock_udp instead
* @brief Connection submodule for UDP connections
* @{
*
* @file
* @brief UDP connection definitions
*
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
*/
#ifndef NET_CONN_UDP_H_
#define NET_CONN_UDP_H_
#include <stdint.h>
#include <stdlib.h>
#ifdef MODULE_GNRC_CONN_UDP
#include "net/gnrc/conn.h"
#endif
#ifdef MODULE_LWIP_CONN_UDP
#include "lwip/conn.h"
#endif
#ifdef MODULE_EMB6_CONN_UDP
#include "emb6/conn/udp.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif
/**
* @brief Forward declaration of @ref conn_udp_t to allow for external definition.
*/
struct conn_udp;
/**
* @brief Implementation-specific type of a UDP connection object
*/
typedef struct conn_udp conn_udp_t;
/**
* @brief Creates a new UDP connection object
*
* @param[out] conn Preallocated connection object. Must fill the size of the stack-specific
* connection desriptor.
* @param[in] addr The local network layer address for @p conn.
* @param[in] addr_len The length of @p addr. Must be fitting for the @p family.
* @param[in] family The family of @p addr (see @ref net_af).
* @param[in] port The local UDP port for @p conn.
*
* @todo With @ref net_gnrc @ref conn_udp_recvfrom needs to be called from the
* same thread as for this function. This is undesired behavior and
* will be fixed in upcoming versions of RIOT.
*
* @return 0 on success.
* @return any other negative number in case of an error. For portability implementations should
* draw inspiration of the errno values from the POSIX' bind() function specification.
*/
int conn_udp_create(conn_udp_t *conn, const void *addr, size_t addr_len, int family,
uint16_t port);
/**
* @brief Closes a UDP connection
*
* @param[in,out] conn A UDP connection object.
*/
void conn_udp_close(conn_udp_t *conn);
/**
* @brief Gets the local address of a UDP connection
*
* @param[in] conn A UDP connection object.
* @param[out] addr The local network layer address. Must have space for any address of
* the connection's family.
* @param[out] port The local UDP port.
*
* @return length of @p addr on success.
* @return any other negative number in case of an error. For portability implementations should
* draw inspiration of the errno values from the POSIX' getsockname() function
* specification.
*/
int conn_udp_getlocaladdr(conn_udp_t *conn, void *addr, uint16_t *port);
/**
* @brief Receives a UDP message
*
* @param[in] conn A UDP connection object.
* @param[out] data Pointer where the received data should be stored.
* @param[in] max_len Maximum space available at @p data.
* @param[out] addr NULL pointer or the sender's network layer address. Must have space
* for any address of the connection's family.
* @param[out] addr_len Length of @p addr. Can be NULL if @p addr is NULL.
* @param[out] port NULL pointer or the sender's UDP port.
*
* @note Function may block.
*
* @todo With @ref net_gnrc this function needs to be called from the same
* thread as @ref conn_udp_create. This is undesired behavior and will
* be fixed in upcoming versions of RIOT.
*
* @return The number of bytes received on success.
* @return 0, if no received data is available, but everything is in order.
* @return any other negative number in case of an error. For portability, implementations should
* draw inspiration of the errno values from the POSIX' recv(), recvfrom(), or recvmsg()
* function specification.
*/
int conn_udp_recvfrom(conn_udp_t *conn, void *data, size_t max_len, void *addr, size_t *addr_len,
uint16_t *port);
/**
* @brief Sends a UDP message
*
* @param[in] data Pointer to the data to send.
* @param[in] len Length of the @p data to send.
* @param[in] src The source address. May be NULL for any interface address.
* @param[in] src_len Length of @p src. May be 0 if @p src is NULL
* @param[in] dst The receiver's network address.
* @param[in] dst_len Length of @p dst.
* @param[in] family The family of @p src and @p dst (see @ref net_af).
* @param[in] sport The source UDP port.
* @param[in] dport The receiver's UDP port.
*
* @note Function may block.
*
* @return The number of bytes sent on success.
* @return any other negative number in case of an error. For portability, implementations should
* draw inspiration of the errno values from the POSIX' send(), sendfrom(), or sendmsg()
* function specification.
*/
int conn_udp_sendto(const void *data, size_t len, const void *src, size_t src_len,
const void *dst, size_t dst_len, int family, uint16_t sport,
uint16_t dport);
#ifdef __cplusplus
}
#endif
#endif /* NET_CONN_UDP4_H_ */
/** @} */