Updates for dynamic loading of DLLs, some cleanups.
This commit is contained in:
BIN
src/86box.cfg
BIN
src/86box.cfg
Binary file not shown.
@@ -3,3 +3,5 @@
|
|||||||
*/
|
*/
|
||||||
#define emulator_version "1.20"
|
#define emulator_version "1.20"
|
||||||
#define emulator_version_w L"1.20"
|
#define emulator_version_w L"1.20"
|
||||||
|
|
||||||
|
#define CONFIG_FILE L"86box.cfg"
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
#
|
#
|
||||||
# Modified Makefile for Win32 MinGW 32-bit environment.
|
# Modified Makefile for Win32 MinGW 32-bit environment.
|
||||||
#
|
#
|
||||||
# Version: @(#)Makefile.mingw 1.0.13 2017/05/17
|
# Version: @(#)Makefile.mingw 1.0.14 2017/05/21
|
||||||
#
|
#
|
||||||
# Authors: Kotori, <oubattler@gmail.com>
|
# Authors: Kotori, <oubattler@gmail.com>
|
||||||
# Fred N. van Kempen, <decwiz@yahoo.com>
|
# Fred N. van Kempen, <decwiz@yahoo.com>
|
||||||
@@ -29,13 +29,10 @@ STUFF =
|
|||||||
EXTRAS =
|
EXTRAS =
|
||||||
|
|
||||||
# Do we want a debugging build?
|
# Do we want a debugging build?
|
||||||
DEBUG = y
|
DEBUG = n
|
||||||
OPTIM = n
|
OPTIM = y
|
||||||
X64 = n
|
X64 = n
|
||||||
|
|
||||||
# Where is the WinPcap DLL ?
|
|
||||||
PCAPDLL = C:\\Windows\\System32\\wpcap.dll
|
|
||||||
|
|
||||||
|
|
||||||
#########################################################################
|
#########################################################################
|
||||||
# Nothing should need changing from here on.. #
|
# Nothing should need changing from here on.. #
|
||||||
@@ -46,7 +43,7 @@ CPP = g++.exe
|
|||||||
CC = gcc.exe
|
CC = gcc.exe
|
||||||
WINDRES = windres.exe
|
WINDRES = windres.exe
|
||||||
|
|
||||||
OPTS = -DWIN32 -I$(PLAT) $(EXTRAS) $(STUFF)
|
OPTS = -DWIN32 -I$(PLAT) -I$(X64INC) $(EXTRAS) $(STUFF)
|
||||||
ifeq ($(DEBUG), y)
|
ifeq ($(DEBUG), y)
|
||||||
ifeq ($(VRAMDUMP), y)
|
ifeq ($(VRAMDUMP), y)
|
||||||
DFLAGS = -march=i686 -ggdb -DDEBUG -DENABLE_VRAM_DUMP
|
DFLAGS = -march=i686 -ggdb -DDEBUG -DENABLE_VRAM_DUMP
|
||||||
@@ -179,7 +176,7 @@ VIDOBJ = video.o \
|
|||||||
WINOBJ = win.o \
|
WINOBJ = win.o \
|
||||||
win_d3d.o win_d3d-fs.o \
|
win_d3d.o win_d3d-fs.o \
|
||||||
win_ddraw.o win_ddraw-fs.o win_ddraw-screenshot.o \
|
win_ddraw.o win_ddraw-fs.o win_ddraw-screenshot.o \
|
||||||
win_language.o win_status.o win_opendir.o \
|
win_language.o win_status.o win_opendir.o win_dynld.o \
|
||||||
win_video.o win_serial.o win_mouse.o \
|
win_video.o win_serial.o win_mouse.o \
|
||||||
win_joystick.o win_midi.o \
|
win_joystick.o win_midi.o \
|
||||||
win_settings.o win_deviceconfig.o win_joystickconfig.o \
|
win_settings.o win_deviceconfig.o win_joystickconfig.o \
|
||||||
@@ -200,7 +197,7 @@ LIBS = -mwindows -lcomctl32 -lwinmm -lopenal.dll -lopenal -lddraw \
|
|||||||
# Build rules.
|
# Build rules.
|
||||||
%.o: %.c
|
%.o: %.c
|
||||||
@echo $<
|
@echo $<
|
||||||
$(CC) $(CFLAGS) -c $<
|
@$(CC) $(CFLAGS) -c $<
|
||||||
|
|
||||||
%.o: %.cc
|
%.o: %.cc
|
||||||
@echo $<
|
@echo $<
|
||||||
@@ -217,7 +214,7 @@ $(PROG).exe: $(OBJ) $(LZFOBJ) $(SLIRPOBJ)
|
|||||||
@echo Linking $(PROG).exe ..
|
@echo Linking $(PROG).exe ..
|
||||||
@$(CC) -o $(PROG).exe \
|
@$(CC) -o $(PROG).exe \
|
||||||
$(OBJ) $(LZFOBJ) $(SLIRPOBJ) \
|
$(OBJ) $(LZFOBJ) $(SLIRPOBJ) \
|
||||||
$(LIBS) -static -Lpcap -lwpcapdelay
|
$(LIBS) #-static -Lpcap -lwpcapdelay
|
||||||
ifneq ($(DEBUG), y)
|
ifneq ($(DEBUG), y)
|
||||||
@strip $(PROG).exe
|
@strip $(PROG).exe
|
||||||
endif
|
endif
|
||||||
@@ -241,10 +238,6 @@ clean:
|
|||||||
@echo Processing $<
|
@echo Processing $<
|
||||||
@$(WINDRES) $(RFLAGS) -i win/86Box.rc -o 86Box.res
|
@$(WINDRES) $(RFLAGS) -i win/86Box.rc -o 86Box.res
|
||||||
|
|
||||||
libwpcapdelay.a: $(PCAPDLL)
|
|
||||||
@dlltool --export-all-symbols --output-def wpcap.def $(PCAPDLL)
|
|
||||||
@dlltool --def wpcap.def --output-delaylib libwpcapdelay.a
|
|
||||||
|
|
||||||
pcap_if.res: pcap_if.rc
|
pcap_if.res: pcap_if.rc
|
||||||
@echo Processing $<
|
@echo Processing $<
|
||||||
@$(WINDRES) $(RFLAGS) -i win/pcap_if.rc -o pcap_if.res
|
@$(WINDRES) $(RFLAGS) -i win/pcap_if.rc -o pcap_if.res
|
||||||
|
|||||||
@@ -1004,6 +1004,7 @@ BEGIN
|
|||||||
2199 "USB is not yet supported"
|
2199 "USB is not yet supported"
|
||||||
2200 "Invalid PCap device"
|
2200 "Invalid PCap device"
|
||||||
2201 "English (United States)"
|
2201 "English (United States)"
|
||||||
|
2202 "Pcap Library Not Available"
|
||||||
END
|
END
|
||||||
|
|
||||||
|
|
||||||
|
|||||||
30
src/WIN/plat_dynld.h
Normal file
30
src/WIN/plat_dynld.h
Normal file
@@ -0,0 +1,30 @@
|
|||||||
|
/*
|
||||||
|
* 86Box A hypervisor and IBM PC system emulator that specializes in
|
||||||
|
* running old operating systems and software designed for IBM
|
||||||
|
* PC systems and compatibles from 1981 through fairly recent
|
||||||
|
* system designs based on the PCI bus.
|
||||||
|
*
|
||||||
|
* This file is part of the 86Box distribution.
|
||||||
|
*
|
||||||
|
* Define the Dynamic Module Loader interface.
|
||||||
|
*
|
||||||
|
* Version: @(#)plat_dynld.h 1.0.1 2017/05/21
|
||||||
|
*
|
||||||
|
* Author: Fred N. van Kempen, <decwiz@yahoo.com>
|
||||||
|
* Copyright 2017 Fred N. van Kempen
|
||||||
|
*/
|
||||||
|
#ifndef PLAT_DYNLD_H
|
||||||
|
# define PLAT_DYNLD_H
|
||||||
|
|
||||||
|
|
||||||
|
typedef struct {
|
||||||
|
const char *name;
|
||||||
|
void *func;
|
||||||
|
} dllimp_t;
|
||||||
|
|
||||||
|
|
||||||
|
extern void *dynld_module(const char *, dllimp_t *);
|
||||||
|
extern void dynld_close(void *);
|
||||||
|
|
||||||
|
|
||||||
|
#endif /*PLAT_DYNLD_H*/
|
||||||
@@ -1,53 +1,72 @@
|
|||||||
|
/*
|
||||||
|
* This should be named 'plat.h' and then include any
|
||||||
|
* Windows-specific header files needed, to keep them
|
||||||
|
* out of the main code.
|
||||||
|
*/
|
||||||
/* Copyright holders: Sarah Walker
|
/* Copyright holders: Sarah Walker
|
||||||
see COPYING for more details
|
see COPYING for more details
|
||||||
*/
|
*/
|
||||||
extern HINSTANCE hinstance;
|
#ifndef BOX_WIN_H
|
||||||
extern HWND ghwnd;
|
# define BOX_WIN_H
|
||||||
extern int mousecapture;
|
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#if 0
|
||||||
extern "C" {
|
# define UNICODE
|
||||||
|
# define BITMAP WINDOWS_BITMAP
|
||||||
|
# include <windows.h>
|
||||||
|
# undef BITMAP
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
#define szClassName L"86BoxMainWnd"
|
#define szClassName L"86BoxMainWnd"
|
||||||
#define szSubClassName L"86BoxSubWnd"
|
#define szSubClassName L"86BoxSubWnd"
|
||||||
#define szStatusBarClassName L"86BoxStatusBar"
|
#define szStatusBarClassName L"86BoxStatusBar"
|
||||||
|
|
||||||
void leave_fullscreen();
|
|
||||||
|
extern HINSTANCE hinstance;
|
||||||
|
extern HWND ghwnd;
|
||||||
|
extern HWND status_hwnd;
|
||||||
|
extern HWND hwndStatus;
|
||||||
|
extern int status_is_open;
|
||||||
|
extern int mousecapture;
|
||||||
|
|
||||||
|
extern char openfilestring[260];
|
||||||
|
extern WCHAR wopenfilestring[260];
|
||||||
|
|
||||||
|
extern int pause;
|
||||||
|
|
||||||
|
|
||||||
|
#ifdef __cplusplus
|
||||||
|
extern "C" {
|
||||||
|
#endif
|
||||||
|
|
||||||
|
extern void leave_fullscreen(void);
|
||||||
|
|
||||||
|
extern void status_open(HWND hwnd);
|
||||||
|
|
||||||
|
extern void deviceconfig_open(HWND hwnd, struct device_t *device);
|
||||||
|
extern void joystickconfig_open(HWND hwnd, int joy_nr, int type);
|
||||||
|
|
||||||
|
extern int getfile(HWND hwnd, char *f, char *fn);
|
||||||
|
extern int getsfile(HWND hwnd, char *f, char *fn);
|
||||||
|
|
||||||
|
extern void get_executable_name(WCHAR *s, int size);
|
||||||
|
extern void set_window_title(WCHAR *s);
|
||||||
|
|
||||||
|
extern void startblit(void);
|
||||||
|
extern void endblit(void);
|
||||||
|
|
||||||
|
extern void win_settings_open(HWND hwnd);
|
||||||
|
extern void win_menu_update();
|
||||||
|
|
||||||
|
extern void update_status_bar_panes(HWND hwnds);
|
||||||
|
|
||||||
|
extern int fdd_type_to_icon(int type);
|
||||||
|
|
||||||
|
extern void hard_disk_add_open(HWND hwnd, int is_existing);
|
||||||
|
|
||||||
#ifdef __cplusplus
|
#ifdef __cplusplus
|
||||||
}
|
}
|
||||||
#endif
|
#endif
|
||||||
|
|
||||||
|
|
||||||
void status_open(HWND hwnd);
|
#endif /*BOX_WIN_H*/
|
||||||
extern HWND status_hwnd;
|
|
||||||
extern int status_is_open;
|
|
||||||
|
|
||||||
void deviceconfig_open(HWND hwnd, struct device_t *device);
|
|
||||||
void joystickconfig_open(HWND hwnd, int joy_nr, int type);
|
|
||||||
|
|
||||||
extern char openfilestring[260];
|
|
||||||
extern WCHAR wopenfilestring[260];
|
|
||||||
|
|
||||||
int getfile(HWND hwnd, char *f, char *fn);
|
|
||||||
int getsfile(HWND hwnd, char *f, char *fn);
|
|
||||||
|
|
||||||
void get_executable_name(WCHAR *s, int size);
|
|
||||||
void set_window_title(WCHAR *s);
|
|
||||||
|
|
||||||
void startblit();
|
|
||||||
void endblit();
|
|
||||||
|
|
||||||
extern int pause;
|
|
||||||
|
|
||||||
void win_settings_open(HWND hwnd);
|
|
||||||
void win_menu_update();
|
|
||||||
|
|
||||||
void update_status_bar_panes(HWND hwnds);
|
|
||||||
|
|
||||||
int fdd_type_to_icon(int type);
|
|
||||||
|
|
||||||
extern HWND hwndStatus;
|
|
||||||
|
|
||||||
void hard_disk_add_open(HWND hwnd, int is_existing);
|
|
||||||
|
|||||||
64
src/WIN/win_dynld.c
Normal file
64
src/WIN/win_dynld.c
Normal file
@@ -0,0 +1,64 @@
|
|||||||
|
/*
|
||||||
|
* 86Box A hypervisor and IBM PC system emulator that specializes in
|
||||||
|
* running old operating systems and software designed for IBM
|
||||||
|
* PC systems and compatibles from 1981 through fairly recent
|
||||||
|
* system designs based on the PCI bus.
|
||||||
|
*
|
||||||
|
* This file is part of the 86Box distribution.
|
||||||
|
*
|
||||||
|
* Try to load a support DLL.
|
||||||
|
*
|
||||||
|
* Version: @(#)win_dynld.c 1.0.1 2017/05/21
|
||||||
|
*
|
||||||
|
* Author: Fred N. van Kempen, <decwiz@yahoo.com>
|
||||||
|
* Copyright 2017 Fred N. van Kempen
|
||||||
|
*/
|
||||||
|
#include <windows.h>
|
||||||
|
#include <stdint.h>
|
||||||
|
#include <stdio.h>
|
||||||
|
#include <stdlib.h>
|
||||||
|
#include <string.h>
|
||||||
|
#include <pcap.h>
|
||||||
|
#include "plat_dynld.h"
|
||||||
|
#include "../ibm.h"
|
||||||
|
|
||||||
|
|
||||||
|
void *
|
||||||
|
dynld_module(const char *name, dllimp_t *table)
|
||||||
|
{
|
||||||
|
HANDLE h;
|
||||||
|
dllimp_t *imp;
|
||||||
|
void *func;
|
||||||
|
char **foo;
|
||||||
|
|
||||||
|
/* See if we can load the desired module. */
|
||||||
|
if ((h = LoadLibrary(name)) == NULL) {
|
||||||
|
pclog("DynLd(\"%s\"): library not found!\n", name);
|
||||||
|
return(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Now load the desired function pointers. */
|
||||||
|
for (imp=table; imp->name!=NULL; imp++) {
|
||||||
|
func = GetProcAddress(h, imp->name);
|
||||||
|
if (func == NULL) {
|
||||||
|
pclog("DynLd(\"%s\"): function '%s' not found!\n",
|
||||||
|
name, imp->name);
|
||||||
|
CloseHandle(h);
|
||||||
|
return(NULL);
|
||||||
|
}
|
||||||
|
|
||||||
|
/* To overcome typing issues.. */
|
||||||
|
*(char **)imp->func = (char *)func;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* All good. */
|
||||||
|
return((void *)h);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
|
void
|
||||||
|
dynld_close(void *handle)
|
||||||
|
{
|
||||||
|
if (handle != NULL)
|
||||||
|
CloseHandle((HANDLE *)handle);
|
||||||
|
}
|
||||||
@@ -21,7 +21,7 @@ LCID dwLanguage;
|
|||||||
|
|
||||||
uint32_t dwLangID, dwSubLangID;
|
uint32_t dwLangID, dwSubLangID;
|
||||||
|
|
||||||
#define STRINGS_NUM 154
|
#define STRINGS_NUM 155 /* FIXME: should be in resource.h !! --FvK */
|
||||||
|
|
||||||
WCHAR lpResourceString[STRINGS_NUM][512];
|
WCHAR lpResourceString[STRINGS_NUM][512];
|
||||||
|
|
||||||
|
|||||||
@@ -11,7 +11,7 @@
|
|||||||
* NOTE: Its still a mess, but we're getting there. The file will
|
* NOTE: Its still a mess, but we're getting there. The file will
|
||||||
* also implement an NE1000 for 8-bit ISA systems.
|
* also implement an NE1000 for 8-bit ISA systems.
|
||||||
*
|
*
|
||||||
* Version: @(#)net_ne2000.c 1.0.4 2017/05/17
|
* Version: @(#)net_ne2000.c 1.0.5 2017/05/21
|
||||||
*
|
*
|
||||||
* Authors: Fred N. van Kempen, <decwiz@yahoo.com>
|
* Authors: Fred N. van Kempen, <decwiz@yahoo.com>
|
||||||
* Peter Grehan, grehan@iprg.nokia.com>
|
* Peter Grehan, grehan@iprg.nokia.com>
|
||||||
@@ -1842,10 +1842,21 @@ nic_init(int board)
|
|||||||
!dev->disable_netbios);
|
!dev->disable_netbios);
|
||||||
|
|
||||||
if (network_attach(dev, dev->physaddr, nic_rx) < 0) {
|
if (network_attach(dev, dev->physaddr, nic_rx) < 0) {
|
||||||
|
#if 0
|
||||||
|
msgbox_error_wstr(ghwnd, L"Unable to init platform network");
|
||||||
|
#endif
|
||||||
pclog(1, "%s: unable to init platform network type %d\n",
|
pclog(1, "%s: unable to init platform network type %d\n",
|
||||||
dev->name, network_type);
|
dev->name, network_type);
|
||||||
|
#if 0
|
||||||
|
/*
|
||||||
|
* To avoid crashes, we ignore the fact that even though
|
||||||
|
* there is no active platform support, we just continue
|
||||||
|
* initializing. If we return an error here, the device
|
||||||
|
* handling code will throw a fatal error... --FvK
|
||||||
|
*/
|
||||||
free(dev);
|
free(dev);
|
||||||
return(NULL);
|
return(NULL);
|
||||||
|
#endif
|
||||||
}
|
}
|
||||||
|
|
||||||
if (dev->is_rtl8029as)
|
if (dev->is_rtl8029as)
|
||||||
@@ -1987,20 +1998,6 @@ static device_config_t ne1000_config[] =
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"net_type", "Network type", CONFIG_SELECTION, "", 0,
|
|
||||||
{
|
|
||||||
{
|
|
||||||
"PCap", 0
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"SLiRP", 1
|
|
||||||
},
|
|
||||||
{
|
|
||||||
""
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"mac", "MAC Address", CONFIG_MAC, "", -1
|
"mac", "MAC Address", CONFIG_MAC, "", -1
|
||||||
},
|
},
|
||||||
@@ -2063,20 +2060,6 @@ static device_config_t ne2000_config[] =
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"net_type", "Network type", CONFIG_SELECTION, "", 0,
|
|
||||||
{
|
|
||||||
{
|
|
||||||
"PCap", 0
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"SLiRP", 1
|
|
||||||
},
|
|
||||||
{
|
|
||||||
""
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"mac", "MAC Address", CONFIG_MAC, "", -1
|
"mac", "MAC Address", CONFIG_MAC, "", -1
|
||||||
},
|
},
|
||||||
@@ -2113,20 +2096,6 @@ static device_config_t rtl8029as_config[] =
|
|||||||
}
|
}
|
||||||
},
|
},
|
||||||
},
|
},
|
||||||
{
|
|
||||||
"net_type", "Network type", CONFIG_SELECTION, "", 0,
|
|
||||||
{
|
|
||||||
{
|
|
||||||
"PCap", 0
|
|
||||||
},
|
|
||||||
{
|
|
||||||
"SLiRP", 1
|
|
||||||
},
|
|
||||||
{
|
|
||||||
""
|
|
||||||
}
|
|
||||||
},
|
|
||||||
},
|
|
||||||
{
|
{
|
||||||
"mac", "MAC Address", CONFIG_MAC, "", -1
|
"mac", "MAC Address", CONFIG_MAC, "", -1
|
||||||
},
|
},
|
||||||
|
|||||||
187
src/net_pcap.c
187
src/net_pcap.c
@@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
* Handle WinPcap library processing.
|
* Handle WinPcap library processing.
|
||||||
*
|
*
|
||||||
* Version: @(#)net_pcap.c 1.0.2 2017/05/17
|
* Version: @(#)net_pcap.c 1.0.3 2017/05/21
|
||||||
*
|
*
|
||||||
* Author: Fred N. van Kempen, <decwiz@yahoo.com>
|
* Author: Fred N. van Kempen, <decwiz@yahoo.com>
|
||||||
*/
|
*/
|
||||||
@@ -22,59 +22,61 @@
|
|||||||
#include "thread.h"
|
#include "thread.h"
|
||||||
#include "device.h"
|
#include "device.h"
|
||||||
#include "network.h"
|
#include "network.h"
|
||||||
|
#include "plat_dynld.h"
|
||||||
|
|
||||||
|
|
||||||
|
static void *pcap_handle; /* handle to WinPcap DLL */
|
||||||
static pcap_t *pcap; /* handle to WinPcap library */
|
static pcap_t *pcap; /* handle to WinPcap library */
|
||||||
static thread_t *poll_tid;
|
static thread_t *poll_tid;
|
||||||
static NETRXCB poll_rx; /* network RX function to call */
|
static NETRXCB poll_rx; /* network RX function to call */
|
||||||
static void *poll_arg; /* network RX function arg */
|
static void *poll_arg; /* network RX function arg */
|
||||||
|
|
||||||
|
|
||||||
#ifdef WALTJE
|
/* Pointers to the real functions. */
|
||||||
int pcap_do_log = 1;
|
static const char *(*f_pcap_lib_version)(void);
|
||||||
# define ENABLE_PCAP_LOG
|
static int (*f_pcap_findalldevs)(pcap_if_t **,char *);
|
||||||
#else
|
static void (*f_pcap_freealldevs)(pcap_if_t *);
|
||||||
int pcap_do_log = 0;
|
static pcap_t *(*f_pcap_open_live)(const char *,int,int,int,char *);
|
||||||
#endif
|
static int (*f_pcap_compile)(pcap_t *,struct bpf_program *,
|
||||||
|
const char *,int,bpf_u_int32);
|
||||||
|
static int (*f_pcap_setfilter)(pcap_t *,struct bpf_program *);
|
||||||
|
static const u_char *(*f_pcap_next)(pcap_t *,struct pcap_pkthdr *);
|
||||||
|
static int (*f_pcap_sendpacket)(pcap_t *,const u_char *,int);
|
||||||
|
static void (*f_pcap_close)(pcap_t *);
|
||||||
|
static dllimp_t pcap_imports[] = {
|
||||||
|
{ "pcap_lib_version", &f_pcap_lib_version },
|
||||||
|
{ "pcap_findalldevs", &f_pcap_findalldevs },
|
||||||
|
{ "pcap_freealldevs", &f_pcap_freealldevs },
|
||||||
|
{ "pcap_open_live", &f_pcap_open_live },
|
||||||
|
{ "pcap_compile", &f_pcap_compile },
|
||||||
|
{ "pcap_setfilter", &f_pcap_setfilter },
|
||||||
|
{ "pcap_next", &f_pcap_next },
|
||||||
|
{ "pcap_sendpacket", &f_pcap_sendpacket },
|
||||||
|
{ "pcap_close", &f_pcap_close },
|
||||||
|
{ NULL, NULL },
|
||||||
|
};
|
||||||
|
|
||||||
|
|
||||||
static void
|
/* Handle the receiving of frames from the channel. */
|
||||||
pcap_log(const char *format, ...)
|
|
||||||
{
|
|
||||||
#ifdef ENABLE_PCAP_LOG
|
|
||||||
va_list ap;
|
|
||||||
|
|
||||||
if (pcap_do_log) {
|
|
||||||
va_start(ap, format);
|
|
||||||
vprintf(format, ap);
|
|
||||||
va_end(ap);
|
|
||||||
fflush(stdout);
|
|
||||||
}
|
|
||||||
#endif
|
|
||||||
}
|
|
||||||
#define pclog pcap_log
|
|
||||||
|
|
||||||
|
|
||||||
/* Check if the interface has a packet for us. */
|
|
||||||
static void
|
static void
|
||||||
poll_thread(void *arg)
|
poll_thread(void *arg)
|
||||||
{
|
{
|
||||||
const unsigned char *data;
|
|
||||||
uint8_t *mac = (uint8_t *)arg;
|
uint8_t *mac = (uint8_t *)arg;
|
||||||
|
const uint8_t *data = NULL;
|
||||||
struct pcap_pkthdr h;
|
struct pcap_pkthdr h;
|
||||||
event_t *evt;
|
|
||||||
uint32_t mac_cmp32[2];
|
uint32_t mac_cmp32[2];
|
||||||
uint16_t mac_cmp16[2];
|
uint16_t mac_cmp16[2];
|
||||||
|
event_t *evt;
|
||||||
|
|
||||||
pclog("PCAP: polling thread started, arg %08lx\n", arg);
|
pclog("PCAP: polling thread started, arg %08lx\n", arg);
|
||||||
|
|
||||||
/* Create a waitable event. */
|
/* Create a waitable event. */
|
||||||
evt = thread_create_event();
|
evt = thread_create_event();
|
||||||
pclog("PCAP: poll event is %08lx\n", evt);
|
|
||||||
|
|
||||||
|
/* As long as the channel is open.. */
|
||||||
while (pcap != NULL) {
|
while (pcap != NULL) {
|
||||||
/* Wait for the next packet to arrive. */
|
/* Wait for the next packet to arrive. */
|
||||||
data = pcap_next(pcap, &h);
|
data = f_pcap_next(pcap, &h);
|
||||||
if (data != NULL) {
|
if (data != NULL) {
|
||||||
/* Received MAC. */
|
/* Received MAC. */
|
||||||
mac_cmp32[0] = *(uint32_t *)(data+6);
|
mac_cmp32[0] = *(uint32_t *)(data+6);
|
||||||
@@ -105,6 +107,43 @@ poll_thread(void *arg)
|
|||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
|
/* Initialize the (Win)Pcap module for use. */
|
||||||
|
int
|
||||||
|
network_pcap_init(netdev_t *list)
|
||||||
|
{
|
||||||
|
char errbuf[PCAP_ERRBUF_SIZE];
|
||||||
|
pcap_if_t *devlist, *dev;
|
||||||
|
int i = 0;
|
||||||
|
|
||||||
|
/* Local variables. */
|
||||||
|
pcap = NULL;
|
||||||
|
|
||||||
|
/* Try loading the DLL. */
|
||||||
|
pcap_handle = dynld_module("wpcap.dll", pcap_imports);
|
||||||
|
if (pcap_handle == NULL) return(-1);
|
||||||
|
|
||||||
|
/* Retrieve the device list from the local machine */
|
||||||
|
if (f_pcap_findalldevs(&devlist, errbuf) == -1) {
|
||||||
|
pclog("PCAP: error in pcap_findalldevs: %s\n", errbuf);
|
||||||
|
return(-1);
|
||||||
|
}
|
||||||
|
|
||||||
|
for (dev=devlist; dev!=NULL; dev=dev->next) {
|
||||||
|
strcpy(list->device, dev->name);
|
||||||
|
if (dev->description)
|
||||||
|
strcpy(list->description, dev->description);
|
||||||
|
else
|
||||||
|
memset(list->description, '\0', sizeof(list->description));
|
||||||
|
list++; i++;
|
||||||
|
}
|
||||||
|
|
||||||
|
/* Release the memory. */
|
||||||
|
f_pcap_freealldevs(devlist);
|
||||||
|
|
||||||
|
return(i);
|
||||||
|
}
|
||||||
|
|
||||||
|
|
||||||
/* Initialize WinPcap for us. */
|
/* Initialize WinPcap for us. */
|
||||||
int
|
int
|
||||||
network_pcap_setup(uint8_t *mac, NETRXCB func, void *arg)
|
network_pcap_setup(uint8_t *mac, NETRXCB func, void *arg)
|
||||||
@@ -114,20 +153,13 @@ network_pcap_setup(uint8_t *mac, NETRXCB func, void *arg)
|
|||||||
struct bpf_program fp;
|
struct bpf_program fp;
|
||||||
char *dev;
|
char *dev;
|
||||||
|
|
||||||
/* Messy, but gets rid of a lot of useless info. */
|
/* Did we already load the DLL? */
|
||||||
dev = (char *)pcap_lib_version();
|
if (pcap_handle == NULL) return(-1);
|
||||||
if (dev == NULL) {
|
|
||||||
/* Hmm, WinPcap doesn't seem to be alive.. */
|
|
||||||
pclog("PCAP: WinPcap library not found, disabling network!\n");
|
|
||||||
network_type = -1;
|
|
||||||
return(-1);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* OK, good for now.. */
|
strcpy(temp, f_pcap_lib_version());
|
||||||
strcpy(temp, dev);
|
|
||||||
dev = strchr(temp, '(');
|
dev = strchr(temp, '(');
|
||||||
if (dev != NULL) *(dev-1) = '\0';
|
if (dev != NULL) *(dev-1) = '\0';
|
||||||
pclog("Initializing WinPcap, version %s\n", temp);
|
pclog("PCAP: initializing, %s\n", temp);
|
||||||
|
|
||||||
/* Get the value of our capture interface. */
|
/* Get the value of our capture interface. */
|
||||||
dev = network_pcap;
|
dev = network_pcap;
|
||||||
@@ -137,38 +169,35 @@ network_pcap_setup(uint8_t *mac, NETRXCB func, void *arg)
|
|||||||
}
|
}
|
||||||
pclog(" Network interface: '%s'\n", dev);
|
pclog(" Network interface: '%s'\n", dev);
|
||||||
|
|
||||||
pcap = pcap_open_live(dev, /* interface name */
|
pcap = f_pcap_open_live(dev, /* interface name */
|
||||||
1518, /* maximum packet size */
|
1518, /* maximum packet size */
|
||||||
1, /* promiscuous mode? */
|
1, /* promiscuous mode? */
|
||||||
10, /* timeout in msec */
|
10, /* timeout in msec */
|
||||||
temp); /* error buffer */
|
temp); /* error buffer */
|
||||||
if (pcap == NULL) {
|
if (pcap == NULL) {
|
||||||
pclog("Unable to open WinPcap: %s!\n", temp);
|
pclog(" Unable to open device: %s!\n", temp);
|
||||||
return(-1);
|
return(-1);
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Create a MAC address based packet filter. */
|
/* Create a MAC address based packet filter. */
|
||||||
pclog("Building packet filter ...");
|
pclog(" Installing packet filter for MAC=%02x:%02x:%02x:%02x:%02x\n",
|
||||||
|
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||||
sprintf(filter_exp,
|
sprintf(filter_exp,
|
||||||
"( ((ether dst ff:ff:ff:ff:ff:ff) or (ether dst %02x:%02x:%02x:%02x:%02x:%02x)) and not (ether src %02x:%02x:%02x:%02x:%02x:%02x) )",
|
"( ((ether dst ff:ff:ff:ff:ff:ff) or (ether dst %02x:%02x:%02x:%02x:%02x:%02x)) and not (ether src %02x:%02x:%02x:%02x:%02x:%02x) )",
|
||||||
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5],
|
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5],
|
||||||
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
mac[0], mac[1], mac[2], mac[3], mac[4], mac[5]);
|
||||||
if (pcap_compile(pcap, &fp, filter_exp, 0, 0xffffffff) != -1) {
|
if (f_pcap_compile(pcap, &fp, filter_exp, 0, 0xffffffff) != -1) {
|
||||||
pclog("...");
|
if (f_pcap_setfilter(pcap, &fp) == -1)
|
||||||
if (pcap_setfilter(pcap, &fp) == -1) {
|
pclog(" Error installing filter (%s) !\n", filter_exp);
|
||||||
pclog(" error installing filter!\n");
|
|
||||||
} else {
|
} else {
|
||||||
pclog("!\nUsing filter\t[%s]\n", filter_exp);
|
pclog(" Could not compile filter (%s) !\n", filter_exp);
|
||||||
}
|
|
||||||
} else {
|
|
||||||
pclog(" could not compile filter!\n");
|
|
||||||
}
|
}
|
||||||
|
|
||||||
/* Save the callback info. */
|
/* Save the callback info. */
|
||||||
poll_rx = func;
|
poll_rx = func;
|
||||||
poll_arg = arg;
|
poll_arg = arg;
|
||||||
|
|
||||||
pclog("PCAP: creating thread..\n");
|
pclog(" Starting thread..\n");
|
||||||
poll_tid = thread_create(poll_thread, mac);
|
poll_tid = thread_create(poll_thread, mac);
|
||||||
|
|
||||||
return(0);
|
return(0);
|
||||||
@@ -199,7 +228,13 @@ network_pcap_close(void)
|
|||||||
#endif
|
#endif
|
||||||
|
|
||||||
/* OK, now shut down WinPcap itself. */
|
/* OK, now shut down WinPcap itself. */
|
||||||
pcap_close(pc);
|
f_pcap_close(pc);
|
||||||
|
|
||||||
|
/* Unload the DLL if possible. */
|
||||||
|
if (pcap_handle != NULL) {
|
||||||
|
dynld_close(pcap_handle);
|
||||||
|
pcap_handle = NULL;
|
||||||
|
}
|
||||||
}
|
}
|
||||||
poll_rx = NULL;
|
poll_rx = NULL;
|
||||||
poll_arg = NULL;
|
poll_arg = NULL;
|
||||||
@@ -211,49 +246,5 @@ void
|
|||||||
network_pcap_in(uint8_t *bufp, int len)
|
network_pcap_in(uint8_t *bufp, int len)
|
||||||
{
|
{
|
||||||
if (pcap != NULL)
|
if (pcap != NULL)
|
||||||
pcap_sendpacket(pcap, bufp, len);
|
f_pcap_sendpacket(pcap, bufp, len);
|
||||||
}
|
|
||||||
|
|
||||||
|
|
||||||
/* Retrieve an easy-to-use list of devices. */
|
|
||||||
int
|
|
||||||
network_devlist(netdev_t *list)
|
|
||||||
{
|
|
||||||
char errbuf[PCAP_ERRBUF_SIZE];
|
|
||||||
char *temp_dev;
|
|
||||||
pcap_if_t *devlist, *dev;
|
|
||||||
int i = 0;
|
|
||||||
|
|
||||||
/* Create a first entry that's always there - needed by UI. */
|
|
||||||
strcpy(list->device, "none");
|
|
||||||
strcpy(list->description, "None");
|
|
||||||
list++; i++;
|
|
||||||
|
|
||||||
/* See if WinPcap is even present, and get out of here if it's not. */
|
|
||||||
temp_dev = (char *)pcap_lib_version();
|
|
||||||
if (temp_dev == NULL) {
|
|
||||||
/* Hmm, WinPcap doesn't seem to be alive.. */
|
|
||||||
pclog("PCAP: WinPcap library not found, not processing the networks list further!\n");
|
|
||||||
return(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Retrieve the device list from the local machine */
|
|
||||||
if (pcap_findalldevs(&devlist, errbuf) == -1) {
|
|
||||||
pclog("NETWORK: error in pcap_findalldevs: %s\n", errbuf);
|
|
||||||
return(i);
|
|
||||||
}
|
|
||||||
|
|
||||||
for (dev=devlist; dev!=NULL; dev=dev->next) {
|
|
||||||
strcpy(list->device, dev->name);
|
|
||||||
if (dev->description)
|
|
||||||
strcpy(list->description, dev->description);
|
|
||||||
else
|
|
||||||
memset(list->description, '\0', sizeof(list->description));
|
|
||||||
list++; i++;
|
|
||||||
}
|
|
||||||
|
|
||||||
/* Release the memory. */
|
|
||||||
pcap_freealldevs(devlist);
|
|
||||||
|
|
||||||
return(i);
|
|
||||||
}
|
}
|
||||||
|
|||||||
@@ -12,7 +12,7 @@
|
|||||||
* it should be malloc'ed and then linked to the NETCARD def.
|
* it should be malloc'ed and then linked to the NETCARD def.
|
||||||
* Will be done later.
|
* Will be done later.
|
||||||
*
|
*
|
||||||
* Version: @(#)network.c 1.0.4 2017/05/17
|
* Version: @(#)network.c 1.0.5 2017/05/21
|
||||||
*
|
*
|
||||||
* Authors: Kotori, <oubattler@gmail.com>
|
* Authors: Kotori, <oubattler@gmail.com>
|
||||||
* Fred N. van Kempen, <decwiz@yahoo.com>
|
* Fred N. van Kempen, <decwiz@yahoo.com>
|
||||||
@@ -25,6 +25,14 @@
|
|||||||
#include "device.h"
|
#include "device.h"
|
||||||
#include "network.h"
|
#include "network.h"
|
||||||
#include "net_ne2000.h"
|
#include "net_ne2000.h"
|
||||||
|
#ifndef unix
|
||||||
|
# define UNICODE
|
||||||
|
# define BITMAP WINDOWS_BITMAP
|
||||||
|
# include <windows.h>
|
||||||
|
# undef BITMAP
|
||||||
|
# include "win.h"
|
||||||
|
# include "win_language.h"
|
||||||
|
#endif
|
||||||
|
|
||||||
|
|
||||||
static netcard_t net_cards[] = {
|
static netcard_t net_cards[] = {
|
||||||
@@ -59,11 +67,20 @@ char network_pcap[512];
|
|||||||
void
|
void
|
||||||
network_init(void)
|
network_init(void)
|
||||||
{
|
{
|
||||||
|
int i;
|
||||||
|
|
||||||
network_type = NET_TYPE_NONE;
|
network_type = NET_TYPE_NONE;
|
||||||
network_card = 0;
|
network_card = 0;
|
||||||
|
|
||||||
/* Initialize list of PCap devices. */
|
/* Create a first device entry that's always there, as needed by UI. */
|
||||||
network_ndev = network_devlist(network_devs);
|
strcpy(network_devs[0].device, "none");
|
||||||
|
strcpy(network_devs[0].description, "None");
|
||||||
|
network_ndev = 1;
|
||||||
|
|
||||||
|
/* Initialize the Pcap system module, if present. */
|
||||||
|
i = network_pcap_init(&network_devs[network_ndev]);
|
||||||
|
if (i > 0)
|
||||||
|
network_ndev += i;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
@@ -79,7 +96,7 @@ network_attach(void *dev, uint8_t *mac, NETRXCB rx)
|
|||||||
{
|
{
|
||||||
int ret = -1;
|
int ret = -1;
|
||||||
|
|
||||||
if (! network_card) return(ret);
|
if (network_card == 0) return(ret);
|
||||||
|
|
||||||
/* Save the card's callback info. */
|
/* Save the card's callback info. */
|
||||||
net_cards[network_card].private = dev;
|
net_cards[network_card].private = dev;
|
||||||
@@ -89,6 +106,10 @@ network_attach(void *dev, uint8_t *mac, NETRXCB rx)
|
|||||||
switch(network_type) {
|
switch(network_type) {
|
||||||
case NET_TYPE_PCAP:
|
case NET_TYPE_PCAP:
|
||||||
ret = network_pcap_setup(mac, rx, dev);
|
ret = network_pcap_setup(mac, rx, dev);
|
||||||
|
if (ret < 0) {
|
||||||
|
msgbox_error(ghwnd, 2202);
|
||||||
|
network_type = NET_TYPE_NONE;
|
||||||
|
}
|
||||||
break;
|
break;
|
||||||
|
|
||||||
case NET_TYPE_SLIRP:
|
case NET_TYPE_SLIRP:
|
||||||
@@ -128,7 +149,7 @@ network_close(void)
|
|||||||
void
|
void
|
||||||
network_reset(void)
|
network_reset(void)
|
||||||
{
|
{
|
||||||
pclog("NETWORK: reset (type=%d, card=%d\n", network_type, network_card);
|
pclog("NETWORK: reset (type=%d, card=%d)\n", network_type, network_card);
|
||||||
|
|
||||||
/* Just in case.. */
|
/* Just in case.. */
|
||||||
network_close();
|
network_close();
|
||||||
@@ -136,11 +157,10 @@ network_reset(void)
|
|||||||
/* If no active card, we're done. */
|
/* If no active card, we're done. */
|
||||||
if ((network_type==NET_TYPE_NONE) || (network_card==0)) return;
|
if ((network_type==NET_TYPE_NONE) || (network_card==0)) return;
|
||||||
|
|
||||||
pclog("NETWORK: set up for %s, card=%s\n",
|
pclog("NETWORK: set up for %s, card='%s'\n",
|
||||||
(network_type==NET_TYPE_SLIRP)?"SLiRP":"WinPcap",
|
(network_type==NET_TYPE_SLIRP)?"SLiRP":"WinPcap",
|
||||||
net_cards[network_card].name);
|
net_cards[network_card].name);
|
||||||
|
|
||||||
pclog("NETWORK: reset (card=%d)\n", network_card);
|
|
||||||
/* Add the (new?) card to the I/O system. */
|
/* Add the (new?) card to the I/O system. */
|
||||||
if (net_cards[network_card].device) {
|
if (net_cards[network_card].device) {
|
||||||
pclog("NETWORK: adding device '%s'\n",
|
pclog("NETWORK: adding device '%s'\n",
|
||||||
|
|||||||
@@ -8,7 +8,7 @@
|
|||||||
*
|
*
|
||||||
* Definitions for the network module.
|
* Definitions for the network module.
|
||||||
*
|
*
|
||||||
* Version: @(#)network.h 1.0.4 2017/05/17
|
* Version: @(#)network.h 1.0.5 2017/05/21
|
||||||
*
|
*
|
||||||
* Authors: Kotori, <oubattler@gmail.com>
|
* Authors: Kotori, <oubattler@gmail.com>
|
||||||
* Fred N. van Kempen, <decwiz@yahoo.com>
|
* Fred N. van Kempen, <decwiz@yahoo.com>
|
||||||
@@ -62,16 +62,15 @@ extern void network_close(void);
|
|||||||
extern void network_reset(void);
|
extern void network_reset(void);
|
||||||
extern void network_tx(uint8_t *, int);
|
extern void network_tx(uint8_t *, int);
|
||||||
|
|
||||||
|
extern int network_pcap_init(netdev_t *);
|
||||||
extern int network_pcap_setup(uint8_t *, NETRXCB, void *);
|
extern int network_pcap_setup(uint8_t *, NETRXCB, void *);
|
||||||
extern void network_pcap_close(void);
|
extern void network_pcap_close(void);
|
||||||
extern void network_pcap_in(uint8_t *, int);
|
extern void network_pcap_in(uint8_t *, int);
|
||||||
extern int network_devlist(netdev_t *);
|
|
||||||
|
|
||||||
extern int network_slirp_setup(uint8_t *, NETRXCB, void *);
|
extern int network_slirp_setup(uint8_t *, NETRXCB, void *);
|
||||||
extern void network_slirp_close(void);
|
extern void network_slirp_close(void);
|
||||||
extern void network_slirp_in(uint8_t *, int);
|
extern void network_slirp_in(uint8_t *, int);
|
||||||
|
|
||||||
extern int network_devlist(netdev_t *);
|
|
||||||
extern int network_dev_to_id(char *);
|
extern int network_dev_to_id(char *);
|
||||||
extern int network_card_available(int);
|
extern int network_card_available(int);
|
||||||
extern char *network_card_getname(int);
|
extern char *network_card_getname(int);
|
||||||
|
|||||||
Reference in New Issue
Block a user