From cbb8d2a64bb6f6651247544e67d58f4c2a814fae Mon Sep 17 00:00:00 2001 From: OBattler Date: Tue, 9 May 2017 04:36:09 +0200 Subject: [PATCH] Change to the MAC address handling. --- src/device.h | 1 + src/net_ne2000.c | 20 ++++++++++++-------- 2 files changed, 13 insertions(+), 8 deletions(-) diff --git a/src/device.h b/src/device.h index fb509ce7f..7dace2286 100644 --- a/src/device.h +++ b/src/device.h @@ -3,6 +3,7 @@ #define CONFIG_BINARY 2 #define CONFIG_SELECTION 3 #define CONFIG_MIDI 4 +#define CONFIG_ETHIF 5 typedef struct device_config_selection_t { diff --git a/src/net_ne2000.c b/src/net_ne2000.c index f1a0eb44d..9647d0856 100644 --- a/src/net_ne2000.c +++ b/src/net_ne2000.c @@ -246,15 +246,15 @@ void ne2000_log(const char *format, ...) #endif } -static uint8_t *ne2000_mac(void) +static void ne2000_mac(uint8_t *mac) { if (network_card_current == 2) { - return maclocal_pci; + memcpy(mac, maclocal_pci, 6); } else { - return maclocal; + memcpy(mac, maclocal, 6); } } @@ -1720,6 +1720,8 @@ void ne2000_poller(void *p) struct pcap_pkthdr h; uint32_t mac_cmp32[2]; uint16_t mac_cmp16[2]; + uint8_t temp_mac[6] = { 0, 0, 0, 0, 0, 0 }; + ne2000_mac(temp_mac); if (!net_is_pcap) { @@ -1756,8 +1758,8 @@ void ne2000_poller(void *p) mac_cmp32[0] = *(uint32_t *) (data+6); mac_cmp16[0] = *(uint16_t *) (data+10); /* Local. */ - mac_cmp32[1] = *(uint32_t *) (ne2000_mac()); - mac_cmp16[1] = *(uint16_t *) (ne2000_mac() + 4); + mac_cmp32[1] = *(uint32_t *) (temp_mac); + mac_cmp16[1] = *(uint16_t *) (temp_mac + 4); if ((mac_cmp32[0] != mac_cmp32[1]) || (mac_cmp16[0] != mac_cmp16[1])) { ne2000_rx_frame(ne2000,data,h.caplen); @@ -2002,6 +2004,7 @@ void *ne2000_init(void) int is_rtl8029as = 0; ne2000_t *ne2000 = malloc(sizeof(ne2000_t)); memset(ne2000, 0, sizeof(ne2000_t)); + uint8_t temp_mac[6] = { 0, 0, 0, 0, 0, 0 }; if (PCI && (network_card_current == 2)) { @@ -2048,7 +2051,8 @@ void *ne2000_init(void) ne2000_io_set(ne2000->base_address, ne2000); - memcpy(ne2000->physaddr, ne2000_mac(), 6); + ne2000_mac(temp_mac); + ne2000_mac(ne2000->physaddr); if (!disable_netbios) { @@ -2192,8 +2196,8 @@ initialize_pcap: char filter_exp[255]; ne2000_log("ne2000 Building packet filter..."); sprintf(filter_exp,"( ((ether dst ff:ff:ff:ff:ff:ff) or (ether dst %02x:%02x:%02x:%02x:%02x:%02x)) and not (ether src %02x:%02x:%02x:%02x:%02x:%02x) )", \ - ne2000_mac()[0], ne2000_mac()[1], ne2000_mac()[2], ne2000_mac()[3], ne2000_mac()[4], ne2000_mac()[5],\ - ne2000_mac()[0], ne2000_mac()[1], ne2000_mac()[2], ne2000_mac()[3], ne2000_mac()[4], ne2000_mac()[5]); + temp_mac[0], temp_mac[1], temp_mac[2], temp_mac[3], temp_mac[4], temp_mac[5],\ + temp_mac[0], temp_mac[1], temp_mac[2], temp_mac[3], temp_mac[4], temp_mac[5]); /* I'm doing a MAC level filter so TCP/IP doesn't matter. */ if (pcap_compile(net_pcap, &fp, filter_exp, 0, 0xffffffff) == -1)