Added network configuration dialogue.

This commit is contained in:
SarahW 2017-07-31 21:45:08 +01:00
commit 961490cca9
10 changed files with 263 additions and 7 deletions

View file

@ -21,7 +21,7 @@ OBJ = 386.o 386_dynarec.o 386_dynarec_ops.o 808x.o acer386sx.o ali1429.o amstrad
vid_svga_render.o vid_tandy.o vid_tandysl.o vid_tgui9440.o vid_tkd8001_ramdac.o vid_tvga.o vid_unk_ramdac.o \
vid_vga.o vid_voodoo.o vid_wy700.o video.o wd76c10.o win.o win-config.o win-config_sel.o win-d3d.o win-d3d-fs.o win-ddraw.o \
win-ddraw-fs.o win-deviceconfig.o win-hdconf.o win-joystick.o win-joystickconfig.o win-keyboard.o win-midi.o win-mouse.o \
win-status.o win-video.o x86seg.o x87.o xtide.o pc.res
win-networkconfig.o win-status.o win-video.o x86seg.o x87.o xtide.o pc.res
DBOBJ = cdrom_image.o dbopl.o nukedopl.o vid_cga_comp.o
SIDOBJ = convolve.o convolve-sse.o envelope.o extfilt.o filter.o pot.o sid.o voice.o wave6581__ST.o wave6581_P_T.o wave6581_PS_.o wave6581_PST.o wave8580__ST.o wave8580_P_T.o wave8580_PS_.o wave8580_PST.o wave.o
NETOBJ = ne2000.o nethandler.o

View file

@ -576,5 +576,6 @@ void resetpchard();
void speedchanged();
void saveconfig(char *fn);
void saveconfig_global_only();
#define UNUSED(x) (void)x

View file

@ -1407,11 +1407,11 @@ void *ne2000_init()
//0 pcap
//1 slirp
//
net_is_slirp = config_get_int(CFG_MACHINE, NULL, "net_type", 1);
pclog("ne2000 pcap device %s\n",config_get_string(CFG_MACHINE, NULL,"pcap_device","nothing"));
net_is_slirp = (config_get_int(CFG_GLOBAL, NULL, "net_type", NET_SLIRP) == NET_SLIRP) ? 1 : 0;
pclog("ne2000 pcap device %s\n",config_get_string(CFG_GLOBAL, NULL,"pcap_device","nothing"));
//Check that we have a string setup, otherwise turn pcap off
if (!strcmp("nothing",config_get_string(CFG_MACHINE, NULL,"pcap_device","nothing")))
if (!strcmp("nothing",config_get_string(CFG_GLOBAL, NULL,"pcap_device","nothing")))
net_is_pcap = 0;
else if (net_is_slirp == 0)
net_is_pcap = 1;
@ -1494,9 +1494,9 @@ void *ne2000_init()
{
pclog("ne2000 Pcap version [%s]\n",_pcap_lib_version());
if ((net_pcap=_pcap_open_live(config_get_string(CFG_MACHINE, NULL,"pcap_device","nothing"),1518,1,15,errbuf))==0)
if ((net_pcap=_pcap_open_live(config_get_string(CFG_GLOBAL, NULL,"pcap_device","nothing"),1518,1,15,errbuf))==0)
{
pclog("ne2000 pcap_open_live error on %s!\n",config_get_string(CFG_MACHINE, NULL,"pcap_device","whatever the ethernet is"));
pclog("ne2000 pcap_open_live error on %s!\n",config_get_string(CFG_GLOBAL, NULL,"pcap_device","whatever the ethernet is"));
net_is_pcap=0; return(ne2000); //YUCK!!!
}
}

View file

@ -18,3 +18,9 @@ void initpcap();
void closepcap();
void vlan_reset();
enum
{
NET_SLIRP = 0,
NET_PCAP = 1
};

View file

@ -920,3 +920,12 @@ void saveconfig(char *fn)
config_save(CFG_GLOBAL, global_config_file);
}
void saveconfig_global_only()
{
char global_config_file[512];
append_filename(global_config_file, pcem_path, "pcem.cfg", 511);
config_save(CFG_GLOBAL, global_config_file);
}

View file

