Network portability fixes - SLiRP and Pcap now both work on Linux and FreeBSD.
This commit is contained in:
@@ -8,7 +8,7 @@
|
||||
*
|
||||
* Handle WinPcap library processing.
|
||||
*
|
||||
* Version: @(#)net_pcap.c 1.0.10 2017/10/16
|
||||
* Version: @(#)net_pcap.c 1.0.11 2017/10/27
|
||||
*
|
||||
* Author: Fred N. van Kempen, <decwiz@yahoo.com>
|
||||
*
|
||||
@@ -79,9 +79,8 @@ poll_thread(void *arg)
|
||||
uint16_t mac_cmp16[2];
|
||||
event_t *evt;
|
||||
|
||||
thread_set_event((event_t *) thread_started);
|
||||
|
||||
pclog("PCAP: polling thread started, arg %08lx\n", arg);
|
||||
thread_set_event((event_t *)thread_started);
|
||||
|
||||
/* Create a waitable event. */
|
||||
evt = thread_create_event();
|
||||
@@ -137,7 +136,11 @@ network_pcap_init(netdev_t *list)
|
||||
pcap = NULL;
|
||||
|
||||
/* Try loading the DLL. */
|
||||
#ifdef WIN32
|
||||
pcap_handle = dynld_module("wpcap.dll", pcap_imports);
|
||||
#else
|
||||
pcap_handle = dynld_module("libpcap.so", pcap_imports);
|
||||
#endif
|
||||
if (pcap_handle == NULL) return(-1);
|
||||
|
||||
/* Retrieve the device list from the local machine */
|
||||
@@ -167,7 +170,12 @@ void
|
||||
network_pcap_reset(void)
|
||||
{
|
||||
/* Try loading the DLL. */
|
||||
#ifdef WIN32
|
||||
pcap_handle = dynld_module("wpcap.dll", pcap_imports);
|
||||
#else
|
||||
pcap_handle = dynld_module("libpcap.so", pcap_imports);
|
||||
#endif
|
||||
|
||||
return;
|
||||
}
|
||||
|
||||
@@ -184,37 +192,19 @@ network_pcap_setup(uint8_t *mac, NETRXCB func, void *arg)
|
||||
/* Did we already load the DLL? */
|
||||
if (pcap_handle == NULL) return(-1);
|
||||
|
||||
#if 1
|
||||
/* Get the value of our capture interface. */
|
||||
dev = network_pcap;
|
||||
if (dev == NULL) {
|
||||
pclog(" PCap device is a null pointer!\n");
|
||||
return(-1);
|
||||
}
|
||||
if ((dev[0] == '\0') || !strcmp(dev, "none")) {
|
||||
pclog(" No network device configured!\n");
|
||||
if ((dev == NULL) || (dev[0] == '\0') || !strcmp(dev, "none")) {
|
||||
pclog(" No PCap interface configured!\n");
|
||||
return(-1);
|
||||
}
|
||||
pclog(" Network interface: '%s'\n", dev);
|
||||
#endif
|
||||
|
||||
strcpy(temp, f_pcap_lib_version());
|
||||
dev = strchr(temp, '(');
|
||||
if (dev != NULL) *(dev-1) = '\0';
|
||||
pclog("PCAP: initializing, %s\n", temp);
|
||||
|
||||
#if 0
|
||||
/* Get the value of our capture interface. */
|
||||
dev = network_pcap;
|
||||
if ((dev[0] == '\0') || !strcmp(dev, "none")) {
|
||||
pclog(" No network device configured!\n");
|
||||
return(-1);
|
||||
}
|
||||
pclog(" Network interface: '%s'\n", dev);
|
||||
#else
|
||||
dev = network_pcap;
|
||||
#endif
|
||||
|
||||
pcap = f_pcap_open_live(dev, /* interface name */
|
||||
1518, /* maximum packet size */
|
||||
1, /* promiscuous mode? */
|
||||
@@ -232,8 +222,13 @@ network_pcap_setup(uint8_t *mac, NETRXCB func, void *arg)
|
||||
"( ((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]);
|
||||
#ifdef WIN32
|
||||
if (f_pcap_compile((pcap_t *) pcap, &fp, filter_exp, 0, 0xffffffff) != -1) {
|
||||
if (f_pcap_setfilter((pcap_t *) pcap, &fp) == -1) {
|
||||
#else
|
||||
if (f_pcap_compile((pcap_t *) pcap, &fp, filter_exp, 0, 0xffffffff) != 0) {
|
||||
if (f_pcap_setfilter((pcap_t *) pcap, &fp) == 0) {
|
||||
#endif
|
||||
pclog(" Error installing filter (%s) !\n", filter_exp);
|
||||
f_pcap_close((pcap_t *) pcap);
|
||||
return (-1);
|
||||
@@ -250,11 +245,9 @@ network_pcap_setup(uint8_t *mac, NETRXCB func, void *arg)
|
||||
|
||||
network_thread_init();
|
||||
|
||||
thread_started = thread_create_event();
|
||||
|
||||
pclog(" Starting thread..\n");
|
||||
thread_started = thread_create_event();
|
||||
poll_tid = thread_create(poll_thread, mac);
|
||||
|
||||
thread_wait_event((event_t *)thread_started, -1);
|
||||
|
||||
return(0);
|
||||
@@ -265,34 +258,20 @@ network_pcap_setup(uint8_t *mac, NETRXCB func, void *arg)
|
||||
void
|
||||
network_pcap_close(void)
|
||||
{
|
||||
volatile pcap_t *pc;
|
||||
pcap_t *pc;
|
||||
|
||||
if (pcap != NULL) {
|
||||
pclog("Closing WinPcap\n");
|
||||
|
||||
/* Tell the polling thread to shut down. */
|
||||
pc = pcap; pcap = NULL;
|
||||
|
||||
#if 0
|
||||
#if 1
|
||||
/* Terminate the polling thread. */
|
||||
if (poll_tid != NULL) {
|
||||
thread_kill(poll_tid);
|
||||
poll_tid = NULL;
|
||||
}
|
||||
#else
|
||||
/* Wait for the polling thread to shut down. */
|
||||
while (poll_tid != NULL)
|
||||
;
|
||||
#endif
|
||||
#endif
|
||||
pc = (pcap_t *)pcap; pcap = NULL;
|
||||
|
||||
/* Tell the thread to terminate. */
|
||||
if (poll_tid != NULL) {
|
||||
network_busy(0);
|
||||
|
||||
pclog("Waiting for network thread to end...\n");
|
||||
/* Wait for the end event. */
|
||||
pclog("Waiting for network thread to end...\n");
|
||||
network_wait_for_end((void *)poll_tid);
|
||||
pclog("Network thread ended\n");
|
||||
|
||||
@@ -306,7 +285,7 @@ network_pcap_close(void)
|
||||
|
||||
/* OK, now shut down WinPcap itself. */
|
||||
f_pcap_close((pcap_t *)pc);
|
||||
pc = pcap = NULL;
|
||||
pcap = NULL;
|
||||
|
||||
/* Unload the DLL if possible. */
|
||||
if (pcap_handle != NULL) {
|
||||
|
||||
@@ -6,21 +6,26 @@
|
||||
*
|
||||
* This file is part of the 86Box distribution.
|
||||
*
|
||||
* Simple program to show usage of WinPcap.
|
||||
* Simple program to show usage of (Win)Pcap.
|
||||
*
|
||||
* Based on the "libpcap" examples.
|
||||
*
|
||||
* Version: @(#)pcap_if.c 1.0.5 2017/10/10
|
||||
* Version: @(#)pcap_if.c 1.0.6 2017/10/27
|
||||
*
|
||||
* Author: Fred N. van Kempen, <decwiz@yahoo.com>
|
||||
*
|
||||
* Copyright 2017 Fred N. van Kempen.
|
||||
*/
|
||||
#include <stdio.h>
|
||||
#include <stdint.h>
|
||||
#include <string.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <ctype.h>
|
||||
#include <pcap.h>
|
||||
#include <time.h>
|
||||
#include "../86box.h"
|
||||
#include "../plat.h"
|
||||
#include "../plat_dynld.h"
|
||||
|
||||
|
||||
@@ -46,12 +51,12 @@ static dllimp_t pcap_imports[] = {
|
||||
typedef struct {
|
||||
char device[128];
|
||||
char description[128];
|
||||
} dev_t;
|
||||
} capdev_t;
|
||||
|
||||
|
||||
/* Retrieve an easy-to-use list of devices. */
|
||||
static int
|
||||
get_devlist(dev_t *list)
|
||||
get_devlist(capdev_t *list)
|
||||
{
|
||||
char errbuf[PCAP_ERRBUF_SIZE];
|
||||
pcap_if_t *devlist, *dev;
|
||||
@@ -192,7 +197,7 @@ start_cap(char *dev)
|
||||
|
||||
/* Show a list of available network interfaces. */
|
||||
static void
|
||||
show_devs(dev_t *list, int num)
|
||||
show_devs(capdev_t *list, int num)
|
||||
{
|
||||
int i;
|
||||
|
||||
@@ -228,13 +233,21 @@ pclog(const char *fmt, ...)
|
||||
int
|
||||
main(int argc, char **argv)
|
||||
{
|
||||
dev_t interfaces[32];
|
||||
capdev_t interfaces[32];
|
||||
int numdev, i;
|
||||
|
||||
/* Try loading the DLL. */
|
||||
#ifdef WIN32
|
||||
pcap_handle = dynld_module("wpcap.dll", pcap_imports);
|
||||
#else
|
||||
pcap_handle = dynld_module("libpcap.so", pcap_imports);
|
||||
#endif
|
||||
if (pcap_handle == NULL) {
|
||||
#ifdef WIN32
|
||||
fprintf(stderr, "Unable to load WinPcap DLL !\n");
|
||||
#else
|
||||
fprintf(stderr, "Unable to load libpcap.so !\n");
|
||||
#endif
|
||||
return(1);
|
||||
}
|
||||
|
||||
|
||||
@@ -222,7 +222,11 @@ void* fluidsynth_init(device_t *info)
|
||||
memset(data, 0, sizeof(fluidsynth_t));
|
||||
|
||||
/* Try loading the DLL. */
|
||||
#ifdef WIN32
|
||||
fluidsynth_handle = dynld_module("libfluidsynth.dll", fluidsynth_imports);
|
||||
#else
|
||||
fluidsynth_handle = dynld_module("libfluidsynth.so", fluidsynth_imports);
|
||||
#endif
|
||||
if (fluidsynth_handle == NULL)
|
||||
{
|
||||
ui_msgbox(MBX_ERROR, (wchar_t *)IDS_2171);
|
||||
|
||||
Reference in New Issue
Block a user