|
|
|
@ -1,21 +1,20 @@
|
|
|
|
|
From b7ed6eeb4f970bf603da8ec90f4f7e8b862dcdb6 Mon Sep 17 00:00:00 2001
|
|
|
|
|
From 9e99bc8ed9f4e4d326a14589ad29607fef89e3a5 Mon Sep 17 00:00:00 2001
|
|
|
|
|
From: Benjamin Valentin <benpicco@zedat.fu-berlin.de>
|
|
|
|
|
Date: Wed, 5 Feb 2014 20:01:41 +0100
|
|
|
|
|
Subject: [PATCH 01/10] add RIOT support
|
|
|
|
|
|
|
|
|
|
---
|
|
|
|
|
Makefile | 29 ++++++++++++++
|
|
|
|
|
external/regex/Makefile | 4 ++
|
|
|
|
|
src-api/common/Makefile | 3 ++
|
|
|
|
|
src-api/common/autobuf.c | 6 +++
|
|
|
|
|
src-api/common/common_types.h | 5 +++
|
|
|
|
|
Makefile | 29 ++++++++++++++++++++
|
|
|
|
|
external/regex/Makefile | 4 +++
|
|
|
|
|
src-api/common/Makefile | 3 +++
|
|
|
|
|
src-api/common/autobuf.c | 6 +++++
|
|
|
|
|
src-api/common/common_types.h | 5 ++++
|
|
|
|
|
src-api/common/daemonize.c | 2 +-
|
|
|
|
|
src-api/common/netaddr.c | 74 +++++++++++++++++++++---------------
|
|
|
|
|
src-api/common/netaddr.h | 22 +++++++----
|
|
|
|
|
src-api/rfc5444/Makefile | 3 ++
|
|
|
|
|
src-api/rfc5444/rfc5444_api_config.h | 51 +++++++++++++++++++++++++
|
|
|
|
|
src-api/rfc5444/rfc5444_print.c | 5 +++
|
|
|
|
|
11 files changed, 165 insertions(+), 39 deletions(-)
|
|
|
|
|
src-api/common/netaddr.c | 11 +++++++-
|
|
|
|
|
src-api/common/netaddr.h | 2 ++
|
|
|
|
|
src-api/rfc5444/Makefile | 3 +++
|
|
|
|
|
src-api/rfc5444/rfc5444_api_config.h | 51 ++++++++++++++++++++++++++++++++++++
|
|
|
|
|
10 files changed, 114 insertions(+), 2 deletions(-)
|
|
|
|
|
create mode 100644 Makefile
|
|
|
|
|
create mode 100644 external/regex/Makefile
|
|
|
|
|
create mode 100644 src-api/common/Makefile
|
|
|
|
@ -83,7 +82,7 @@ index 77c519b..37e77ac 100644
|
|
|
|
|
@@ -51,6 +51,12 @@
|
|
|
|
|
#include <winsock2.h>
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
+#ifdef RIOT_VERSION
|
|
|
|
|
+int getpagesize(void) {
|
|
|
|
|
+ return 512;
|
|
|
|
@ -91,7 +90,7 @@ index 77c519b..37e77ac 100644
|
|
|
|
|
+#endif
|
|
|
|
|
+
|
|
|
|
|
#include "common/autobuf.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
diff --git a/src-api/common/common_types.h b/src-api/common/common_types.h
|
|
|
|
|
index c90cf46..b5f170a 100644
|
|
|
|
@ -116,145 +115,48 @@ index 103c88f..8a6cd2b 100644
|
|
|
|
|
@@ -48,7 +48,7 @@
|
|
|
|
|
#include "common/common_types.h"
|
|
|
|
|
#include "common/daemonize.h"
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-#ifndef WIN32
|
|
|
|
|
+#if (!defined(_WIN32)) && (!defined(RIOT_VERSION))
|
|
|
|
|
/**
|
|
|
|
|
* Prepare the start of a daemon. Fork into background,
|
|
|
|
|
* but keep stdin/out/err open and a pipe connected to
|
|
|
|
|
diff --git a/src-api/common/netaddr.c b/src-api/common/netaddr.c
|
|
|
|
|
index dedab2c..1b602ec 100644
|
|
|
|
|
index dedab2c..6b214ee 100644
|
|
|
|
|
--- a/src-api/common/netaddr.c
|
|
|
|
|
+++ b/src-api/common/netaddr.c
|
|
|
|
|
@@ -43,7 +43,14 @@
|
|
|
|
|
@@ -43,7 +43,11 @@
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
+#ifndef RIOT_VERSION
|
|
|
|
|
#include <net/if.h>
|
|
|
|
|
+#else
|
|
|
|
|
+#include <arpa/inet.h>
|
|
|
|
|
+#include "net/af.h"
|
|
|
|
|
+#define DONT_HAVE_SIN6_SCOPE_ID
|
|
|
|
|
+#endif
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
#include "common/common_types.h"
|
|
|
|
|
#include "common/string.h"
|
|
|
|
|
@@ -175,12 +182,12 @@ netaddr_to_binary(void *dst, const struct netaddr *src, size_t len) {
|
|
|
|
|
int
|
|
|
|
|
netaddr_from_socket(struct netaddr *dst, const union netaddr_socket *src) {
|
|
|
|
|
memset(dst->_addr, 0, sizeof(dst->_addr));
|
|
|
|
|
- if (src->std.sa_family == AF_INET) {
|
|
|
|
|
+ if (src->std.sin6_family == AF_INET) {
|
|
|
|
|
/* ipv4 */
|
|
|
|
|
- memcpy(dst->_addr, &src->v4.sin_addr, 4);
|
|
|
|
|
+ memcpy(dst->_addr, &src->v4.sin6_addr, 4);
|
|
|
|
|
dst->_prefix_len = 32;
|
|
|
|
|
}
|
|
|
|
|
- else if (src->std.sa_family == AF_INET6){
|
|
|
|
|
+ else if (src->std.sin6_family == AF_INET6){
|
|
|
|
|
/* ipv6 */
|
|
|
|
|
memcpy(dst->_addr, &src->v6.sin6_addr, 16);
|
|
|
|
|
dst->_prefix_len = 128;
|
|
|
|
|
@@ -190,7 +197,7 @@ netaddr_from_socket(struct netaddr *dst, const union netaddr_socket *src) {
|
|
|
|
|
dst->_type = AF_UNSPEC;
|
|
|
|
|
return -1;
|
|
|
|
|
}
|
|
|
|
|
- dst->_type = (uint8_t)src->std.sa_family;
|
|
|
|
|
+ dst->_type = (uint8_t)src->std.sin6_family;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -204,12 +211,12 @@ netaddr_from_socket(struct netaddr *dst, const union netaddr_socket *src) {
|
|
|
|
|
int
|
|
|
|
|
netaddr_to_socket(union netaddr_socket *dst, const struct netaddr *src) {
|
|
|
|
|
/* copy address type */
|
|
|
|
|
- dst->std.sa_family = src->_type;
|
|
|
|
|
+ dst->std.sin6_family = src->_type;
|
|
|
|
|
|
|
|
|
|
switch (src->_type) {
|
|
|
|
|
case AF_INET:
|
|
|
|
|
/* ipv4 */
|
|
|
|
|
- memcpy(&dst->v4.sin_addr, src->_addr, 4);
|
|
|
|
|
+ memcpy(&dst->v4.sin6_addr, src->_addr, 4);
|
|
|
|
|
break;
|
|
|
|
|
case AF_INET6:
|
|
|
|
|
/* ipv6 */
|
|
|
|
|
@@ -221,7 +228,7 @@ netaddr_to_socket(union netaddr_socket *dst, const struct netaddr *src) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* copy address type */
|
|
|
|
|
- dst->std.sa_family= src->_type;
|
|
|
|
|
+ dst->std.sin6_family= src->_type;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -319,14 +326,16 @@ netaddr_socket_init(union netaddr_socket *combined, const struct netaddr *addr,
|
|
|
|
|
switch (addr->_type) {
|
|
|
|
|
case AF_INET:
|
|
|
|
|
/* ipv4 */
|
|
|
|
|
- memcpy(&combined->v4.sin_addr, addr->_addr, 4);
|
|
|
|
|
- combined->v4.sin_port = htons(port);
|
|
|
|
|
+ memcpy(&combined->v4.sin6_addr, addr->_addr, 4);
|
|
|
|
|
+ combined->v4.sin6_port = HTONS(port);
|
|
|
|
|
break;
|
|
|
|
|
case AF_INET6:
|
|
|
|
|
@@ -326,7 +330,9 @@ netaddr_socket_init(union netaddr_socket *combined, const struct netaddr *addr,
|
|
|
|
|
/* ipv6 */
|
|
|
|
|
memcpy(&combined->v6.sin6_addr, addr->_addr, 16);
|
|
|
|
|
- combined->v6.sin6_port = htons(port);
|
|
|
|
|
+ combined->v6.sin6_port = HTONS(port);
|
|
|
|
|
combined->v6.sin6_port = htons(port);
|
|
|
|
|
+#ifndef DONT_HAVE_SIN6_SCOPE_ID
|
|
|
|
|
combined->v6.sin6_scope_id = if_index;
|
|
|
|
|
+#endif
|
|
|
|
|
break;
|
|
|
|
|
default:
|
|
|
|
|
/* unknown address type */
|
|
|
|
|
@@ -334,7 +343,7 @@ netaddr_socket_init(union netaddr_socket *combined, const struct netaddr *addr,
|
|
|
|
|
@@ -561,6 +567,7 @@ netaddr_socket_to_string(struct netaddr_str *dst, const union netaddr_socket *sr
|
|
|
|
|
ntohs(src->v4.sin_port));
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* copy address type */
|
|
|
|
|
- combined->std.sa_family = addr->_type;
|
|
|
|
|
+ combined->std.sin6_family = addr->_type;
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
@@ -344,11 +353,11 @@ netaddr_socket_init(union netaddr_socket *combined, const struct netaddr *addr,
|
|
|
|
|
*/
|
|
|
|
|
uint16_t
|
|
|
|
|
netaddr_socket_get_port(const union netaddr_socket *sock) {
|
|
|
|
|
- switch (sock->std.sa_family) {
|
|
|
|
|
+ switch (sock->std.sin6_family) {
|
|
|
|
|
case AF_INET:
|
|
|
|
|
- return ntohs(sock->v4.sin_port);
|
|
|
|
|
+ return NTOHS(sock->v4.sin6_port);
|
|
|
|
|
case AF_INET6:
|
|
|
|
|
- return ntohs(sock->v6.sin6_port);
|
|
|
|
|
+ return NTOHS(sock->v6.sin6_port);
|
|
|
|
|
default:
|
|
|
|
|
return 0;
|
|
|
|
|
}
|
|
|
|
|
@@ -555,28 +564,31 @@ const char *
|
|
|
|
|
netaddr_socket_to_string(struct netaddr_str *dst, const union netaddr_socket *src) {
|
|
|
|
|
struct netaddr_str buf;
|
|
|
|
|
|
|
|
|
|
- if (src->std.sa_family == AF_INET) {
|
|
|
|
|
+ if (src->std.sin6_family == AF_INET) {
|
|
|
|
|
snprintf(dst->buf, sizeof(*dst), "%s:%d",
|
|
|
|
|
- inet_ntop(AF_INET, &src->v4.sin_addr, buf.buf, sizeof(buf)),
|
|
|
|
|
- ntohs(src->v4.sin_port));
|
|
|
|
|
+ inet_ntop(AF_INET, &src->v4.sin6_addr, buf.buf, sizeof(buf)),
|
|
|
|
|
+ NTOHS(src->v4.sin6_port));
|
|
|
|
|
}
|
|
|
|
|
- else if (src->std.sa_family == AF_INET6) {
|
|
|
|
|
+ else if (src->std.sin6_family == AF_INET6) {
|
|
|
|
|
else if (src->std.sa_family == AF_INET6) {
|
|
|
|
|
+#ifndef DONT_HAVE_SIN6_SCOPE_ID
|
|
|
|
|
if (src->v6.sin6_scope_id) {
|
|
|
|
|
char scope_buf[IF_NAMESIZE];
|
|
|
|
|
|
|
|
|
|
snprintf(dst->buf, sizeof(*dst), "[%s]:%d%%%s",
|
|
|
|
|
inet_ntop(AF_INET6, &src->v6.sin6_addr, buf.buf, sizeof(buf)),
|
|
|
|
|
- ntohs(src->v6.sin6_port),
|
|
|
|
|
+ NTOHS(src->v6.sin6_port),
|
|
|
|
|
|
|
|
|
|
@@ -569,7 +576,9 @@ netaddr_socket_to_string(struct netaddr_str *dst, const union netaddr_socket *sr
|
|
|
|
|
ntohs(src->v6.sin6_port),
|
|
|
|
|
if_indextoname(src->v6.sin6_scope_id, scope_buf));
|
|
|
|
|
}
|
|
|
|
|
- else {
|
|
|
|
@ -263,133 +165,23 @@ index dedab2c..1b602ec 100644
|
|
|
|
|
+ {
|
|
|
|
|
snprintf(dst->buf, sizeof(*dst), "[%s]:%d",
|
|
|
|
|
inet_ntop(AF_INET6, &src->v6.sin6_addr, buf.buf, sizeof(buf)),
|
|
|
|
|
- ntohs(src->v6.sin6_port));
|
|
|
|
|
+ NTOHS(src->v6.sin6_port));
|
|
|
|
|
}
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
- snprintf(dst->buf, sizeof(*dst), "\"Unknown socket type: %d\"", src->std.sa_family);
|
|
|
|
|
+ snprintf(dst->buf, sizeof(*dst), "\"Unknown socket type: %d\"", src->std.sin6_family);
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
return dst->buf;
|
|
|
|
|
@@ -622,13 +634,13 @@ int
|
|
|
|
|
netaddr_cmp_to_socket(const struct netaddr *a1, const union netaddr_socket *a2) {
|
|
|
|
|
int result = 0;
|
|
|
|
|
|
|
|
|
|
- result = (int)a1->_type - (int)a2->std.sa_family;
|
|
|
|
|
+ result = (int)a1->_type - (int)a2->std.sin6_family;
|
|
|
|
|
if (result) {
|
|
|
|
|
return result;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
if (a1->_type == AF_INET) {
|
|
|
|
|
- result = memcmp(a1->_addr, &a2->v4.sin_addr, 4);
|
|
|
|
|
+ result = memcmp(a1->_addr, &a2->v4.sin6_addr, 4);
|
|
|
|
|
}
|
|
|
|
|
else if (a1->_type == AF_INET6) {
|
|
|
|
|
/* ipv6 */
|
|
|
|
|
@@ -741,20 +753,20 @@ const char *
|
|
|
|
|
inet_ntop(int af, const void *src, char *dst, socklen_t cnt)
|
|
|
|
|
{
|
|
|
|
|
if (af == AF_INET) {
|
|
|
|
|
- struct sockaddr_in in;
|
|
|
|
|
+ sockaddr6_t in;
|
|
|
|
|
memset(&in, 0, sizeof(in));
|
|
|
|
|
in.sin_family = AF_INET;
|
|
|
|
|
- memcpy(&in.sin_addr, src, sizeof(struct in_addr));
|
|
|
|
|
- getnameinfo((struct sockaddr *)&in, sizeof(struct sockaddr_in),
|
|
|
|
|
+ memcpy(&in.sin6_addr, src, sizeof(struct in_addr));
|
|
|
|
|
+ getnameinfo((sockaddr6_t *)&in, sizeof(sockaddr6_t),
|
|
|
|
|
dst, cnt, NULL, 0, NI_NUMERICHOST);
|
|
|
|
|
return dst;
|
|
|
|
|
}
|
|
|
|
|
else if (af == AF_INET6) {
|
|
|
|
|
- struct sockaddr_in6 in;
|
|
|
|
|
+ sockaddr6_t in;
|
|
|
|
|
memset(&in, 0, sizeof(in));
|
|
|
|
|
in.sin6_family = AF_INET6;
|
|
|
|
|
memcpy(&in.sin6_addr, src, sizeof(struct in_addr6));
|
|
|
|
|
- getnameinfo((struct sockaddr *)&in, sizeof(struct sockaddr_in6),
|
|
|
|
|
+ getnameinfo((sockaddr6_t *)&in, sizeof(sockaddr6_t),
|
|
|
|
|
dst, cnt, NULL, 0, NI_NUMERICHOST);
|
|
|
|
|
return dst;
|
|
|
|
|
}
|
|
|
|
|
@@ -795,7 +807,7 @@ inet_pton(int af, const char *src, void *dst)
|
|
|
|
|
|
|
|
|
|
sock = (union netaddr_socket *)res->ai_addr;
|
|
|
|
|
if (af == AF_INET) {
|
|
|
|
|
- memcpy(dst, &sock->v4.sin_addr, 4);
|
|
|
|
|
+ memcpy(dst, &sock->v4.sin6_addr, 4);
|
|
|
|
|
}
|
|
|
|
|
else {
|
|
|
|
|
memcpy(dst, &sock->v6.sin6_addr, 16);
|
|
|
|
|
@@ -928,7 +940,7 @@ _subnetmask_to_prefixlen(const char *src) {
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
/* transform into host byte order */
|
|
|
|
|
- v4 = ntohl(v4);
|
|
|
|
|
+ v4 = NTOHL(v4);
|
|
|
|
|
|
|
|
|
|
shift = 0xffffffff;
|
|
|
|
|
for (len = 31; len >= 0; len--) {
|
|
|
|
|
ntohs(src->v6.sin6_port));
|
|
|
|
|
diff --git a/src-api/common/netaddr.h b/src-api/common/netaddr.h
|
|
|
|
|
index 78fd5b4..e65bf94 100644
|
|
|
|
|
index 78fd5b4..cc8189c 100644
|
|
|
|
|
--- a/src-api/common/netaddr.h
|
|
|
|
|
+++ b/src-api/common/netaddr.h
|
|
|
|
|
@@ -43,18 +43,26 @@
|
|
|
|
|
#define NETADDR_H_
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
-#ifndef _WIN32
|
|
|
|
|
+#if (!defined(_WIN32)) && (!defined(RIOT_VERSION))
|
|
|
|
|
@@ -45,9 +45,11 @@
|
|
|
|
|
|
|
|
|
|
#ifndef _WIN32
|
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
|
+#ifndef RIOT_VERSION
|
|
|
|
|
#include <netinet/if_ether.h>
|
|
|
|
|
#include <netinet/ip.h>
|
|
|
|
|
#include <net/if.h>
|
|
|
|
|
-#else
|
|
|
|
|
+#endif
|
|
|
|
|
+
|
|
|
|
|
+#ifdef _WIN32
|
|
|
|
|
#else
|
|
|
|
|
#include <winsock2.h>
|
|
|
|
|
#include <ws2tcpip.h>
|
|
|
|
|
|
|
|
|
|
#define IF_NAMESIZE 16
|
|
|
|
|
#endif
|
|
|
|
|
|
|
|
|
|
+#ifdef RIOT_VERSION
|
|
|
|
|
+#include "socket_base/socket.h"
|
|
|
|
|
+#define INET_ADDRSTRLEN (16)
|
|
|
|
|
+#define INET6_ADDRSTRLEN (48)
|
|
|
|
|
+#endif
|
|
|
|
|
+
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
#include <string.h>
|
|
|
|
|
|
|
|
|
|
@@ -97,10 +105,10 @@ struct netaddr {
|
|
|
|
|
* to all variants without casting and compiler warnings.
|
|
|
|
|
*/
|
|
|
|
|
union netaddr_socket {
|
|
|
|
|
- struct sockaddr_in v4;
|
|
|
|
|
- struct sockaddr_in6 v6;
|
|
|
|
|
- struct sockaddr std;
|
|
|
|
|
- struct sockaddr_storage storage;
|
|
|
|
|
+ sockaddr6_t v4;
|
|
|
|
|
+ sockaddr6_t v6;
|
|
|
|
|
+ sockaddr6_t std;
|
|
|
|
|
+ sockaddr6_t storage;
|
|
|
|
|
};
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
|
@@ -337,7 +345,7 @@ netaddr_set_prefix_length(struct netaddr *n, uint8_t prefix_len) {
|
|
|
|
|
*/
|
|
|
|
|
static INLINE sa_family_t
|
|
|
|
|
netaddr_socket_get_addressfamily(const union netaddr_socket *s) {
|
|
|
|
|
- return s->std.sa_family;
|
|
|
|
|
+ return s->std.sin6_family;
|
|
|
|
|
}
|
|
|
|
|
|
|
|
|
|
#endif /* NETADDR_H_ */
|
|
|
|
|
diff --git a/src-api/rfc5444/Makefile b/src-api/rfc5444/Makefile
|
|
|
|
|
new file mode 100644
|
|
|
|
|
index 0000000..5e0046d
|
|
|
|
@ -456,24 +248,5 @@ index 0000000..9bf6622
|
|
|
|
|
+#define CLEAR_ADDRESS_POSTFIX false
|
|
|
|
|
+
|
|
|
|
|
+#endif /* RFC5444_API_CONFIG_H_ */
|
|
|
|
|
diff --git a/src-api/rfc5444/rfc5444_print.c b/src-api/rfc5444/rfc5444_print.c
|
|
|
|
|
index 4b3e04d..7b9a308 100644
|
|
|
|
|
--- a/src-api/rfc5444/rfc5444_print.c
|
|
|
|
|
+++ b/src-api/rfc5444/rfc5444_print.c
|
|
|
|
|
@@ -41,8 +41,13 @@
|
|
|
|
|
#include <assert.h>
|
|
|
|
|
#include <stdio.h>
|
|
|
|
|
#include <stdlib.h>
|
|
|
|
|
+#ifdef RIOT_VERSION
|
|
|
|
|
+#include "socket_base/socket.h"
|
|
|
|
|
+#include "inet_ntop.h"
|
|
|
|
|
+#else
|
|
|
|
|
#include <sys/socket.h>
|
|
|
|
|
#include <arpa/inet.h>
|
|
|
|
|
+#endif
|
|
|
|
|
|
|
|
|
|
#include "common/netaddr.h"
|
|
|
|
|
#include "rfc5444/rfc5444_reader.h"
|
|
|
|
|
--
|
|
|
|
|
--
|
|
|
|
|
1.9.1
|
|
|
|
|
|
|
|
|
|