@ -367,6 +367,23 @@ BEGIN
DEFPUSHBUTTON "New...", IDC_NEW, 200-54,40, 50, 14, WS_TABSTOP
DEFPUSHBUTTON "Configuration...", IDC_CONFIG, 200-54,58, 50, 14, WS_TABSTOP
DEFPUSHBUTTON "HDD...", IDC_HDCONF, 200-54,76, 50, 14, WS_TABSTOP
#ifdef USE_NETWORKING
DEFPUSHBUTTON "Network...",IDC_NETWORK, 200-54,104,50, 14, WS_TABSTOP
#endif
LISTBOX IDC_LIST, 4, 4,140,142, WS_TABSTOP|WS_VSCROLL
END
NetworkConfDlg DIALOGEX 0, 0, 400, 80
STYLE DS_SETFONT | DS_MODALFRAME | DS_FIXEDSYS | WS_POPUP | WS_CAPTION | WS_SYSMENU
CAPTION "Configure Network"
FONT 8, "MS Sans Serif"
BEGIN
DEFPUSHBUTTON "OK",IDOK,64,56,50,14, WS_TABSTOP
PUSHBUTTON "Cancel",IDCANCEL,128,56,50,14, WS_TABSTOP
COMBOBOX IDC_COMBONETTYPE,62,16,157,120,CBS_DROPDOWN | WS_VSCROLL | WS_TABSTOP
COMBOBOX IDC_COMBONETDEVICE,62,36,327,120,CBS_DROPDOWN | WS_VSCROLL | WS_TABSTOP
LTEXT "Type :",IDC_STATIC,15,16,40,10
LTEXT "Device :",IDC_STATIC,15,36,34,10
END

View file

@ -142,3 +142,7 @@
#define IDC_LIST 1201
#define IDC_CONFIG 1202
#define IDC_HDCONF 1203
#define IDC_NETWORK 1204
#define IDC_COMBONETTYPE 1200
#define IDC_COMBONETDEVICE 1201

View file

@ -168,6 +168,11 @@ static BOOL CALLBACK config_selection_dlgproc(HWND hdlg, UINT message, WPARAM wP
return TRUE;
}
#ifdef USE_NETWORKING
case IDC_NETWORK:
networkconfig_open(hdlg);
return TRUE;
#endif
}
break;
}

213
src/win-networkconfig.c Normal file
View file

