1
0
mirror of https://github.com/simh/simh.git synced 2026-01-25 11:46:37 +00:00

Merge branch 'SerialMux' and compiler suggested cleanup

This commit is contained in:
Mark Pizzolato
2012-12-18 09:52:14 -08:00
149 changed files with 11789 additions and 1437 deletions

View File

@@ -528,6 +528,7 @@ void eth_packet_trace_ex(ETH_DEV* dev, const uint8 *msg, int len, char* txt, int
int i, same, group, sidx, oidx;
char outbuf[80], strbuf[18];
static char hex[] = "0123456789ABCDEF";
for (i=same=0; i<len; i += 16) {
if ((i > 0) && (0 == memcmp(&msg[i], &msg[i-16], 16))) {
++same;
@@ -551,8 +552,9 @@ void eth_packet_trace_ex(ETH_DEV* dev, const uint8 *msg, int len, char* txt, int
strbuf[sidx] = '\0';
sim_debug(reason, dev->dptr, "%04X%-48s %s\n", i, outbuf, strbuf);
}
if (same > 0)
if (same > 0) {
sim_debug(reason, dev->dptr, "%04X thru %04X same as above\n", i-(16*same), len-1);
}
}
}
}
@@ -666,6 +668,7 @@ void eth_zero(ETH_DEV* dev)
static ETH_DEV **eth_open_devices = NULL;
static int eth_open_device_count = 0;
#if defined (USE_NETWORK) || defined (USE_SHARED)
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));
@@ -684,6 +687,7 @@ for (i=0; i<eth_open_device_count; ++i)
break;
}
}
#endif
t_stat eth_show (FILE* st, UNIT* uptr, int32 val, void* desc)
{
@@ -702,7 +706,20 @@ t_stat eth_show (FILE* st, UNIT* uptr, int32 val, void* desc)
for (i=0, min=0; i<number; i++)
if ((len = strlen(list[i].name)) > min) min = len;
for (i=0; i<number; i++)
fprintf(st," %2d %-*s (%s)\n", i, (int)min, list[i].name, list[i].desc);
fprintf(st," eth%d\t%-*s (%s)\n", i, (int)min, list[i].name, list[i].desc);
}
if (eth_open_device_count) {
int i;
char desc[ETH_DEV_DESC_MAX], *d;
fprintf(st,"Open ETH Devices:\n");
for (i=0; i<eth_open_device_count; i++) {
d = eth_getdesc_byname(eth_open_devices[i]->name, desc);
if (d)
fprintf(st, " %-7s%s (%s)\n", eth_open_devices[i]->dptr->name, eth_open_devices[i]->dptr->units[0].filename, d);
else
fprintf(st, " %-7s%s\n", eth_open_devices[i]->dptr->name, eth_open_devices[i]->dptr->units[0].filename);
}
}
if (eth_open_device_count) {
int i;
@@ -785,7 +802,7 @@ void ethq_remove(ETH_QUE* que)
}
}
void ethq_insert_data(ETH_QUE* que, int32 type, const uint8 *data, int used, int len, int crc_len, const uint8 *crc_data, int32 status)
void ethq_insert_data(ETH_QUE* que, int32 type, const uint8 *data, int used, size_t len, size_t crc_len, const uint8 *crc_data, int32 status)
{
struct eth_item* item;
@@ -960,11 +977,11 @@ static char* (*p_pcap_lib_version) (void);
/* load function pointer from DLL */
typedef int (*_func)();
void load_function(char* function, _func* func_ptr) {
static void load_function(char* function, _func* func_ptr) {
#ifdef _WIN32
*func_ptr = (_func)GetProcAddress(hLib, function);
*func_ptr = (_func)((size_t)GetProcAddress(hLib, function));
#else
*func_ptr = (_func)dlsym(hLib, function);
*func_ptr = (_func)((size_t)dlsym(hLib, function));
#endif
if (*func_ptr == 0) {
char* msg = "Eth: Failed to find function '%s' in %s\r\n";
@@ -1411,7 +1428,7 @@ static void eth_get_nic_hw_addr(ETH_DEV* dev, char *devname)
memset(command, 0, sizeof(command));
for (i=0; patterns[i] && (0 == dev->have_host_nic_phy_addr); ++i) {
snprintf(command, sizeof(command)-1, "ifconfig %s | %s >NIC.hwaddr", devname, patterns[i]);
system(command);
(void)system(command);
if (NULL != (f = fopen("NIC.hwaddr", "r"))) {
while (0 == dev->have_host_nic_phy_addr) {
if (fgets(command, sizeof(command)-1, f)) {
@@ -1421,7 +1438,7 @@ static void eth_get_nic_hw_addr(ETH_DEV* dev, char *devname)
while (p1) {
p2 = strchr(p1+1, ':');
if (p2 <= p1+3) {
int mac_bytes[6];
unsigned int mac_bytes[6];
if (6 == sscanf(p1-2, "%02x:%02x:%02x:%02x:%02x:%02x", &mac_bytes[0], &mac_bytes[1], &mac_bytes[2], &mac_bytes[3], &mac_bytes[4], &mac_bytes[5])) {
dev->host_nic_phy_hw_addr[0] = mac_bytes[0];
dev->host_nic_phy_hw_addr[1] = mac_bytes[1];
@@ -1469,7 +1486,7 @@ HANDLE hWait = pcap_getevent ((pcap_t*)dev->handle);
#else
int sel_ret;
int do_select = 0;
int select_fd;
int select_fd = 0;
switch (dev->eth_api) {
case ETH_API_PCAP:
@@ -1697,7 +1714,6 @@ memset(errbuf, 0, sizeof(errbuf));
if (0 == strncmp("tap:", savname, 4)) {
int tun = -1; /* TUN/TAP Socket */
int on = 1;
char dev_name[64] = "";
#if defined(USE_TAP_NETWORK)
if (!strcmp(savname, "tap:tapN")) {
@@ -1733,41 +1749,45 @@ if (0 == strncmp("tap:", savname, 4)) {
else
strncpy(errbuf, strerror(errno), sizeof(errbuf)-1);
#elif defined(USE_BSDTUNTAP) && defined(USE_TAP_NETWORK)
snprintf(dev_name, sizeof(dev_name)-1, "/dev/%s", savname+4);
dev_name[sizeof(dev_name)-1] = '\0';
if (1) {
char dev_name[64] = "";
if ((tun = open(dev_name, O_RDWR)) >= 0) {
if (ioctl(tun, FIONBIO, &on)) {
strncpy(errbuf, strerror(errno), sizeof(errbuf)-1);
close(tun);
}
else {
dev->fd_handle = tun;
strcpy(savname, savname+4);
}
#if defined (__APPLE__)
if (1) {
struct ifreq ifr;
int s;
snprintf(dev_name, sizeof(dev_name)-1, "/dev/%s", savname+4);
dev_name[sizeof(dev_name)-1] = '\0';
memset (&ifr, 0, sizeof(ifr));
ifr.ifr_addr.sa_family = AF_INET;
strncpy(ifr.ifr_name, savname, sizeof(ifr.ifr_name));
if ((s = socket(AF_INET, SOCK_DGRAM, 0)) >= 0) {
if (ioctl(s, SIOCGIFFLAGS, (caddr_t)&ifr) >= 0) {
ifr.ifr_flags |= IFF_UP;
if (ioctl(s, SIOCSIFFLAGS, (caddr_t)&ifr)) {
strncpy(errbuf, strerror(errno), sizeof(errbuf)-1);
close(tun);
}
}
close(s);
if ((tun = open(dev_name, O_RDWR)) >= 0) {
if (ioctl(tun, FIONBIO, &on)) {
strncpy(errbuf, strerror(errno), sizeof(errbuf)-1);
close(tun);
}
else {
dev->fd_handle = tun;
strcpy(savname, savname+4);
}
#if defined (__APPLE__)
if (1) {
struct ifreq ifr;
int s;
memset (&ifr, 0, sizeof(ifr));
ifr.ifr_addr.sa_family = AF_INET;
strncpy(ifr.ifr_name, savname, sizeof(ifr.ifr_name));
if ((s = socket(AF_INET, SOCK_DGRAM, 0)) >= 0) {
if (ioctl(s, SIOCGIFFLAGS, (caddr_t)&ifr) >= 0) {
ifr.ifr_flags |= IFF_UP;
if (ioctl(s, SIOCSIFFLAGS, (caddr_t)&ifr)) {
strncpy(errbuf, strerror(errno), sizeof(errbuf)-1);
close(tun);
}
}
close(s);
}
}
}
#endif
}
else
strncpy(errbuf, strerror(errno), sizeof(errbuf)-1);
}
else
strncpy(errbuf, strerror(errno), sizeof(errbuf)-1);
}
#else
strncpy(errbuf, "No support for tap: devices", sizeof(errbuf)-1);
#endif /* !defined(__linux) && !defined(USE_BSDTUNTAP) */
@@ -2116,13 +2136,13 @@ if ((packet->len >= ETH_MIN_PACKET) && (packet->len <= ETH_MAX_PACKET)) {
break;
#ifdef USE_TAP_NETWORK
case ETH_API_TAP:
status = ((packet->len == write(dev->fd_handle, (void *)packet->msg, packet->len)) ? 0 : -1);
status = (((int)packet->len == write(dev->fd_handle, (void *)packet->msg, packet->len)) ? 0 : -1);
break;
#endif
#ifdef USE_VDE_NETWORK
case ETH_API_VDE:
status = vde_send((VDECONN*)dev->handle, (void *)packet->msg, packet->len, 0);
if ((status == packet->len) || (status == 0))
if ((status == (int)packet->len) || (status == 0))
status = 0;
else
if ((status == -1) && ((errno == EAGAIN) || (errno == EWOULDBLOCK)))
@@ -2218,6 +2238,7 @@ key ^= 0x3f;
return (hash[key>>3] & (1 << (key&0x7)));
}
#if 0
static int
_eth_hash_validate(ETH_MAC *MultiCastList, int count, ETH_MULTIHASH hash)
{
@@ -2269,6 +2290,7 @@ ETH_MULTIHASH thash = {0x01, 0x40, 0x00, 0x00, 0x48, 0x88, 0x40, 0x00};
_eth_hash_validate(tMacs, sizeof(tMacs)/sizeof(tMacs[0]), thash);
}
#endif
/* The IP header */
struct IPHeader {
@@ -2936,10 +2958,12 @@ if (dev->dptr->dctrl & dev->dbit) {
eth_mac_fmt(&dev->filter_address[i], mac);
sim_debug(dev->dbit, dev->dptr, " Addr[%d]: %s\n", i, mac);
}
if (dev->all_multicast)
if (dev->all_multicast) {
sim_debug(dev->dbit, dev->dptr, "All Multicast\n");
if (dev->promiscuous)
}
if (dev->promiscuous) {
sim_debug(dev->dbit, dev->dptr, "Promiscuous\n");
}
}
/* setup BPF filters and other fields to minimize packet delivery */