Browse Source

lwip: initial import of conn_udp wrapper

pr/gpio
Martine Lenders 7 years ago
parent
commit
5431df6a7e
  1. 4
      Makefile.dep
  2. 3
      pkg/lwip/Makefile.include
  3. 3
      pkg/lwip/contrib/conn/udp/Makefile
  4. 75
      pkg/lwip/contrib/conn/udp/lwip_conn_udp.c
  5. 4
      sys/include/net/conn/udp.h

4
Makefile.dep

@ -381,6 +381,10 @@ ifneq (,$(filter lwip_conn_ip,$(USEMODULE)))
USEMODULE += lwip_raw
endif
ifneq (,$(filter lwip_conn_udp,$(USEMODULE)))
USEMODULE += lwip_udp
endif
ifneq (,$(filter lwip_%,$(USEMODULE)))
USEMODULE += lwip
endif

3
pkg/lwip/Makefile.include

@ -7,6 +7,9 @@ endif
ifneq (,$(filter lwip_conn_ip,$(USEMODULE)))
DIRS += $(RIOTBASE)/pkg/lwip/contrib/conn/ip
endif
ifneq (,$(filter lwip_conn_udp,$(USEMODULE)))
DIRS += $(RIOTBASE)/pkg/lwip/contrib/conn/udp
endif
ifneq (,$(filter lwip_contrib,$(USEMODULE)))
DIRS += $(RIOTBASE)/pkg/lwip/contrib
endif

3
pkg/lwip/contrib/conn/udp/Makefile

@ -0,0 +1,3 @@
MODULE := lwip_conn_udp
include $(RIOTBASE)/Makefile.base

75
pkg/lwip/contrib/conn/udp/lwip_conn_udp.c

@ -0,0 +1,75 @@
/*
* Copyright (C) 2015 Freie Universität Berlin
*
* 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.
*/
/**
* @{
*
* @file
* @author Martine Lenders <mlenders@inf.fu-berlin.de>
*/
#include <assert.h>
#include <errno.h>
#include "net/ipv4/addr.h"
#include "net/ipv6/addr.h"
#include "net/conn/udp.h"
#include "lwip/api.h"
#include "lwip/conn.h"
int conn_udp_create(conn_udp_t *conn, const void *addr, size_t addr_len, int family, uint16_t port)
{
struct netconn *tmp;
int res;
res = lwip_conn_create(&tmp, addr, addr_len, family, NETCONN_UDP, 0, port);
if (res < 0) {
return res;
}
conn->lwip_conn = tmp;
return res;
}
void conn_udp_close(conn_udp_t *conn)
{
assert(conn != NULL);
netconn_delete(conn->lwip_conn);
}
int conn_udp_getlocaladdr(conn_udp_t *conn, void *addr, uint16_t *port)
{
assert(conn != NULL);
return lwip_conn_getlocaladdr(conn->lwip_conn, addr, port);
}
int conn_udp_recvfrom(conn_udp_t *conn, void *data, size_t max_len, void *addr, size_t *addr_len,
uint16_t *port)
{
assert(conn != NULL);
return lwip_conn_recvfrom(conn->lwip_conn, data, max_len, addr, addr_len, port);
}
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)
{
struct netconn *tmp;
int res;
res = lwip_conn_create(&tmp, src, src_len, family, NETCONN_UDP, 0, sport);
if (res < 0) {
return res;
}
res = lwip_conn_sendto(tmp, data, len, dst, dst_len, dport);
netconn_delete(tmp);
return res;
}
/** @} */

4
sys/include/net/conn/udp.h

@ -27,6 +27,10 @@
#include "net/gnrc/conn.h"
#endif
#ifdef MODULE_LWIP_CONN_UDP
#include "lwip/conn.h"
#endif
#ifdef __cplusplus
extern "C" {
#endif

Loading…
Cancel
Save