Skip to content

Commit 3536c84

Browse files
committed
oonf_api: adapt for new sockets
1 parent 320aa47 commit 3536c84

11 files changed

+96
-398
lines changed

Makefile.dep

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@ endif
55
ifneq (,$(filter nhdp,$(USEMODULE)))
66
USEMODULE += conn_udp
77
USEMODULE += vtimer
8-
USEMODULE += oonf_common
98
USEMODULE += oonf_rfc5444
109
endif
1110

@@ -307,9 +306,13 @@ ifneq (,$(filter fib,$(USEMODULE)))
307306
USEMODULE += xtimer
308307
endif
309308

309+
ifneq (,$(filter oonf_rfc5444,$(USEMODULE)))
310+
USEMODULE += oonf_common
311+
endif
312+
310313
ifneq (,$(filter oonf_common,$(USEMODULE)))
311314
USEPKG += oonf_api
312-
USEMODULE += socket_base
315+
USEMODULE += posix_sockets
313316
endif
314317

315318
ifneq (,$(filter %_conn_ip,$(USEMODULE)))
Lines changed: 33 additions & 260 deletions
Original file line numberDiff line numberDiff line change
@@ -1,21 +1,20 @@
1-
From b7ed6eeb4f970bf603da8ec90f4f7e8b862dcdb6 Mon Sep 17 00:00:00 2001
1+
From 9e99bc8ed9f4e4d326a14589ad29607fef89e3a5 Mon Sep 17 00:00:00 2001
22
From: Benjamin Valentin <benpicco@zedat.fu-berlin.de>
33
Date: Wed, 5 Feb 2014 20:01:41 +0100
44
Subject: [PATCH 01/10] add RIOT support
55

