Skip to content

Commit 6fd146a

Browse files
NattyNarwhalpkoning2
authored andcommitted
Keep track of generated vmnet MAC addr
The vmnet interface created for a simh instance has its own MAC address. It doesn't seem too useful to for simh itself (you can just use whatever MAC address and send/receive frames with that), but it does make referencing it in other places (i.e. SHOW ETHERNET vs. ifconfig) easier. The generated MAC address is provided at interface creation time; while we could look it up earlier like with pcap, this seems more efficient.
1 parent a0df08a commit 6fd146a

File tree

1 file changed

+22
-0
lines changed

1 file changed

+22
-0
lines changed

sim_ether.c

Lines changed: 22 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -1805,6 +1805,10 @@ return tool;
18051805

18061806
static void eth_get_nic_hw_addr(ETH_DEV* dev, const char *devname, int set_on)
18071807
{
1808+
// we set this at interface creation time in open_port for vmnet
1809+
if (dev->eth_api == ETH_API_VMN) {
1810+
return;
1811+
}
18081812
memset(&dev->host_nic_phy_hw_addr, 0, sizeof(dev->host_nic_phy_hw_addr));
18091813
dev->have_host_nic_phy_addr = 0;
18101814
if (dev->eth_api != ETH_API_PCAP)
@@ -2361,9 +2365,27 @@ memset(errbuf, 0, PCAP_ERRBUF_SIZE);
23612365

23622366
cb_finished = dispatch_semaphore_create(0);
23632367

2368+
// Set the MAC address
2369+
__block ETH_DEV *eth_dev = (ETH_DEV*)opaque;
2370+
23642371
vmn_interface = vmnet_start_interface(if_desc, vmn_queue, ^(vmnet_return_t status, xpc_object_t params){
23652372
vmn_status = status;
23662373

2374+
if (vmn_status == VMNET_SUCCESS) {
2375+
// Scan like eth_scan_mac but simplified (only one format)
2376+
const char *mac_string = xpc_dictionary_get_string(params, vmnet_mac_address_key);
2377+
int a[6];
2378+
if (6 == sscanf(mac_string, "%x:%x:%x:%x:%x:%x", &a[0], &a[1], &a[2], &a[3], &a[4], &a[5])) {
2379+
eth_dev->have_host_nic_phy_addr = 1;
2380+
eth_dev->host_nic_phy_hw_addr[0] = a[0];
2381+
eth_dev->host_nic_phy_hw_addr[1] = a[1];
2382+
eth_dev->host_nic_phy_hw_addr[2] = a[2];
2383+
eth_dev->host_nic_phy_hw_addr[3] = a[3];
2384+
eth_dev->host_nic_phy_hw_addr[4] = a[4];
2385+
eth_dev->host_nic_phy_hw_addr[5] = a[5];
2386+
}
2387+
}
2388+
23672389
dispatch_semaphore_signal(cb_finished);
23682390
});
23692391
dispatch_semaphore_wait(cb_finished, DISPATCH_TIME_FOREVER);

0 commit comments

Comments
 (0)