From 53a9dc36ed6867218f82672cd3b45dabd756b2b9 Mon Sep 17 00:00:00 2001 From: Martine Lenders <m.lenders@fu-berlin.de> Date: Wed, 26 Apr 2017 14:41:45 +0200 Subject: [PATCH] nhdp: port to sock --- Makefile.dep | 2 +- sys/net/routing/nhdp/nhdp.c | 36 ++++++++++++++---------------------- 2 files changed, 15 insertions(+), 23 deletions(-) diff --git a/Makefile.dep b/Makefile.dep index 519285ee08..6654a948fb 100644 --- a/Makefile.dep +++ b/Makefile.dep @@ -14,7 +14,7 @@ ifneq (,$(filter csma_sender,$(USEMODULE))) endif ifneq (,$(filter nhdp,$(USEMODULE))) - USEMODULE += conn_udp + USEMODULE += sock_udp USEMODULE += xtimer USEMODULE += oonf_rfc5444 endif diff --git a/sys/net/routing/nhdp/nhdp.c b/sys/net/routing/nhdp/nhdp.c index 7a58977b38..4665f7746f 100644 --- a/sys/net/routing/nhdp/nhdp.c +++ b/sys/net/routing/nhdp/nhdp.c @@ -18,8 +18,7 @@ * @} */ -#include "net/gnrc/conn.h" -#include "net/conn/udp.h" +#include "net/sock/udp.h" #include "msg.h" #include "net/gnrc/netapi.h" #include "net/gnrc/netif.h" @@ -38,10 +37,6 @@ #include "nhdp_writer.h" #include "nhdp_reader.h" -#ifndef MODULE_CONN_UDP -#error "nhdp needs a conn_udp implementation to work" -#endif - #define HELLO_TIMER (12345) char nhdp_stack[NHDP_STACK_SIZE]; @@ -53,7 +48,7 @@ static kernel_pid_t nhdp_rcv_pid = KERNEL_PID_UNDEF; static kernel_pid_t helper_pid = KERNEL_PID_UNDEF; static nhdp_if_entry_t nhdp_if_table[GNRC_NETIF_NUMOF]; static mutex_t send_rcv_mutex = MUTEX_INIT; -static conn_udp_t conn; +static sock_udp_t sock; #if (NHDP_METRIC_NEEDS_TIMER) static xtimer_t metric_timer; @@ -295,27 +290,24 @@ static void *_nhdp_runner(void *arg) */ static void *_nhdp_receiver(void *arg __attribute__((unused))) { + static const sock_udp_ep_t ep = { .family = AF_INET6, + .netif = SOCK_ADDR_ANY_NETIF, + .port = MANET_PORT }; char nhdp_rcv_buf[NHDP_MAX_RFC5444_PACKET_SZ]; msg_t msg_q[NHDP_MSG_QUEUE_SIZE]; msg_init_queue(msg_q, NHDP_MSG_QUEUE_SIZE); - /* Configure socket address for the manet port 269 */ - ipv6_addr_t unspec = IPV6_ADDR_UNSPECIFIED; - /* Bind UDP socket to socket address */ - if (conn_udp_create(&conn, &unspec, sizeof(unspec), AF_INET6, MANET_PORT) == -1) { + if (sock_udp_create(&sock, &ep, NULL, 0) < 0) { /* Failed creating the connection */ return 0; } while (1) { - ipv6_addr_t rcv_addr; - uint16_t rcv_port; - size_t addr_len = sizeof(rcv_addr); - int32_t rcv_size = conn_udp_recvfrom(&conn, (void *)nhdp_rcv_buf, - NHDP_MAX_RFC5444_PACKET_SZ, &rcv_addr, - &addr_len, &rcv_port); + int32_t rcv_size = sock_udp_recv(&sock, (void *)nhdp_rcv_buf, + NHDP_MAX_RFC5444_PACKET_SZ, + SOCK_NO_TIMEOUT, NULL); if (rcv_size > 0) { /* Packet received, let the reader handle it */ @@ -325,7 +317,7 @@ static void *_nhdp_receiver(void *arg __attribute__((unused))) } } - conn_udp_close(&conn); + sock_udp_close(&sock); return 0; } @@ -337,8 +329,8 @@ static void write_packet(struct rfc5444_writer *wr __attribute__((unused)), struct rfc5444_writer_target *iface __attribute__((unused)), void *buffer, size_t length) { - ipv6_addr_t src, dst = IPV6_ADDR_ALL_NODES_LINK_LOCAL; - uint16_t sport, dport = MANET_PORT; - conn_udp_getlocaladdr(&conn, &src, &sport); - conn_udp_sendto(buffer, length, &src, sizeof(src), &dst, sizeof(dst), AF_INET, sport, dport); + sock_udp_ep_t ep = { .family = AF_INET6, .netif = SOCK_ADDR_ANY_NETIF, + .port = MANET_PORT }; + memcpy(ep.addr.ipv6, &ipv6_addr_all_nodes_link_local, sizeof(ep.addr.ipv6)); + sock_udp_send(&sock, buffer, length, &ep); } -- GitLab