66
---
7-
Makefile | 29 ++++++++++++++
8-
external/regex/Makefile | 4 ++
9-
src-api/common/Makefile | 3 ++
10-
src-api/common/autobuf.c | 6 +++
11-
src-api/common/common_types.h | 5 +++
7+
Makefile | 29 ++++++++++++++++++++
8+
external/regex/Makefile | 4 +++
9+
src-api/common/Makefile | 3 +++
10+
src-api/common/autobuf.c | 6 +++++
11+
src-api/common/common_types.h | 5 ++++
1212
src-api/common/daemonize.c | 2 +-
13-
src-api/common/netaddr.c | 74 +++++++++++++++++++++---------------
14-
src-api/common/netaddr.h | 22 +++++++----
15-
src-api/rfc5444/Makefile | 3 ++
16-
src-api/rfc5444/rfc5444_api_config.h | 51 +++++++++++++++++++++++++
17-
src-api/rfc5444/rfc5444_print.c | 5 +++
18-
11 files changed, 165 insertions(+), 39 deletions(-)
13+
src-api/common/netaddr.c | 11 +++++++-
14+
src-api/common/netaddr.h | 2 ++
15+
src-api/rfc5444/Makefile | 3 +++
16+
src-api/rfc5444/rfc5444_api_config.h | 51 ++++++++++++++++++++++++++++++++++++
17+
10 files changed, 114 insertions(+), 2 deletions(-)
1918
create mode 100644 Makefile
2019
create mode 100644 external/regex/Makefile
2120
create mode 100644 src-api/common/Makefile
@@ -83,15 +82,15 @@ index 77c519b..37e77ac 100644
8382
@@ -51,6 +51,12 @@
8483
#include <winsock2.h>
8584
#endif
86-
85+
8786
+#ifdef RIOT_VERSION
8887
+int getpagesize(void) {
8988
+ return 512;
9089
+}
9190
+#endif
9291
+
9392
#include "common/autobuf.h"
94-
93+
9594
/**
9695
diff --git a/src-api/common/common_types.h b/src-api/common/common_types.h
9796
index c90cf46..b5f170a 100644
@@ -116,145 +115,48 @@ index 103c88f..8a6cd2b 100644
116115
@@ -48,7 +48,7 @@
117116
#include "common/common_types.h"
118117
#include "common/daemonize.h"
119-
118+
120119
-#ifndef WIN32
121120
+#if (!defined(_WIN32)) && (!defined(RIOT_VERSION))
122121
/**
123122
* Prepare the start of a daemon. Fork into background,
124123
* but keep stdin/out/err open and a pipe connected to
125124
diff --git a/src-api/common/netaddr.c b/src-api/common/netaddr.c
126-
index dedab2c..1b602ec 100644
125+
index dedab2c..6b214ee 100644
127126
--- a/src-api/common/netaddr.c
128127
+++ b/src-api/common/netaddr.c
129-
@@ -43,7 +43,14 @@
128+
@@ -43,7 +43,11 @@
130129
#include <stdio.h>
131130
#include <stdlib.h>
132131
#include <string.h>
133132
+#ifndef RIOT_VERSION
134133
#include <net/if.h>
135134
+#else
136-
+#include <arpa/inet.h>
137-
+#include "net/af.h"
138135
+#define DONT_HAVE_SIN6_SCOPE_ID
139136
+#endif
140-
137+
141138
#include "common/common_types.h"
142139
#include "common/string.h"
143-
@@ -175,12 +182,12 @@ netaddr_to_binary(void *dst, const struct netaddr *src, size_t len) {
144-
int
145-
netaddr_from_socket(struct netaddr *dst, const union netaddr_socket *src) {
146-
memset(dst->_addr, 0, sizeof(dst->_addr));
147-
- if (src->std.sa_family == AF_INET) {
148-
+ if (src->std.sin6_family == AF_INET) {
149-
/* ipv4 */
150-
- memcpy(dst->_addr, &src->v4.sin_addr, 4);
151-
+ memcpy(dst->_addr, &src->v4.sin6_addr, 4);
152-
dst->_prefix_len = 32;
153-
}
154-
- else if (src->std.sa_family == AF_INET6){
155-
+ else if (src->std.sin6_family == AF_INET6){
156-
/* ipv6 */
157-
memcpy(dst->_addr, &src->v6.sin6_addr, 16);
158-
dst->_prefix_len = 128;
159-
@@ -190,7 +197,7 @@ netaddr_from_socket(struct netaddr *dst, const union netaddr_socket *src) {
160-
dst->_type = AF_UNSPEC;
161-
return -1;
162-
}
163-
- dst->_type = (uint8_t)src->std.sa_family;
164-
+ dst->_type = (uint8_t)src->std.sin6_family;
165-
return 0;
166-
}
167-
168-
@@ -204,12 +211,12 @@ netaddr_from_socket(struct netaddr *dst, const union netaddr_socket *src) {
169-
int
170-
netaddr_to_socket(union netaddr_socket *dst, const struct netaddr *src) {
171-
/* copy address type */
172-
- dst->std.sa_family = src->_type;
173-
+ dst->std.sin6_family = src->_type;
174-
175-
switch (src->_type) {
176-
case AF_INET:
177-
/* ipv4 */
178-
- memcpy(&dst->v4.sin_addr, src->_addr, 4);
179-
+ memcpy(&dst->v4.sin6_addr, src->_addr, 4);
180-
break;
181-
case AF_INET6:
182-
/* ipv6 */
183-
@@ -221,7 +228,7 @@ netaddr_to_socket(union netaddr_socket *dst, const struct netaddr *src) {
184-
}
185-
186-
/* copy address type */
187-
- dst->std.sa_family= src->_type;
188-
+ dst->std.sin6_family= src->_type;
189-
return 0;
190-
}
191-
192-
@@ -319,14 +326,16 @@ netaddr_socket_init(union netaddr_socket *combined, const struct netaddr *addr,
193-
switch (addr->_type) {
194-
case AF_INET:
195-
/* ipv4 */
196-
- memcpy(&combined->v4.sin_addr, addr->_addr, 4);
197-
- combined->v4.sin_port = htons(port);
198-
+ memcpy(&combined->v4.sin6_addr, addr->_addr, 4);
199-
+ combined->v4.sin6_port = HTONS(port);
200-
break;
201-
case AF_INET6:
140+
@@ -326,7 +330,9 @@ netaddr_socket_init(union netaddr_socket *combined, const struct netaddr *addr,
202141
/* ipv6 */
203142
memcpy(&combined->v6.sin6_addr, addr->_addr, 16);
204-
- combined->v6.sin6_port = htons(port);
205-
+ combined->v6.sin6_port = HTONS(port);
143+
combined->v6.sin6_port = htons(port);
206144
+#ifndef DONT_HAVE_SIN6_SCOPE_ID
207145
combined->v6.sin6_scope_id = if_index;
208146
+#endif
209147
break;
210148
default:
211149
/* unknown address type */
212-
@@ -334,7 +343,7 @@ netaddr_socket_init(union netaddr_socket *combined, const struct netaddr *addr,
150+
@@ -561,6 +567,7 @@ netaddr_socket_to_string(struct netaddr_str *dst, const union netaddr_socket *sr
151+
ntohs(src->v4.sin_port));
213152
}
214-
215-
/* copy address type */
216-
- combined->std.sa_family = addr->_type;
217-
+ combined->std.sin6_family = addr->_type;
218-
return 0;
219-
}
220-
221-
@@ -344,11 +353,11 @@ netaddr_socket_init(union netaddr_socket *combined, const struct netaddr *addr,
222-
*/
223-
uint16_t
224-
netaddr_socket_get_port(const union netaddr_socket *sock) {
225-
- switch (sock->std.sa_family) {
226-
+ switch (sock->std.sin6_family) {
227-
case AF_INET:
228-
- return ntohs(sock->v4.sin_port);
229-
+ return NTOHS(sock->v4.sin6_port);
230-
case AF_INET6:
231-
- return ntohs(sock->v6.sin6_port);
232-
+ return NTOHS(sock->v6.sin6_port);
233-
default:
234-
return 0;
235-
}
236-
@@ -555,28 +564,31 @@ const char *
237-
netaddr_socket_to_string(struct netaddr_str *dst, const union netaddr_socket *src) {
238-
struct netaddr_str buf;
239-
240-
- if (src->std.sa_family == AF_INET) {
241-
+ if (src->std.sin6_family == AF_INET) {
242-
snprintf(dst->buf, sizeof(*dst), "%s:%d",
243-
- inet_ntop(AF_INET, &src->v4.sin_addr, buf.buf, sizeof(buf)),
244-
- ntohs(src->v4.sin_port));
245-
+ inet_ntop(AF_INET, &src->v4.sin6_addr, buf.buf, sizeof(buf)),
246-
+ NTOHS(src->v4.sin6_port));
247-
}
248-
- else if (src->std.sa_family == AF_INET6) {
249-
+ else if (src->std.sin6_family == AF_INET6) {
153+
else if (src->std.sa_family == AF_INET6) {
250154
+#ifndef DONT_HAVE_SIN6_SCOPE_ID
251155
if (src->v6.sin6_scope_id) {
252156
char scope_buf[IF_NAMESIZE];
253-
254-
snprintf(dst->buf, sizeof(*dst), "[%s]:%d%%%s",
255-
inet_ntop(AF_INET6, &src->v6.sin6_addr, buf.buf, sizeof(buf)),
256-
- ntohs(src->v6.sin6_port),
257-
+ NTOHS(src->v6.sin6_port),
157+
158+
@@ -569,7 +576,9 @@ netaddr_socket_to_string(struct netaddr_str *dst, const union netaddr_socket *sr
159+
ntohs(src->v6.sin6_port),
258160
if_indextoname(src->v6.sin6_scope_id, scope_buf));
259161
}
260162
- else {
@@ -263,133 +165,23 @@ index dedab2c..1b602ec 100644
263165
+ {
264166
snprintf(dst->buf, sizeof(*dst), "[%s]:%d",
265167
inet_ntop(AF_INET6, &src->v6.sin6_addr, buf.buf, sizeof(buf)),
266-
- ntohs(src->v6.sin6_port));
267-
+ NTOHS(src->v6.sin6_port));
268-
}
269-
}
270-
else {
271-
- snprintf(dst->buf, sizeof(*dst), "\"Unknown socket type: %d\"", src->std.sa_family);
272-
+ snprintf(dst->buf, sizeof(*dst), "\"Unknown socket type: %d\"", src->std.sin6_family);
273-
}
274-
275-
return dst->buf;
276-
@@ -622,13 +634,13 @@ int
277-
netaddr_cmp_to_socket(const struct netaddr *a1, const union netaddr_socket *a2) {
278-
int result = 0;
279-
280-
- result = (int)a1->_type - (int)a2->std.sa_family;
281-
+ result = (int)a1->_type - (int)a2->std.sin6_family;
282-
if (result) {
283-
return result;
284-
}
285-
286-
if (a1->_type == AF_INET) {
287-
- result = memcmp(a1->_addr, &a2->v4.sin_addr, 4);
288-
+ result = memcmp(a1->_addr, &a2->v4.sin6_addr, 4);
289-
}
290-
else if (a1->_type == AF_INET6) {
291-
/* ipv6 */
292-
@@ -741,20 +753,20 @@ const char *
293-
inet_ntop(int af, const void *src, char *dst, socklen_t cnt)
294-
{
295-
if (af == AF_INET) {
296-
- struct sockaddr_in in;
297-
+ sockaddr6_t in;
298-
memset(&in, 0, sizeof(in));
299-
in.sin_family = AF_INET;
300-
- memcpy(&in.sin_addr, src, sizeof(struct in_addr));
301-
- getnameinfo((struct sockaddr *)&in, sizeof(struct sockaddr_in),
302-
+ memcpy(&in.sin6_addr, src, sizeof(struct in_addr));
303-
+ getnameinfo((sockaddr6_t *)&in, sizeof(sockaddr6_t),
304-
dst, cnt, NULL, 0, NI_NUMERICHOST);
305-
return dst;
306-
}
307-
else if (af == AF_INET6) {
308-
- struct sockaddr_in6 in;
309-
+ sockaddr6_t in;
310-
memset(&in, 0, sizeof(in));
311-
in.sin6_family = AF_INET6;
312-
memcpy(&in.sin6_addr, src, sizeof(struct in_addr6));
313-
- getnameinfo((struct sockaddr *)&in, sizeof(struct sockaddr_in6),
314-
+ getnameinfo((sockaddr6_t *)&in, sizeof(sockaddr6_t),
315-
dst, cnt, NULL, 0, NI_NUMERICHOST);
316-
return dst;
317-
}
318-
@@ -795,7 +807,7 @@ inet_pton(int af, const char *src, void *dst)
319-
320-
sock = (union netaddr_socket *)res->ai_addr;
321-
if (af == AF_INET) {
322-
- memcpy(dst, &sock->v4.sin_addr, 4);
323-
+ memcpy(dst, &sock->v4.sin6_addr, 4);
324-
}
325-
else {
326-
memcpy(dst, &sock->v6.sin6_addr, 16);
327-
@@ -928,7 +940,7 @@ _subnetmask_to_prefixlen(const char *src) {
328-
}
329-
330-
/* transform into host byte order */
331-
- v4 = ntohl(v4);
332-
+ v4 = NTOHL(v4);
333-
334-
shift = 0xffffffff;
335-
for (len = 31; len >= 0; len--) {
168+
ntohs(src->v6.sin6_port));
336169
diff --git a/src-api/common/netaddr.h b/src-api/common/netaddr.h
337-
index 78fd5b4..e65bf94 100644
170+
index 78fd5b4..cc8189c 100644
338171
--- a/src-api/common/netaddr.h
339172
+++ b/src-api/common/netaddr.h
340-
@@ -43,18 +43,26 @@
341-
#define NETADDR_H_
342-
343-
344-
-#ifndef _WIN32
345-
+#if (!defined(_WIN32)) && (!defined(RIOT_VERSION))
173+
@@ -45,9 +45,11 @@
174+
175+
#ifndef _WIN32
346176
#include <arpa/inet.h>
177+
+#ifndef RIOT_VERSION
347178
#include <netinet/if_ether.h>
348179
#include <netinet/ip.h>
349180
#include <net/if.h>
350-
-#else
351181
+#endif
352-
+
353-
+#ifdef _WIN32
182+
#else
354183
#include <winsock2.h>
355184
#include <ws2tcpip.h>
356-
357-
#define IF_NAMESIZE 16
358-
#endif
359-
360-
+#ifdef RIOT_VERSION
361-
+#include "socket_base/socket.h"
362-
+#define INET_ADDRSTRLEN (16)
363-
+#define INET6_ADDRSTRLEN (48)
364-
+#endif
365-
+
366-
#include <assert.h>
367-
#include <string.h>
368-
369-
@@ -97,10 +105,10 @@ struct netaddr {
370-
* to all variants without casting and compiler warnings.
371-
*/
372-
union netaddr_socket {
373-
- struct sockaddr_in v4;
374-
- struct sockaddr_in6 v6;
375-
- struct sockaddr std;
376-
- struct sockaddr_storage storage;
377-
+ sockaddr6_t v4;
378-
+ sockaddr6_t v6;
379-
+ sockaddr6_t std;
380-
+ sockaddr6_t storage;
381-
};
382-
383-
/**
384-
@@ -337,7 +345,7 @@ netaddr_set_prefix_length(struct netaddr *n, uint8_t prefix_len) {
385-
*/
386-
static INLINE sa_family_t
387-
netaddr_socket_get_addressfamily(const union netaddr_socket *s) {
388-
- return s->std.sa_family;
389-
+ return s->std.sin6_family;
390-
}
391-
392-
#endif /* NETADDR_H_ */
393185
diff --git a/src-api/rfc5444/Makefile b/src-api/rfc5444/Makefile
394186
new file mode 100644
395187
index 0000000..5e0046d
@@ -456,24 +248,5 @@ index 0000000..9bf6622
456248
+#define CLEAR_ADDRESS_POSTFIX false
457249
+
458250
+#endif /* RFC5444_API_CONFIG_H_ */
459-
diff --git a/src-api/rfc5444/rfc5444_print.c b/src-api/rfc5444/rfc5444_print.c
460-
index 4b3e04d..7b9a308 100644
461-
--- a/src-api/rfc5444/rfc5444_print.c
462-
+++ b/src-api/rfc5444/rfc5444_print.c
463-
@@ -41,8 +41,13 @@
464-
#include <assert.h>
465-
#include <stdio.h>
466-
#include <stdlib.h>
467-
+#ifdef RIOT_VERSION
468-
+#include "socket_base/socket.h"
469-
+#include "inet_ntop.h"
470-
+#else
471-
#include <sys/socket.h>
472-
#include <arpa/inet.h>
473-
+#endif
474-
475-
#include "common/netaddr.h"
476-
#include "rfc5444/rfc5444_reader.h"
477-
--
251+
--
478252
1.9.1
479-

0 commit comments

Comments
 (0)