From cb746a1aeae7941fa412ffe368a93c86fe1ecd9d Mon Sep 17 00:00:00 2001 From: goldsimon Date: Thu, 1 Mar 2018 07:08:03 +0100 Subject: [PATCH] zepif: fix destination IP (default should be broadcast, not 0.0.0.0) --- src/include/netif/zepif.h | 12 ++++++++---- src/netif/zepif.c | 17 ++++++++++------- 2 files changed, 18 insertions(+), 11 deletions(-) diff --git a/src/include/netif/zepif.h b/src/include/netif/zepif.h index 0f31811b..04ffdce1 100644 --- a/src/include/netif/zepif.h +++ b/src/include/netif/zepif.h @@ -56,10 +56,14 @@ extern "C" { /** Pass this struct as 'state' to netif_add to control the behaviour * of this netif. If NULL is passed, default behaviour is chosen */ struct zepif_init { - /** The UDP port used for ZEP frames (0 = default) */ - u16_t zep_udp_port; - /** The IP address to sed ZEP frames to */ - const ip_addr_t *zep_ip_addr; + /** The UDP port used to ZEP frames from (0 = default) */ + u16_t zep_src_udp_port; + /** The UDP port used to ZEP frames to (0 = default) */ + u16_t zep_dst_udp_port; + /** The IP address to sed ZEP frames from (NULL = ANY) */ + const ip_addr_t *zep_src_ip_addr; + /** The IP address to sed ZEP frames to (NULL = BROADCAST) */ + const ip_addr_t *zep_dst_ip_addr; /** If != NULL, the udp pcb is bound to this netif */ const struct netif *zep_netif; /** MAC address of the 6LowPAN device */ diff --git a/src/netif/zepif.c b/src/netif/zepif.c index 3fa2bf01..66ecac87 100644 --- a/src/netif/zepif.c +++ b/src/netif/zepif.c @@ -192,7 +192,7 @@ zepif_linkoutput(struct netif *netif, struct pbuf *p) #if ZEPIF_LOOPBACK zepif_udp_recv(netif, state->pcb, pbuf_clone(PBUF_RAW, PBUF_RAM, q), NULL, 0); #endif - err = udp_sendto(state->pcb, q, state->init.zep_ip_addr, state->init.zep_udp_port); + err = udp_sendto(state->pcb, q, state->init.zep_dst_ip_addr, state->init.zep_dst_udp_port); } pbuf_free(q); @@ -214,13 +214,16 @@ zepif_init(struct netif *netif) } memset(state, 0, sizeof(struct zepif_state)); if (init_state != NULL) { - state->init = *init_state; + memcpy(&state->init, init_state, sizeof(struct zepif_init)); } - if (state->init.zep_udp_port == 0) { - state->init.zep_udp_port = ZEPIF_DEFAULT_UDP_PORT; + if (state->init.zep_src_udp_port == 0) { + state->init.zep_src_udp_port = ZEPIF_DEFAULT_UDP_PORT; } - if (state->init.zep_ip_addr == NULL) { - state->init.zep_ip_addr = IP_ADDR_ANY; + if (state->init.zep_dst_udp_port == 0) { + state->init.zep_dst_udp_port = ZEPIF_DEFAULT_UDP_PORT; + } + if (state->init.zep_dst_ip_addr == NULL) { + state->init.zep_dst_ip_addr = IP_ADDR_BROADCAST; } netif->state = NULL; @@ -230,7 +233,7 @@ zepif_init(struct netif *netif) err = ERR_MEM; goto err_ret; } - err = udp_bind(state->pcb, state->init.zep_ip_addr, state->init.zep_udp_port); + err = udp_bind(state->pcb, state->init.zep_src_ip_addr, state->init.zep_src_udp_port); if (err != ERR_OK) { goto err_ret; }