@ -0,0 +1,213 @@
#define BITMAP WINDOWS_BITMAP
#include <windows.h>
#include <windowsx.h>
#undef BITMAP
#include <commctrl.h>
#include <pcap.h>
#include "ibm.h"
#include "config.h"
#include "nethandler.h"
#include "resources.h"
#include "win.h"
static HINSTANCE net_hLib = 0;
static char *net_lib_name = "wpcap.dll";
static pcap_if_t *alldevs;
static char *dev_name[20];
int (*_pcap_findalldevs)(pcap_if_t **, char *);
void (*_pcap_freealldevs)(pcap_if_t *);
pcap_t *(*_pcap_open_live)(const char *, int, int, int, char *);
int (*_pcap_datalink)(pcap_t *);
void (*_pcap_close)(pcap_t *);
#define ETH_DEV_NAME_MAX 256 /* maximum device name size */
#define ETH_DEV_DESC_MAX 256 /* maximum device description size */
#define ETH_MAX_DEVICE 30 /* maximum ethernet devices */
#define ETH_PROMISC 1 /* promiscuous mode = true */
#define ETH_MAX_PACKET 1514 /* maximum ethernet packet size */
#define PCAP_READ_TIMEOUT -1
static int get_network_name(char *dev_name, char *regval)
{
if (dev_name[strlen( "\\Device\\NPF_" )] == '{')
{
char regkey[2048];
HKEY reghnd;
sprintf(regkey, "SYSTEM\\CurrentControlSet\\Control\\Network\\"
"{4D36E972-E325-11CE-BFC1-08002BE10318}\\%s\\Connection", dev_name+
strlen("\\Device\\NPF_"));
if (RegOpenKeyExA(HKEY_LOCAL_MACHINE, regkey, 0, KEY_QUERY_VALUE, &reghnd) == ERROR_SUCCESS)
{
DWORD reglen = 2048;
DWORD regtype;
if (RegQueryValueExA(reghnd, "Name", NULL, &regtype, (LPBYTE)regval, &reglen) == ERROR_SUCCESS)
{
RegCloseKey (reghnd);
if ((regtype != REG_SZ) || (reglen > 2048))
return -1;
/*Name now in regval*/
return 0;
}
RegCloseKey (reghnd);
}
}
return -1;
}
static BOOL CALLBACK networkconfig_dlgproc(HWND hdlg, UINT message, WPARAM wParam, LPARAM lParam)
{
HWND h;
pcap_if_t *dev;
char errbuf[PCAP_ERRBUF_SIZE];
int type;
switch (message)
{
case WM_INITDIALOG:
h = GetDlgItem(hdlg, IDC_COMBONETTYPE);
SendMessage(h, CB_ADDSTRING, 0, (LPARAM)(LPCSTR)"SLiRP");
SendMessage(h, CB_SETCURSEL, 0, 0);
h = GetDlgItem(hdlg, IDC_COMBONETDEVICE);
SendMessage(h, CB_SETCURSEL, 0, 0);
EnableWindow(h, FALSE);
net_hLib = LoadLibraryA(net_lib_name);
if (net_hLib)
{
int c = 0;
int match = 0;
_pcap_findalldevs = (void *)GetProcAddress(net_hLib, "pcap_findalldevs");
_pcap_freealldevs = (void *)GetProcAddress(net_hLib, "pcap_freealldevs");
_pcap_open_live = (void *)GetProcAddress(net_hLib, "pcap_open_live");
_pcap_datalink = (void *)GetProcAddress(net_hLib, "pcap_datalink");
_pcap_close = (void *)GetProcAddress(net_hLib, "pcap_close");
if (_pcap_findalldevs(&alldevs, errbuf) != -1)
{
char *pcap_device = config_get_string(CFG_GLOBAL, NULL, "pcap_device", "nothing");
h = GetDlgItem(hdlg, IDC_COMBONETDEVICE);
for (dev = alldevs; dev; dev = dev->next)
{
pcap_t *conn = _pcap_open_live(dev->name, ETH_MAX_PACKET, ETH_PROMISC, PCAP_READ_TIMEOUT, errbuf);
int datalink;
if (conn)
{
datalink = _pcap_datalink(conn);
_pcap_close(conn);
}
if (conn && datalink == DLT_EN10MB)
{
char desc[2048];
char s[2048];
if ((dev->flags & PCAP_IF_LOOPBACK) || (!strcmp("any", dev->name)))
continue;
if (pcap_device)
{
if (!strcmp(pcap_device, dev->name))
match = c;
}
dev_name[c++] = dev->name;
if (get_network_name(dev->name, desc))
SendMessage(h, CB_ADDSTRING, 0, (LPARAM)(LPCSTR)dev->name);
else
{
sprintf(s, "%s - %s", dev->name, desc);
SendMessage(h, CB_ADDSTRING, 0, (LPARAM)(LPCSTR)s);
}
}
}
}
if (c)
{
h = GetDlgItem(hdlg, IDC_COMBONETTYPE);
SendMessage(h, CB_ADDSTRING, 0, (LPARAM)(LPCSTR)"PCAP");
if (config_get_int(CFG_GLOBAL, NULL, "net_type", NET_SLIRP) == NET_PCAP)
{
SendMessage(h, CB_SETCURSEL, 1, 0);
h = GetDlgItem(hdlg, IDC_COMBONETDEVICE);
SendMessage(h, CB_SETCURSEL, match, 0);
EnableWindow(h, TRUE);
}
}
}
return TRUE;
case WM_COMMAND:
switch (LOWORD(wParam))
{
case IDOK:
h = GetDlgItem(hdlg, IDC_COMBONETTYPE);
type = SendMessage(h, CB_GETCURSEL, 0, 0);
if (type) /*PCAP*/
{
int dev;
h = GetDlgItem(hdlg, IDC_COMBONETDEVICE);
dev = SendMessage(h, CB_GETCURSEL, 0, 0);
config_set_int(CFG_GLOBAL, NULL, "net_type", NET_PCAP);
config_set_string(CFG_GLOBAL, NULL, "pcap_device", dev_name[dev]);
}
else /*SLiRP*/
{
config_set_int(CFG_GLOBAL, NULL, "net_type", NET_SLIRP);
config_set_string(CFG_GLOBAL, NULL, "pcap_device", "nothing");
}
saveconfig_global_only();
case IDCANCEL:
EndDialog(hdlg, 0);
if (net_hLib)
{
_pcap_freealldevs(alldevs);
_pcap_findalldevs = NULL;
_pcap_freealldevs = NULL;
_pcap_open_live = NULL;
_pcap_datalink = NULL;
_pcap_close = NULL;
FreeLibrary(net_hLib);
}
return TRUE;
case IDC_COMBONETTYPE:
if (HIWORD(wParam) == CBN_SELCHANGE)
{
int type;
h = GetDlgItem(hdlg, IDC_COMBONETTYPE);
type = SendMessage(h, CB_GETCURSEL, 0, 0);
h = GetDlgItem(hdlg, IDC_COMBONETDEVICE);
if (!type)
EnableWindow(h, FALSE);
else
EnableWindow(h, TRUE);
return TRUE;
}
}
break;
}
return FALSE;
}
void networkconfig_open(HWND hwnd)
{
DialogBox(hinstance, TEXT("NetworkConfDlg"), hwnd, (DLGPROC)networkconfig_dlgproc);
}

View file

@ -30,6 +30,7 @@ struct device_t;
void deviceconfig_open(HWND hwnd, struct device_t *device);
void joystickconfig_open(HWND hwnd, int joy_nr, int type);
void networkconfig_open(HWND hwnd);
extern char openfilestring[260];