From 83172116e8f8651cbabf4f4bd54c277d5df5d2c0 Mon Sep 17 00:00:00 2001 From: Mark Pizzolato Date: Wed, 25 Apr 2012 05:29:50 -0700 Subject: [PATCH] Added SHOW ETHERNET command and extended eth_show to track and display open ethernet devices --- scp.c | 3 +++ sim_ether.c | 64 +++++++++++++++++++++++++++++++++++++++++++++++++++-- sim_ether.h | 6 +++-- 3 files changed, 69 insertions(+), 4 deletions(-) diff --git a/scp.c b/scp.c index b4598ab8..aece202b 100644 --- a/scp.c +++ b/scp.c @@ -215,6 +215,7 @@ #include "sim_defs.h" #include "sim_rev.h" +#include "sim_ether.h" #include #include #include @@ -693,6 +694,7 @@ static CTAB cmd_table[] = { "sh{ow} SHOW show device SHOW commands\n" "sh{ow} {arg,...} show device parameters\n" "sh{ow} {arg,...} show unit parameters\n" + "sh{ow} ethernet show ethernet devices\n" "sh{ow} on show on condition actions\n" }, { "DO", &do_cmd, 1, "do {-V} {-O} {-E} {-Q} {arg,arg...}\b" @@ -2035,6 +2037,7 @@ static SHTAB show_glob_tab[] = { { "DEBUG", &sim_show_debug, 0 }, /* deprecated */ { "THROTTLE", &sim_show_throt, 0 }, { "ASYNCH", &sim_show_asynch, 0 }, + { "ETHERNET", ð_show_devices, 0 }, { "ON", &show_on, 0 }, { NULL, NULL, 0 } }; diff --git a/sim_ether.c b/sim_ether.c index d6d556ef..cbb54161 100644 --- a/sim_ether.c +++ b/sim_ether.c @@ -637,6 +637,25 @@ char* eth_getname_byname(char* name, char* temp) return (found ? temp : NULL); } +char* eth_getdesc_byname(char* name, char* temp) +{ + ETH_LIST list[ETH_MAX_DEVICE]; + int count = eth_devices(ETH_MAX_DEVICE, list); + size_t n; + int i, found; + + found = 0; + n = strlen(name); + for (i=0; ireflections = -1; /* not established yet */ } +static ETH_DEV **eth_open_devices = NULL; +static eth_open_device_count = 0; + +static void _eth_add_to_open_list (ETH_DEV* dev) +{ +eth_open_devices = realloc(eth_open_devices, (eth_open_device_count+1)*sizeof(*eth_open_devices)); +eth_open_devices[eth_open_device_count++] = dev; +} + +static void _eth_remove_from_open_list (ETH_DEV* dev) +{ +int i, j; + +for (i=0; i min) min = len; for (i=0; iname, desc); + if (d) + fprintf(st, " %-7s%s (%s)\n", eth_open_devices[i]->dptr->name, eth_open_devices[i]->name, d); + else + fprintf(st, " %-7s%s\n", eth_open_devices[i]->dptr->name, eth_open_devices[i]->name); + } } return SCPE_OK; } +t_stat eth_show_devices (FILE* st, DEVICE *dptr, UNIT* uptr, int32 val, void* desc) +{ +return eth_show (st, uptr, val, desc); +} + t_stat ethq_init(ETH_QUE* que, int max) { /* create dynamic queue if it does not exist */ @@ -1800,6 +1859,7 @@ if (dev->eth_api == ETH_API_PCAP) { ioctl(pcap_fileno(dev->handle), BIOCIMMEDIATE, &v); } #endif +_eth_add_to_open_list (dev); return SCPE_OK; } @@ -1862,7 +1922,7 @@ if (sim_log) fprintf (sim_log, msg, dev->name); /* clean up the mess */ free(dev->name); eth_zero(dev); - +_eth_remove_from_open_list (dev); return SCPE_OK; } diff --git a/sim_ether.h b/sim_ether.h index 4e549d98..f26e2e39 100644 --- a/sim_ether.h +++ b/sim_ether.h @@ -288,8 +288,10 @@ uint32 eth_crc32(uint32 crc, const void* vbuf, size_t len); /* Compute Ethernet void eth_packet_trace (ETH_DEV* dev, const uint8 *msg, int len, char* txt); /* trace ethernet packet header+crc */ void eth_packet_trace_ex (ETH_DEV* dev, const uint8 *msg, int len, char* txt, int detail, uint32 reason); /* trace ethernet packet */ -t_stat eth_show (FILE* st, UNIT* uptr, /* show ethernet devices */ - int32 val, void* desc); +t_stat eth_show (FILE* st, UNIT* uptr, /* show ethernet devices */ + int32 val, void* desc); +t_stat eth_show_devices (FILE* st, DEVICE *dptr, /* show ethernet devices */ + UNIT* uptr, int32 val, void* desc); void eth_show_dev (FILE*st, ETH_DEV* dev); /* show ethernet device state */ void eth_mac_fmt (ETH_MAC* add, char* buffer); /* format ethernet mac address */