From 36ab2047abd0f33d3709d96225fddb1797ec0ba9 Mon Sep 17 00:00:00 2001 From: waltje Date: Mon, 12 Nov 2018 16:12:41 -0500 Subject: [PATCH] Changes to how network providers are loaded. --- src/devices/network/net_pcap.c | 18 ++++++++++++----- src/devices/network/net_slirp.c | 35 +++++++++++++++++++++------------ src/devices/network/network.c | 35 ++++++++++++++++++++++----------- src/devices/network/network.h | 5 ++++- src/devices/system/intel.c | 4 ++-- src/ui/lang/VARCem.def | 4 ++-- src/ui/ui_resource.h | 4 ++-- 7 files changed, 68 insertions(+), 37 deletions(-) diff --git a/src/devices/network/net_pcap.c b/src/devices/network/net_pcap.c index fd4a175..9e2e9a7 100644 --- a/src/devices/network/net_pcap.c +++ b/src/devices/network/net_pcap.c @@ -8,7 +8,7 @@ * * Handle WinPcap library processing. * - * Version: @(#)net_pcap.c 1.0.9 2018/11/06 + * Version: @(#)net_pcap.c 1.0.10 2018/11/12 * * Author: Fred N. van Kempen, * @@ -174,7 +174,6 @@ static int net_pcap_init(netdev_t *list) { char errbuf[PCAP_ERRBUF_SIZE]; - wchar_t temp[512]; pcap_if_t *devlist, *dev; char *str = PCAP_DLL_PATH; int i = 0; @@ -185,9 +184,9 @@ net_pcap_init(netdev_t *list) /* Try loading the DLL. */ pcap_handle = dynld_module(str, pcap_imports); if (pcap_handle == NULL) { - swprintf(temp, sizeof_w(temp), - get_string(IDS_ERR_NOLIB), "PCap", str); - ui_msgbox(MBX_ERROR, temp); + /* Forward module name back to caller. */ + strcpy(list->description, str); + ERRLOG("PCAP: unable to load '%s', PCAP not available!\n", str); return(-1); } else { @@ -325,6 +324,14 @@ net_pcap_reset(uint8_t *mac) } +/* Are we available or not? */ +static int +net_pcap_available(void) +{ + return((pcap_handle != NULL) ? 1 : 0); +} + + /* Send a packet to the Pcap interface. */ static void net_pcap_send(uint8_t *bufp, int len) @@ -348,5 +355,6 @@ const network_t network_pcap = { net_pcap_init, net_pcap_close, net_pcap_reset, + net_pcap_available, net_pcap_send }; diff --git a/src/devices/network/net_slirp.c b/src/devices/network/net_slirp.c index 63bd2eb..ec60db9 100644 --- a/src/devices/network/net_slirp.c +++ b/src/devices/network/net_slirp.c @@ -8,7 +8,7 @@ * * Handle SLiRP library processing. * - * Version: @(#)net_slirp.c 1.0.5 2018/11/06 + * Version: @(#)net_slirp.c 1.0.6 2018/11/12 * * Author: Fred N. van Kempen, * @@ -50,7 +50,11 @@ #include #include #include -//#include +#ifdef USE_LIBSLIRP +# include +#else +typedef void slirp_t; /* nicer than void.. */ +#endif #define HAVE_STDARG_H #define netdbg network_log #include "../../emu.h" @@ -67,9 +71,6 @@ #endif -typedef void slirp_t; /* nicer than void.. */ - - static volatile void *slirp_handle; /* handle to SLiRP DLL */ static slirp_t *slirp; /* SLiRP library handle */ static volatile thread_t *poll_tid; @@ -204,18 +205,17 @@ slirp_can_output(void) * be properly initialized. */ static int -net_slirp_init(UNUSED(netdev_t *arg)) +net_slirp_init(netdev_t *list) { - wchar_t temp[512]; - char tempA[128]; + char temp[128]; const char *fn = SLIRP_DLL_PATH; /* Try loading the DLL. */ slirp_handle = dynld_module(fn, slirp_imports); if (slirp_handle == NULL) { - swprintf(temp, sizeof_w(temp), - get_string(IDS_ERR_NOLIB), "SLiRP", fn); - ui_msgbox(MBX_ERROR, temp); + /* Forward module name back to caller. */ + strcpy(list->description, fn); + ERRLOG("SLIRP: unable to load '%s', SLiRP not available!\n", fn); return(-1); } else { @@ -226,11 +226,11 @@ net_slirp_init(UNUSED(netdev_t *arg)) SLIRP_debug(handle_logging); /* Get the library version. */ - if (SLIRP_version(tempA, sizeof(tempA)) <= 0) { + if (SLIRP_version(temp, sizeof(temp)) <= 0) { ERRLOG("SLiRP could not get version!\n"); return(-1); } - INFO("SLiRP: initializing, version %s ..\n", tempA); + INFO("SLiRP: initializing, version %s ..\n", temp); return(1); } @@ -292,6 +292,14 @@ net_slirp_close(void) } +/* Are we available or not? */ +static int +net_slirp_available(void) +{ + return((slirp_handle != NULL) ? 1 : 0); +} + + /* Send a packet to the SLiRP interface. */ static void net_slirp_send(uint8_t *pkt, int pkt_len) @@ -311,5 +319,6 @@ const network_t network_slirp = { net_slirp_init, net_slirp_close, net_slirp_reset, + net_slirp_available, net_slirp_send }; diff --git a/src/devices/network/network.c b/src/devices/network/network.c index 1eb7c74..d84afe4 100644 --- a/src/devices/network/network.c +++ b/src/devices/network/network.c @@ -8,7 +8,7 @@ * * Implementation of the network module. * - * Version: @(#)network.c 1.0.17 2018/11/06 + * Version: @(#)network.c 1.0.18 2018/11/12 * * Author: Fred N. van Kempen, * @@ -92,11 +92,13 @@ static const struct { const network_t *net; } networks[] = { { "none", NULL }, + { "slirp", &network_slirp }, { "pcap", &network_pcap }, #ifdef USE_VNS { "vns", &network_vns }, #endif + { NULL, NULL } }; @@ -141,10 +143,8 @@ network_getname(int net) int network_available(int net) { -#if 0 - if (networks[net].net != NULL) + if (networks[net].net && networks[net].net->available) return(networks[net].net->available()); -#endif return(1); } @@ -256,6 +256,7 @@ network_end(void) void network_init(void) { + wchar_t temp[512]; int i, k; /* Clear the local data. */ @@ -271,14 +272,24 @@ network_init(void) network_host_ndev = 1; /* Initialize the network provider modules, if present. */ - i = 0; - while (networks[i].internal_name != NULL) { - if (networks[i].net != NULL) { - k = networks[i].net->init(&network_host_devs[network_host_ndev]); - if (k > 0) - network_host_ndev += k; + for (i = 0; networks[i].internal_name != NULL; i++) { + if (networks[i].net == NULL) continue; + + /* Try to load network provider module. */ + k = networks[i].net->init(&network_host_devs[network_host_ndev]); + if ((k < 0) && (i == network_type)) { + /* Provider not available. */ + swprintf(temp, sizeof_w(temp), + get_string(IDS_ERR_NOLIB), + networks[i].net->name, + network_host_devs[network_host_ndev].description); + ui_msgbox(MBX_ERROR, temp); + continue; } - i++; + + /* If they have interfaces, add them. */ + if (k > 0) + network_host_ndev += k; } } @@ -306,7 +317,7 @@ network_attach(void *dev, uint8_t *mac, NETRXCB rx) if (networks[network_type].net->reset(mac) < 0) { /* Tell user we can't do this (at the moment.) */ swprintf(temp, sizeof_w(temp), - get_string(IDS_ERR_PCAP), networks[network_type].net->name); + get_string(IDS_ERR_NONET), networks[network_type].net->name); ui_msgbox(MBX_ERROR, temp); // FIXME: we should ask in the dialog if they want to diff --git a/src/devices/network/network.h b/src/devices/network/network.h index 11b5714..270488c 100644 --- a/src/devices/network/network.h +++ b/src/devices/network/network.h @@ -8,7 +8,7 @@ * * Definitions for the network module. * - * Version: @(#)network.h 1.0.7 2018/11/06 + * Version: @(#)network.h 1.0.8 2018/11/12 * * Author: Fred N. van Kempen, * @@ -59,17 +59,20 @@ enum { typedef void (*NETRXCB)(void *, uint8_t *bufp, int); +/* Define a host interface entry for a network provider. */ typedef struct { char device[128]; char description[128]; } netdev_t; +/* Define a network provider. */ typedef struct { const char *name; int (*init)(netdev_t *); void (*close)(void); int (*reset)(uint8_t *); + int (*available)(void); void (*send)(uint8_t *, int); } network_t; diff --git a/src/devices/system/intel.c b/src/devices/system/intel.c index 2531d1b..681968c 100644 --- a/src/devices/system/intel.c +++ b/src/devices/system/intel.c @@ -8,7 +8,7 @@ * * Implementation of Intel mainboards. * - * Version: @(#)intel.c 1.0.6 2018/11/08 + * Version: @(#)intel.c 1.0.7 2018/11/11 * * Authors: Fred N. van Kempen, * Miran Grca, @@ -115,7 +115,7 @@ timer_read(uint16_t addr, void *priv) if (dev->timer < 0) return 0; - latch = dev->timer / TIMER_USEC; + latch = (uint16_t)(dev->timer / TIMER_USEC); if (addr & 1) ret = latch >> 8; diff --git a/src/ui/lang/VARCem.def b/src/ui/lang/VARCem.def index 81fe3f8..2803ab0 100644 --- a/src/ui/lang/VARCem.def +++ b/src/ui/lang/VARCem.def @@ -8,7 +8,7 @@ * * String table for the application, shared by all platforms. * - * Version: @(#)VARCem.def 1.0.3 2018/10/18 + * Version: @(#)VARCem.def 1.0.4 2018/11/12 * * Author: Fred N. van Kempen, * @@ -58,7 +58,7 @@ STRTBL( IDS_WARNING, STR_2103 ) /* System errors (2200.) */ STRTBL( IDS_ERR_ACCEL, STR_2200 ) STRTBL( IDS_ERR_INPUT, STR_2201 ) -STRTBL( IDS_ERR_PCAP, STR_2202 ) +STRTBL( IDS_ERR_NONET, STR_2202 ) STRTBL( IDS_ERR_PCAP_NO, STR_2203 ) STRTBL( IDS_ERR_PCAP_DEV, STR_2204 ) STRTBL( IDS_ERR_NOLIB, STR_2205 ) diff --git a/src/ui/ui_resource.h b/src/ui/ui_resource.h index f82d051..fd113f1 100644 --- a/src/ui/ui_resource.h +++ b/src/ui/ui_resource.h @@ -12,7 +12,7 @@ * those are not used by the platform code. This is easier to * maintain. * - * Version: @(#)ui_resource.h 1.0.18 2018/10/18 + * Version: @(#)ui_resource.h 1.0.19 2018/11/12 * * Author: Fred N. van Kempen, * @@ -262,7 +262,7 @@ /* System errors (2200.) */ #define IDS_ERR_ACCEL 2200 /* "Unable to load Accelerators" */ #define IDS_ERR_INPUT 2201 /* "Unable to register Raw Input" */ -#define IDS_ERR_PCAP 2202 /* "PCap failed to set up.." */ +#define IDS_ERR_NONET 2202 /* "%s failed to set up.." */ #define IDS_ERR_PCAP_NO 2203 /* "No PCap devices found" */ #define IDS_ERR_PCAP_DEV 2204 /* "Invalid PCap device" */ #define IDS_ERR_NOLIB 2205 /* "Unable to initialize %s.." */