From 42419baa16a1eff8e1c85bf590b75b1876356419 Mon Sep 17 00:00:00 2001 From: Michael Casadevall Date: Sat, 7 Nov 2020 10:02:59 -0500 Subject: [PATCH] Failback for PCAP to use name as description if the later is blank This allows 86Box to use pcap properly under WINE under Linux as most interfaces on Linux leave the description as a NULL. Signed-off-by: Michael Casadevall --- src/network/net_pcap.c | 27 +++++++++++++++++---------- 1 file changed, 17 insertions(+), 10 deletions(-) diff --git a/src/network/net_pcap.c b/src/network/net_pcap.c index 7068443cd..c91d3e80a 100644 --- a/src/network/net_pcap.c +++ b/src/network/net_pcap.c @@ -261,17 +261,24 @@ net_pcap_prepare(netdev_t *list) } for (dev=devlist; dev!=NULL; dev=dev->next) { - if (strlen(dev->name) <= 127) - strcpy(list->device, dev->name); - else - strncpy(list->device, dev->name, 127); - if (dev->description) { - if (strlen(dev->description) <= 127) - strcpy(list->description, dev->description); - else - strncpy(list->description, dev->description, 127); - } else + /** + * we initialize the strings to NULL first for strncpy + */ + + memset(list->device, '\0', sizeof(list->device)); memset(list->description, '\0', sizeof(list->description)); + + strncpy(list->device, dev->name, 127); + if (dev->description) { + if (strlen(dev->description) <= 127) + strcpy(list->description, dev->description); + else + strncpy(list->description, dev->description, 127); + } else { + /* if description is NULL, set the name. This allows pcap to display *something* useful under WINE */ + strncpy(list->description, dev->name, sizeof(list->description)-1); + } + list++; i++; }