From cac420aec5b8b9bc2016bca5c6704d72c69b2ad7 Mon Sep 17 00:00:00 2001 From: Simon Goldschmidt Date: Fri, 21 Oct 2011 20:03:37 +0200 Subject: [PATCH] pcapif: remove trailing spaces from adapter names, deleted old (unused) files --- ports/win32/pcap_helper.c | 70 --------------------------------------- ports/win32/pcap_helper.h | 11 ------ ports/win32/pcapif.c | 10 +++++- 3 files changed, 9 insertions(+), 82 deletions(-) delete mode 100644 ports/win32/pcap_helper.c delete mode 100644 ports/win32/pcap_helper.h diff --git a/ports/win32/pcap_helper.c b/ports/win32/pcap_helper.c deleted file mode 100644 index 6796e30..0000000 --- a/ports/win32/pcap_helper.c +++ /dev/null @@ -1,70 +0,0 @@ -#include "pcap_helper.h" - -#define WIN32_LEAN_AND_MEAN -/* get the windows definitions of the following 4 functions out of the way */ -#include -#include -#define HAVE_REMOTE -#include "pcap.h" - -/** Get the index of an adapter by its network address - * - * @param netaddr network address of the adapter (e.g. 192.168.1.0) - * @return index of the adapter or negative on error - */ -int -get_adapter_index_from_addr(struct in_addr *netaddr, char *guid, size_t guid_len) -{ - pcap_if_t *alldevs; - pcap_if_t *d; - char errbuf[PCAP_ERRBUF_SIZE+1]; - char source[] = "rpcap://"; - int index = 0; - - memset(guid, 0, guid_len); - memset(errbuf, 0, sizeof(errbuf)); - - /* Retrieve the interfaces list */ - if (pcap_findalldevs_ex(source, NULL, &alldevs, errbuf) == -1) { - printf("Error in pcap_findalldevs: %s\n", errbuf); - return -1; - } - /* Scan the list printing every entry */ - for (d = alldevs; d != NULL; d = d->next, index++) { - pcap_addr_t *a; - for(a = d->addresses; a != NULL; a = a->next) { - if (a->addr->sa_family == AF_INET) { - ULONG a_addr = ((struct sockaddr_in *)a->addr)->sin_addr.s_addr; - ULONG a_netmask = ((struct sockaddr_in *)a->netmask)->sin_addr.s_addr; - ULONG a_netaddr = a_addr & a_netmask; - ULONG addr = (*netaddr).s_addr; - if (a_netaddr == addr) { - int ret = -1; - char name[128]; - char *start, *end; - size_t len = strlen(d->name); - if(len > 127) { - len = 127; - } - memcpy(name, d->name, len); - name[len] = 0; - start = strstr(name, "{"); - if (start != NULL) { - end = strstr(start, "}"); - if (end != NULL) { - size_t len = end - start + 1; - memcpy(guid, start, len); - ret = index; - } - } - pcap_freealldevs(alldevs); - return ret; - } - } - } - } - printf("Network address not found.\n"); - - pcap_freealldevs(alldevs); - return -1; -} diff --git a/ports/win32/pcap_helper.h b/ports/win32/pcap_helper.h deleted file mode 100644 index 7e21aee..0000000 --- a/ports/win32/pcap_helper.h +++ /dev/null @@ -1,11 +0,0 @@ -#ifndef __PCAP_HELPER_H__ -#define __PCAP_HELPER_H__ - -#include - -struct in_addr; - - -int get_adapter_index_from_addr(struct in_addr* netaddr, char *guid, size_t guid_len); - -#endif /* __PCAP_HELPER_H__ */ \ No newline at end of file diff --git a/ports/win32/pcapif.c b/ports/win32/pcapif.c index 1708ee8..7388a76 100644 --- a/ports/win32/pcapif.c +++ b/ports/win32/pcapif.c @@ -293,6 +293,10 @@ pcapif_init_adapter(int adapter_num, void *arg) desc += 17; } len = LWIP_MIN(len, ADAPTER_DESC_LEN-1); + while ((desc[len-1] == ' ') || (desc[len-1] == '\t')) { + /* don't copy trailing whitespace */ + len--; + } strncpy(pa->description, desc, len); pa->description[len] = 0; } else { @@ -307,7 +311,7 @@ pcapif_init_adapter(int adapter_num, void *arg) char *desc = d->description; char descBuf[128]; size_t len; - const char* devname = d->name;; + const char* devname = d->name; if (d->name == NULL) { devname = ""; } else { @@ -331,6 +335,10 @@ pcapif_init_adapter(int adapter_num, void *arg) desc += 17; } len = LWIP_MIN(len, 127); + while ((desc[len-1] == ' ') || (desc[len-1] == '\t')) { + /* don't copy trailing whitespace */ + len--; + } strncpy(descBuf, desc, len); descBuf[len] = 0; printf(" Desc: \"%s\"\n", descBuf);