From 1ca05f0c0857487e3121e2efd0d1cba6d75ffcb3 Mon Sep 17 00:00:00 2001 From: "Martine S. Lenders" Date: Mon, 16 Sep 2019 13:59:13 +0200 Subject: [PATCH] gnrc_netif_ethernet: fix debug output for received packet A received packet is outputted in DEBUG _after_ it was already parsed, but with a reference to the already parsed header. The result is that there can be some garbage in the output and the packet is not dumped in total. As without parsing we do not have access to the header yet, we use the `gnrc_netif_addr_to_str()` helper function instead of parsing the destination address by hand. --- .../gnrc/netif/ethernet/gnrc_netif_ethernet.c | 16 ++++++++-------- 1 file changed, 8 insertions(+), 8 deletions(-) diff --git a/sys/net/gnrc/netif/ethernet/gnrc_netif_ethernet.c b/sys/net/gnrc/netif/ethernet/gnrc_netif_ethernet.c index d15aecbbf9..8517cc1d6b 100644 --- a/sys/net/gnrc/netif/ethernet/gnrc_netif_ethernet.c +++ b/sys/net/gnrc/netif/ethernet/gnrc_netif_ethernet.c @@ -34,6 +34,8 @@ static int _send(gnrc_netif_t *netif, gnrc_pktsnip_t *pkt); static gnrc_pktsnip_t *_recv(gnrc_netif_t *netif); +static char addr_str[ETHERNET_ADDR_LEN * 3]; + static const gnrc_netif_ops_t ethernet_ops = { .send = _send, .recv = _recv, @@ -196,6 +198,12 @@ static gnrc_pktsnip_t *_recv(gnrc_netif_t *netif) gnrc_pktbuf_realloc_data(pkt, nread); } + DEBUG("gnrc_netif_ethernet: received packet from %s of length %d\n", + gnrc_netif_addr_to_str(pkt->data, ETHERNET_ADDR_LEN, addr_str), + nread); +#if defined(MODULE_OD) && ENABLE_DEBUG + od_hex_dump(pkt->data, nread, OD_WIDTH_DEFAULT); +#endif /* mark ethernet header */ gnrc_pktsnip_t *eth_hdr = gnrc_pktbuf_mark(pkt, sizeof(ethernet_hdr_t), GNRC_NETTYPE_UNDEF); if (!eth_hdr) { @@ -232,14 +240,6 @@ static gnrc_pktsnip_t *_recv(gnrc_netif_t *netif) gnrc_netif_hdr_set_dst_addr(netif_hdr->data, hdr->dst, ETHERNET_ADDR_LEN); gnrc_netif_hdr_set_netif(netif_hdr->data, netif); - DEBUG("gnrc_netif_ethernet: received packet from %02x:%02x:%02x:%02x:%02x:%02x " - "of length %d\n", - hdr->src[0], hdr->src[1], hdr->src[2], hdr->src[3], hdr->src[4], - hdr->src[5], nread); -#if defined(MODULE_OD) && ENABLE_DEBUG - od_hex_dump(hdr, nread, OD_WIDTH_DEFAULT); -#endif - gnrc_pktbuf_remove_snip(pkt, eth_hdr); LL_APPEND(pkt, netif_hdr); }