aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorMichael Richardson <mcr@sandelman.ca>2023-07-27 12:41:06 -0400
committerGitHub <noreply@github.com>2023-07-27 12:41:06 -0400
commit08a63dc096c5360806487ee17f9e06ae6c833a67 (patch)
treeaa7c6973dc4e822bb5c725c2df483b8b5c0c9d2f
parentc63961294842a15cdfc858e991d611e72aec6f8c (diff)
parente80574e28617c0948eacccabf4bb665035458870 (diff)
Merge pull request #1209 from the-tcpdump-group/nuke-msdos
MSDOS packet driver interface is no longer testable
-rw-r--r--INSTALL.md4
-rw-r--r--Makefile.in11
-rw-r--r--gencode.c4
-rw-r--r--msdos/bin2c.c43
-rw-r--r--msdos/makefile179
-rw-r--r--msdos/makefile.dj127
-rw-r--r--msdos/makefile.wc132
-rw-r--r--msdos/pkt_rx0.asm197
-rw-r--r--msdos/pkt_rx1.s155
-rw-r--r--msdos/pktdrvr.c1436
-rw-r--r--msdos/pktdrvr.h153
-rw-r--r--msdos/readme.dos166
-rw-r--r--optimize.c16
-rw-r--r--pcap-dos.c1550
-rw-r--r--pcap-dos.h225
-rw-r--r--pcap-int.h11
-rw-r--r--pcap.c27
-rw-r--r--savefile.c6
-rw-r--r--sf-pcap.c6
19 files changed, 12 insertions, 4436 deletions
diff --git a/INSTALL.md b/INSTALL.md
index 10836eba..30229cb3 100644
--- a/INSTALL.md
+++ b/INSTALL.md
@@ -245,7 +245,6 @@ in `/usr/include/sys/dlpi.h`, and find the corresponding value.
llc.h - 802.2 LLC SAP definitions
missing/* - replacements for missing library functions
mkdep - construct Makefile dependency list
- msdos/* - drivers for MS-DOS capture support
nametoaddr.c - hostname to address routines
nametoaddr.h - hostname to address prototypes
nlpid.h - OSI network layer protocol identifier definitions
@@ -281,8 +280,7 @@ in `/usr/include/sys/dlpi.h`, and find the corresponding value.
pcap-dbus.c - D-Bus capture support
pcap-dbus.h - D-Bus capture support
pcap-dlpi.c - Data Link Provider Interface support
- pcap-dos.c - MS-DOS capture support
- pcap-dos.h - headers for MS-DOS capture support
+ pcap-dos.c - removed in 2023, after libpcap 1.10
pcap-dpdk.c - DPDK device support
pcap-dpdk.h - DPDK device support
pcap-enet.c - enet support
diff --git a/Makefile.in b/Makefile.in
index da00e79f..b5025c33 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -296,15 +296,6 @@ EXTRA_DIST = \
missing/strtok_r.c \
missing/win_asprintf.c \
mkdep \
- msdos/bin2c.c \
- msdos/makefile \
- msdos/makefile.dj \
- msdos/makefile.wc \
- msdos/pkt_rx0.asm \
- msdos/pkt_rx1.s \
- msdos/pktdrvr.c \
- msdos/pktdrvr.h \
- msdos/readme.dos \
nomkdep \
org.tcpdump.chmod_bpf.plist \
pcap-airpcap.c \
@@ -321,8 +312,6 @@ EXTRA_DIST = \
pcap-dbus.h \
pcap-dll.rc \
pcap-dlpi.c \
- pcap-dos.c \
- pcap-dos.h \
pcap-dpdk.c \
pcap-dpdk.h \
pcap-enet.c \
diff --git a/gencode.c b/gencode.c
index 501354bb..8f055492 100644
--- a/gencode.c
+++ b/gencode.c
@@ -43,10 +43,6 @@
#include <stdarg.h>
#include <stdio.h>
-#ifdef MSDOS
-#include "pcap-dos.h"
-#endif
-
#include "pcap-int.h"
#include "extract.h"
diff --git a/msdos/bin2c.c b/msdos/bin2c.c
deleted file mode 100644
index 26d90083..00000000
--- a/msdos/bin2c.c
+++ /dev/null
@@ -1,43 +0,0 @@
-#include <stdio.h>
-#include <stdlib.h>
-#include <stdarg.h>
-#include <time.h>
-
-static void Abort (const char *fmt,...)
-{
- va_list args;
- va_start (args, fmt);
- vfprintf (stderr, fmt, args);
- va_end (args);
- exit (1);
-}
-
-int main (int argc, char **argv)
-{
- FILE *inFile;
- FILE *outFile = stdout;
- time_t now = time (NULL);
- int ch, i;
-
- if (argc != 2)
- Abort ("Usage: %s bin-file [> result]", argv[0]);
-
- if ((inFile = fopen(argv[1],"rb")) == NULL)
- Abort ("Cannot open %s\n", argv[1]);
-
- fprintf (outFile,
- "/* data statements for file %s at %.24s */\n"
- "/* Generated by BIN2C, G. Vanem 1995 */\n",
- argv[1], ctime(&now));
-
- i = 0;
- while ((ch = fgetc(inFile)) != EOF)
- {
- if (i++ % 12 == 0)
- fputs ("\n ", outFile);
- fprintf (outFile, "0x%02X,", ch);
- }
- fputc ('\n', outFile);
- fclose (inFile);
- return (0);
-}
diff --git a/msdos/makefile b/msdos/makefile
deleted file mode 100644
index b86abec5..00000000
--- a/msdos/makefile
+++ /dev/null
@@ -1,179 +0,0 @@
-#
-# Makefile for dos-libpcap. NB. This makefile requires a Borland
-# compatible make tool.
-#
-# Targets:
-# Borland C 4.0+ (DOS large model)
-# Metaware HighC 3.3+ (PharLap 386|DosX)
-#
-
-.AUTODEPEND
-.SWAP
-
-!if "$(WATT_ROOT)" == ""
-!error Environment variable "WATT_ROOT" not set.
-!endif
-
-WATT_INC = $(WATT_ROOT)\inc
-
-DEFS = -DMSDOS -DDEBUG -DNDIS_DEBUG -D_U_= -Dinline= \
- -DHAVE_STRERROR -DHAVE_LIMITS_H
-
-ASM = tasm.exe -t -l -mx -m2 -DDEBUG
-
-SOURCE = grammar.c scanner.c bpf_filt.c bpf_imag.c bpf_dump.c \
- etherent.c gencode.c nametoad.c pcap-dos.c optimize.c \
- savefile.c pcap.c msdos\ndis2.c msdos\pktdrvr.c
-
-BORLAND_OBJ = $(SOURCE:.c=.obj) msdos\pkt_rx0.obj msdos\ndis_0.obj
-
-HIGHC_OBJ = $(SOURCE:.c=.o32) msdos\pkt_rx0.o32
-
-all:
- @echo Usage: make pcap_bc.lib or pcap_hc.lib
-
-
-pcap_bc.lib: bcc.arg $(BORLAND_OBJ) pcap_bc
-
-
-pcap_hc.lib: hc386.arg $(HIGHC_OBJ)
- 386lib $< @&&|
- -nowarn -nobackup -twocase -replace $(HIGHC_OBJ)
-|
-
-pcap_bc: $(BORLAND_OBJ)
- @tlib pcap_bc.lib /C @&&|
- -+$(**:.obj=-+)
-|
-
-.c.obj:
- bcc.exe @bcc.arg -o$*.obj $*.c
-
-.c.o32:
- hc386.exe @hc386.arg -o $*.o32 $*.c
-
-.asm.obj:
- $(ASM) $*.asm, $*.obj
-
-.asm.o32:
- $(ASM) -DDOSX=1 $*.asm, $*.o32
-
-scanner.c: scanner.l
- flex -Ppcap_ -7 -oscanner.c scanner.l
-
-grammar.c tokdefs.h: grammar.y
- bison --name-prefix=pcap_ --yacc --defines grammar.y
- - @del grammar.c
- - @del tokdefs.h
- ren y_tab.c grammar.c
- ren y_tab.h tokdefs.h
-
-bcc.arg: msdos\Makefile
- @copy &&|
- $(DEFS) -ml -c -v -3 -O2 -po -RT- -w-
- -I$(WATT_INC) -I. -I.\msdos\pm_drvr -H=$(TEMP)\bcc.sym
-| $<
-
-hc386.arg: msdos\Makefile
- @copy &&|
- # -DUSE_32BIT_DRIVERS
- $(DEFS) -DDOSX=1 -w3 -c -g -O5
- -I$(WATT_INC) -I. -I.\msdos\pm_drvr
- -Hsuffix=.o32
- -Hnocopyr
- -Hpragma=Offwarn(491,553,572)
- -Hon=Recognize_library # make memcpy/strlen etc. inline
- -Hoff=Behaved # turn off some optimizer warnings
-| $<
-
-clean:
- @del *.obj
- @del *.o32
- @del *.lst
- @del *.map
- @del bcc.arg
- @del hc386.arg
- @del grammar.c
- @del tokdefs.h
- @del scanner.c
- @echo Cleaned
-
-#
-# dependencies
-#
-pkt_rx0.obj: msdos\pkt_rx0.asm
-
-bpf_filt.obj: bpf_filt.c pcap-int.h pcap.h pcap-bpf.h
-
-bpf_imag.obj: bpf_imag.c pcap-int.h pcap.h pcap-bpf.h
-
-bpf_dump.obj: bpf_dump.c pcap.h pcap-bpf.h
-
-etherent.obj: etherent.c pcap-int.h pcap.h pcap-bpf.h pcap-namedb.h
-
-optimize.obj: optimize.c pcap-int.h pcap.h pcap-bpf.h gencode.h
-
-savefile.obj: savefile.c pcap-int.h pcap.h pcap-bpf.h
-
-pcap.obj: pcap.c pcap-dos.h pcap-int.h pcap.h pcap-bpf.h
-
-grammar.obj: grammar.c pcap-int.h pcap.h pcap-bpf.h gencode.h \
- pf.h pcap-namedb.h
-
-scanner.obj: scanner.c pcap-int.h pcap.h pcap-bpf.h gencode.h \
- pcap-namedb.h tokdefs.h
-
-gencode.obj: gencode.c pcap-dos.h pcap-int.h pcap.h pcap-bpf.h \
- ethertype.h nlpid.h llc.h gencode.h atmuni31.h sunatmpos.h ppp.h sll.h \
- arcnet.h pf.h pcap-namedb.h
-
-nametoad.obj: nametoad.c pcap-int.h pcap.h pcap-bpf.h gencode.h \
- pcap-namedb.h ethertype.h
-
-pcap-dos.obj: pcap-dos.c pcap.h pcap-bpf.h pcap-dos.h pcap-int.h \
- msdos\pktdrvr.h
-
-pktdrvr.obj: msdos\pktdrvr.c pcap-dos.h pcap-int.h \
- pcap.h pcap-bpf.h msdos\pktdrvr.h msdos\pkt_stub.inc
-
-ndis2.obj: msdos\ndis2.c pcap-dos.h pcap-int.h pcap.h pcap-bpf.h \
- msdos\ndis2.h
-
-pkt_rx0.o32: msdos\pkt_rx0.asm
-
-bpf_filt.o32: bpf_filt.c pcap-int.h pcap.h pcap-bpf.h
-
-bpf_imag.o32: bpf_imag.c pcap-int.h pcap.h pcap-bpf.h
-
-bpf_dump.o32: bpf_dump.c pcap.h pcap-bpf.h
-
-etherent.o32: etherent.c pcap-int.h pcap.h pcap-bpf.h pcap-namedb.h
-
-optimize.o32: optimize.c pcap-int.h pcap.h pcap-bpf.h gencode.h
-
-savefile.o32: savefile.c pcap-int.h pcap.h pcap-bpf.h
-
-pcap.o32: pcap.c pcap-dos.h pcap-int.h pcap.h pcap-bpf.h
-
-grammar.o32: grammar.c pcap-int.h pcap.h pcap-bpf.h gencode.h \
- pf.h pcap-namedb.h
-
-scanner.o32: scanner.c pcap-int.h pcap.h pcap-bpf.h gencode.h \
- pcap-namedb.h tokdefs.h
-
-gencode.o32: gencode.c pcap-dos.h pcap-int.h pcap.h pcap-bpf.h \
- ethertype.h nlpid.h llc.h gencode.h atmuni31.h sunatmpos.h ppp.h sll.h \
- arcnet.h pf.h pcap-namedb.h
-
-nametoad.o32: nametoad.c pcap-int.h pcap.h pcap-bpf.h gencode.h \
- pcap-namedb.h ethertype.h
-
-pcap-dos.o32: pcap-dos.c pcap.h pcap-bpf.h pcap-dos.h pcap-int.h \
- msdos\pktdrvr.h
-
-pktdrvr.o32: msdos\pktdrvr.c pcap-dos.h pcap-int.h \
- pcap.h pcap-bpf.h msdos\pktdrvr.h msdos\pkt_stub.inc
-
-ndis2.o32: msdos\ndis2.c pcap-dos.h pcap-int.h pcap.h pcap-bpf.h \
- msdos\ndis2.h
-
diff --git a/msdos/makefile.dj b/msdos/makefile.dj
deleted file mode 100644
index 7c65cc06..00000000
--- a/msdos/makefile.dj
+++ /dev/null
@@ -1,127 +0,0 @@
-#
-# GNU Makefile for DOS-libpcap. djgpp version.
-#
-# Use this makefile from the libpcap root directory.
-# E.g. like this:
-#
-# c:\net\pcap> make -f msdos/makefile.dj
-#
-# Note: you should do a "set LFN=y" before running this makefile.
-#
-
-VPATH = missing msdos
-
-PREREQUISITES = scanner.c grammar.c tokdefs.h version.h msdos/pkt_stub.inc
-
-include ./msdos/common.dj
-
-DRIVER_DIR = ./msdos/pm_drvr
-
-CFLAGS += -DDEBUG -DNDIS_DEBUG -DHAVE_LIMITS_H -DHAVE_STRERROR -DHAVE_SNPRINTF -DHAVE_VSNPRINTF\
- -D_U_='__attribute__((unused))'
-
-CFLAGS += -Dyylval=pcap_lval # -DBDEBUG -DNDEBUG
-
-SOURCES = grammar.c scanner.c bpf_filter.c bpf_image.c bpf_dump.c \
- etherent.c gencode.c nametoaddr.c pcap-common.c pcap-dos.c optimize.c \
- savefile.c pcap.c sf-pcap.c sf-pcapng.c \
- msdos/pktdrvr.c msdos/ndis2.c
-
-OBJECTS = $(addprefix $(OBJ_DIR)/, $(notdir $(SOURCES:.c=.o)))
-TEMPBIN = tmp.bin
-
-ifeq ($(USE_32BIT_DRIVERS),1)
- PM_OBJECTS = $(addprefix $(OBJ_DIR)/, \
- printk.o pci.o pci-scan.o bios32.o dma.o irq.o intwrap.o \
- lock.o kmalloc.o quirks.o timer.o net_init.o)
- #
- # Static link of drivers
- #
- ifeq ($(USE_32BIT_MODULES),0)
- PM_OBJECTS += $(addprefix $(OBJ_DIR)/, \
- accton.o 8390.o 3c503.o 3c509.o 3c59x.o 3c515.o \
- 3c575_cb.o 3c90x.o ne.o wd.o cs89x0.o rtl8139.o)
- endif
-endif
-
-TARGETS = msdos/bin2c.exe libpcap.a filtertest.exe findalldevstest.exe \
- nonblocktest.exe opentest.exe
-
-all: $(TARGETS)
- @echo 'Welcome to libpcap/djgpp with samples.'
-
-ifeq ($(USE_32BIT_DRIVERS),1)
-$(PM_OBJECTS):
- $(MAKE) -f Makefile.dj -C $(DRIVER_DIR) $(notdir $@)
-endif
-
-libpcap.a: version.h $(OBJECTS) $(PM_OBJECTS)
- rm -f $@
- ar rs $@ $^
-
-filtertest.exe: tests/filtertest.c libpcap.a
- $(CC) $(CFLAGS) -Din_addr_t=u_long -o $@ $^ $(WATT32_ROOT)/lib/libwatt.a
- @echo
-
-findalldevstest.exe: tests/findalldevstest.c libpcap.a
- $(CC) $(CFLAGS) -o $@ $^ $(WATT32_ROOT)/lib/libwatt.a
- @echo
-
-nonblocktest.exe: tests/nonblocktest.c libpcap.a
- $(CC) $(CFLAGS) -o $@ $^ $(WATT32_ROOT)/lib/libwatt.a
- @echo
-
-opentest.exe: tests/opentest.c libpcap.a
- $(CC) $(CFLAGS) -o $@ $^ $(WATT32_ROOT)/lib/libwatt.a
- @echo
-
-msdos/pkt_stub.inc: msdos/bin2c.exe msdos/pkt_rx1.S
- $(ASM) -o $(TEMPBIN) -lmsdos/pkt_rx1.lst msdos/pkt_rx1.S
- ./msdos/bin2c $(TEMPBIN) > $@
- rm -f $(TEMPBIN)
-
-grammar.c tokdefs.h: grammar.y
- rm -f grammar.c tokdefs.h
- $(YACC) --name-prefix=pcap_ --yacc --defines grammar.y
- mv -f y.tab.c grammar.c
- mv -f y.tab.h tokdefs.h
-
-version.h: ./VERSION
- @echo '/* Generated from VERSION. Do not edit */' > $@
- sed -e 's/.*/static char pcap_version_string[] = "libpcap (&)";/' ./VERSION >> $@
-
-scanner.c: scanner.l
- $(LEX) -Ppcap_ -7 -t $^ > $@
- @echo
-
-msdos/bin2c.exe: msdos/bin2c.c
- $(CC) $*.c -o $*.exe
-
-clean:
- rm -f $(OBJECTS) msdos/pkt_rx1.lst Makefile.bak .depend.dj $(PREREQUISITES)
-# $(MAKE) -f Makefile.dj -C $(DRIVER_DIR) clean
-
-vclean: clean
- rm -f $(TARGETS)
- -rmdir $(OBJ_DIR)
-
-#
-# Manually generated dependencies
-#
-msdos/pktdrvr.c: msdos/pkt_stub.inc
-scanner.c: scanner.l
-grammar.c tokdefs.h: grammar.y
-grammar.h: grammar.y
-scanner.l: pcap-int.h pcap-namedb.h gencode.h grammar.h
-grammar.y: pcap-int.h gencode.h pcap-namedb.h
-
-#
-# Generate dependencies.
-#
-REPLACE = sed -e 's/\(.*\)\.o: /\n$$(OBJ_DIR)\/\1.o: /'
-
-depend: $(PREREQUISITES)
- $(CC) -MM $(CFLAGS) $(SOURCES) | $(REPLACE) > .depend.dj
-
--include .depend.dj
-
diff --git a/msdos/makefile.wc b/msdos/makefile.wc
deleted file mode 100644
index a0aa71fc..00000000
--- a/msdos/makefile.wc
+++ /dev/null
@@ -1,132 +0,0 @@
-#
-# Watcom Makefile for dos-libpcap.
-#
-# Specify MODEL = `3r' or `3s'
-# Specify TARGET = `pharlap' or `dos4g'
-#
-# Use this makefile from the libpcap root directory.
-# E.g. like this:
-#
-# c:\net\pcap> wmake -f msdos\makefile.wc
-#
-
-MODEL = 3s
-TARGET = dos4g
-
-OBJDIR = msdos\$(TARGET).w$(MODEL)
-LIB = $(OBJDIR)\pcap.lib
-
-.EXTENSIONS: .l .y
-
-DEFS = -dDEBUG -dNDIS_DEBUG -d_U_= -dHAVE_LIMITS_H -dHAVE_STRERROR &
- -dHAVE_SNPRINTF -dHAVE_VSNPRINTF
-
-CC = wcc386.exe
-ASM = wasm.exe -$(MODEL) $(DEFS) -dDOSX -dDOS4GW -zq -bt=dos -fr=nul -d3 -s
-
-OBJS = $(OBJDIR)\grammar.obj $(OBJDIR)\scanner.obj $(OBJDIR)\pcap.obj &
- $(OBJDIR)\bpf_filter.obj $(OBJDIR)\bpf_imag.obj $(OBJDIR)\bpf_dump.obj &
- $(OBJDIR)\etherent.obj $(OBJDIR)\gencode.obj $(OBJDIR)\nametoad.obj &
- $(OBJDIR)\pcap-dos.obj $(OBJDIR)\pktdrvr.obj $(OBJDIR)\optimize.obj &
- $(OBJDIR)\savefile.obj $(OBJDIR)\ndis2.obj
-
-CFLAGS = $(DEFS) $(YYDEFS) -I. -I$(%watt_root)\inc -I.\msdos\pm_drvr &
- -$(MODEL) -mf -zff -zgf -zq -bt=dos -fr=nul -w6 -fpi &
- -oilrtf -zm
-
-TEMPBIN = tmp.bin
-
-all: $(OBJDIR) $(OBJDIR)\pcap.lib
-
-$(OBJDIR):
- - mkdir $(OBJDIR)
-
-$(OBJDIR)\pcap.lib: $(OBJS) wlib.arg
- wlib -q -b -c $(OBJDIR)\pcap.lib @wlib.arg
-
-wlib.arg: msdos\makefile.wc
- %create $^@
- for %f in ($(OBJS)) do %append $^@ +- %f
-
-$(OBJDIR)\pktdrvr.obj: msdos\pkt_stub.inc msdos\pktdrvr.c &
- pcap-dos.h pcap-int.h pcap.h msdos\pktdrvr.h
- *$(CC) $(CFLAGS) msdos\pktdrvr.c -fo=$@
-
-$(OBJDIR)\bpf_filter.obj: bpf_filter.c
- *$(CC) $(CFLAGS) bpf_filter.c -fo=$@
-
-$(OBJDIR)\ndis2.obj: msdos\ndis2.c
- *$(CC) $(CFLAGS) msdos\ndis2.c -fo=$@
-
-.ERASE
-.c{$(OBJDIR)}.obj:
- *$(CC) $(CFLAGS) $[@ -fo=$@
-
-grammar.c tokdefs.h: grammar.y
- bison --name-prefix=pcap_ --yacc --defines $[@
- - @del grammar.c
- - @del tokdefs.h
- ren y_tab.c grammar.c
- ren y_tab.h tokdefs.h
-
-scanner.c: scanner.l
- flex -Ppcap_ -7 -o$@ $[@
-
-msdos\pkt_stub.inc: bin2c.exe msdos\pkt_rx1.S
- nasm -fbin -dDEBUG -o $(TEMPBIN) -lmsdos\pkt_rx1.lst msdos\pkt_rx1.S
- bin2c.exe $(TEMPBIN) > $@
- @del $(TEMPBIN)
-
-bin2c.exe: msdos\bin2c.c
- wcl $[@
-
-clean realclean vclean: .SYMBOLIC
- for %f in (dos4g.w3r dos4g.w3s pharlap.w3r pharlap.w3s) do &
- @del %f\*.obj
- @del grammar.c
- @del tokdefs.h
- @del scanner.c
- @del bin2c.exe
- @del bin2c.obj
- @del msdos\pkt_stub.inc
- @echo Cleaned
-
-#
-# dependencies
-#
-$(OBJDIR)\bpf_filter.obj: bpf_filter.c pcap-int.h pcap.h pcap-bpf.h
-
-$(OBJDIR)\bpf_imag.obj: bpf_imag.c pcap-int.h pcap.h pcap-bpf.h
-
-$(OBJDIR)\bpf_dump.obj: bpf_dump.c pcap.h pcap-bpf.h
-
-$(OBJDIR)\etherent.obj: etherent.c pcap-int.h pcap.h pcap-bpf.h pcap-namedb.h
-
-$(OBJDIR)\optimize.obj: optimize.c pcap-int.h pcap.h pcap-bpf.h gencode.h
-
-$(OBJDIR)\savefile.obj: savefile.c pcap-int.h pcap.h pcap-bpf.h
-
-$(OBJDIR)\pcap.obj: pcap.c pcap-dos.h pcap-int.h pcap.h pcap-bpf.h
-
-$(OBJDIR)\grammar.obj: grammar.c pcap-int.h pcap.h pcap-bpf.h gencode.h &
- pcap-namedb.h
-
-$(OBJDIR)\scanner.obj: scanner.c pcap-int.h pcap.h pcap-bpf.h gencode.h &
- pcap-namedb.h tokdefs.h
-
-$(OBJDIR)\gencode.obj: gencode.c pcap-dos.h pcap-int.h pcap.h pcap-bpf.h &
- ethertyp.h nlpid.h llc.h gencode.h atmuni31.h sunatmpo.h ppp.h sll.h &
- arcnet.h pcap-namedb.h
-
-$(OBJDIR)\nametoad.obj: nametoad.c pcap-int.h pcap.h pcap-bpf.h gencode.h &
- pcap-namedb.h ethertyp.h
-
-$(OBJDIR)\pcap-dos.obj: pcap-dos.c pcap.h pcap-bpf.h pcap-dos.h pcap-int.h &
- msdos\pktdrvr.h
-
-$(OBJDIR)\pktdrvr.obj: msdos\pktdrvr.c pcap-dos.h pcap-int.h &
- pcap.h pcap-bpf.h msdos\pktdrvr.h msdos\pkt_stub.inc
-
-$(OBJDIR)\ndis2.obj: msdos\ndis2.c pcap-dos.h pcap-int.h pcap.h pcap-bpf.h &
- msdos\ndis2.h
-
diff --git a/msdos/pkt_rx0.asm b/msdos/pkt_rx0.asm
deleted file mode 100644
index d604fa14..00000000
--- a/msdos/pkt_rx0.asm
+++ /dev/null
@@ -1,197 +0,0 @@
-PAGE 60,132
-NAME PKT_RX
-
-ifdef ??version ; using TASM
- masm
- jumps
-endif
-
-PUBLIC _pktDrop, _pktRxBuf, _pktTxBuf, _pktTemp
-PUBLIC _rxOutOfs, _rxInOfs, _PktReceiver, _pktRxEnd
-
-;
-; these sizes MUST be equal to the sizes in PKTDRVR.H
-;
-
-RX_BUF_SIZE = 1500 ; max message size on Ethernet
-TX_BUF_SIZE = 1500
-
-ifdef DOSX
- .386
- NUM_RX_BUF = 32 ; # of RX element buffers
- _TEXT SEGMENT PUBLIC DWORD USE16 'CODE'
- _TEXT ENDS
- _DATA SEGMENT PUBLIC DWORD USE16 'CODE'
- _DATA ENDS
- D_SEG EQU <_TEXT SEGMENT>
- D_END EQU <_TEXT ENDS>
- ASSUME CS:_TEXT,DS:_TEXT
-else
- .286
- NUM_RX_BUF = 10
- _TEXT SEGMENT PUBLIC DWORD 'CODE'
- _TEXT ENDS
- _DATA SEGMENT PUBLIC DWORD 'DATA'
- _DATA ENDS
- D_SEG EQU <_DATA SEGMENT>
- D_END EQU <_DATA ENDS>
- ASSUME CS:_TEXT,DS:_DATA
-endif
-
-;-------------------------------------------
-
-D_SEG
-
-RX_ELEMENT STRUC
- firstCount dw 0 ; # of bytes on 1st call
- secondCount dw 0 ; # of bytes on 2nd call
- handle dw 0 ; handle for upcall
- destinAdr db 6 dup (0) ; packet destination address
- sourceAdr db 6 dup (0) ; packet source address
- protocol dw 0 ; packet protocol number
- rxBuffer db RX_BUF_SIZE dup (0) ; RX buffer
-ENDS
- align 4
-_rxOutOfs dw offset _pktRxBuf ; ring buffer offsets
-_rxInOfs dw offset _pktRxBuf ; into _pktRxBuf
-_pktDrop dw 0,0 ; packet drop counter
-_pktTemp db 20 dup (0) ; temp work area
-_pktTxBuf db (TX_BUF_SIZE+14) dup (0) ; TX buffer
-_pktRxBuf RX_ELEMENT NUM_RX_BUF dup (<>) ; RX structures
- LAST_OFS = offset $
-
- screenSeg dw 0B800h
- newInOffset dw 0
-
- fanChars db '-\|/'
- fanIndex dw 0
-
-D_END
-
-_TEXT SEGMENT
-
-
-SHOW_RX MACRO
- push es
- push bx
- mov bx, screenSeg
- mov es, bx ;; r-mode segment of colour screen
- mov di, 158 ;; upper right corner - 1
- mov bx, fanIndex
- mov al, fanChars[bx] ;; get write char
- mov ah, 15 ;; and white colour
- stosw ;; write to screen at ES:EDI
- inc fanIndex ;; update next index
- and fanIndex, 3
- pop bx
- pop es
-ENDM
-
-;------------------------------------------------------------------------
-;
-; This macro return ES:DI to tail of Rx queue
-
-ENQUEUE MACRO
- LOCAL @noWrap
- mov ax, _rxInOfs ;; DI = current in-offset
- add ax, SIZE RX_ELEMENT ;; point to next _pktRxBuf buffer
- cmp ax, LAST_OFS ;; pointing past last ?
- jb @noWrap ;; no - jump
- lea ax, _pktRxBuf ;; yes, point to 1st buffer
- align 4
-@noWrap: cmp ax, _rxOutOfs ;; in-ofs = out-ofs ?
- je @dump ;; yes, queue is full
- mov di, _rxInOfs ;; ES:DI -> buffer at queue input
- mov newInOffset, ax ;; remember new input offset
-
- ;; NOTE. rxInOfs is updated after the packet has been copied
- ;; to ES:DI (= DS:SI on 2nd call) by the packet driver
-
-ENDM
-
-;------------------------------------------------------------------------
-;
-; This routine gets called by the packet driver twice:
-; 1st time (AX=0) it requests an address where to put the packet
-;
-; 2nd time (AX=1) the packet has been copied to this location (DS:SI)
-; BX has client handle (stored in RX_ELEMENT.handle).
-; CX has # of bytes in packet on both call. They should be equal.
-;
-; A test for equality is done by putting CX in _pktRxBuf [n].firstCount
-; and _pktRxBuf[n].secondCount, and CL on first call in
-; _pktRxBuf[n].rxBuffer[CX]. These values are checked in "PktReceive"
-; (PKTDRVR.C)
-;
-;---------------------------------------------------------------------
-
-_PktReceiver:
- pushf
- cli ; no distraction wanted !
- push ds
- push bx
-ifdef DOSX
- mov bx, cs
-else
- mov bx, SEG _DATA
-endif
- mov ds, bx
- mov es, bx ; ES = DS = CS or seg _DATA
- pop bx ; restore handle
-
- cmp ax, 0 ; first call? (AX=0)
- jne @post ; AX=1: second call, do post process
-
-ifdef DEBUG
- SHOW_RX ; show that a packet is received
-endif
- cmp cx, RX_BUF_SIZE+14 ; size OK ?
- ja @skip ; no, packet to large for us
-
- ENQUEUE ; ES:DI -> _pktRxBuf[n]
-
- mov [di].firstCount, cx ; remember the first count.
- mov [di].handle, bx ; remember the handle.
- add di, 6 ; ES:DI -> _pktRxBuf[n].destinAdr
- pop ds
- popf
- retf ; far return to driver with ES:DI
-
- align 4
-@dump: inc _pktDrop[0] ; discard the packet on 1st call
- adc _pktDrop[2], 0 ; increment packets lost
-
-@skip: xor di, di ; return ES:DI = NIL pointer
- xor ax, ax
- mov es, ax
- pop ds
- popf
- retf
-
- align 4
-@post: or si, si ; DS:SI->_pktRxBuf[n][n].destinAdr
- jz @discard ; make sure we don't use NULL-pointer
-
- sub si, 6 ; DS:SI -> _pktRxBuf[n].destinAdr
- ;
- ; push si
- ; push [si].firstCount
- ; call bpf_filter_match ; run the filter here some day?
- ; add sp, 4
- ; cmp ax, 0
- ; je @discard
-
- mov [si].secondCount, cx
- mov ax, newInOffset
- mov _rxInOfs, ax ; update _pktRxBuf input offset
-
- align 4
-@discard:pop ds
- popf
- retf
-
-_pktRxEnd db 0 ; marker for end of r-mode code/data
-
-_TEXT ENDS
-
-END
diff --git a/msdos/pkt_rx1.s b/msdos/pkt_rx1.s
deleted file mode 100644
index 654e6577..00000000
--- a/msdos/pkt_rx1.s
+++ /dev/null
@@ -1,155 +0,0 @@
-;
-; This file requires NASM 0.97+ to assemble
-;
-; Currently used only for djgpp + DOS4GW targets
-;
-; these sizes MUST be equal to the sizes in PKTDRVR.H
-;
-%define ETH_MTU 1500 ; max data size on Ethernet
-%define ETH_MIN 60 ; min/max total frame size
-%define ETH_MAX (ETH_MTU+2*6+2) ; =1514
-%define NUM_RX_BUF 32 ; # of RX element buffers
-%define RX_SIZE (ETH_MAX+6) ; sizeof(RX_ELEMENT) = 1514+6
-%idefine offset
-
-struc RX_ELEMENT
- .firstCount resw 1 ; # of bytes on 1st call
- .secondCount resw 1 ; # of bytes on 2nd call
- .handle resw 1 ; handle for upcall
- ; .timeStamp resw 4 ; 64-bit RDTSC value
- .destinAdr resb 6 ; packet destination address
- .sourceAdr resb 6 ; packet source address
- .protocol resw 1 ; packet protocol number
- .rxBuffer resb ETH_MTU ; RX buffer
-endstruc
-
-;-------------------------------------------
-
-[org 0] ; assemble to .bin file
-
-_rxOutOfs dw offset _pktRxBuf ; ring buffer offsets
-_rxInOfs dw offset _pktRxBuf ; into _pktRxBuf
-_pktDrop dw 0,0 ; packet drop counter
-_pktTemp resb 20 ; temp work area
-_pktTxBuf resb (ETH_MAX) ; TX buffer
-_pktRxBuf resb (RX_SIZE*NUM_RX_BUF) ; RX structures
- LAST_OFS equ $
-
-screenSeg dw 0B800h
-newInOffset dw 0
-
-fanChars db '-\|/'
-fanIndex dw 0
-
-%macro SHOW_RX 0
- push es
- push bx
- mov bx, [screenSeg]
- mov es, bx ;; r-mode segment of colour screen
- mov di, 158 ;; upper right corner - 1
- mov bx, [fanIndex]
- mov al, [fanChars+bx] ;; get write char
- mov ah, 15 ;; and white colour
- cld ;; Needed?
- stosw ;; write to screen at ES:EDI
- inc word [fanIndex] ;; update next index
- and word [fanIndex], 3
- pop bx
- pop es
-%endmacro
-
-;PutTimeStamp
-; rdtsc
-; mov [si].timeStamp, eax
-; mov [si+4].timeStamp, edx
-; ret
-
-
-;------------------------------------------------------------------------
-;
-; This routine gets called by the packet driver twice:
-; 1st time (AX=0) it requests an address where to put the packet
-;
-; 2nd time (AX=1) the packet has been copied to this location (DS:SI)
-; BX has client handle (stored in RX_ELEMENT.handle).
-; CX has # of bytes in packet on both call. They should be equal.
-; A test for equality is done by putting CX in _pktRxBuf [n].firstCount
-; and _pktRxBuf[n].secondCount, and CL on first call in
-; _pktRxBuf[n].rxBuffer[CX]. These values are checked in "PktReceive"
-; (PKTDRVR.C)
-;
-;---------------------------------------------------------------------
-
-_PktReceiver:
- pushf
- cli ; no distraction wanted !
- push ds
- push bx
- mov bx, cs
- mov ds, bx
- mov es, bx ; ES = DS = CS or seg _DATA
- pop bx ; restore handle
-
- cmp ax, 0 ; first call? (AX=0)
- jne @post ; AX=1: second call, do post process
-
-%ifdef DEBUG
- SHOW_RX ; show that a packet is received
-%endif
-
- cmp cx, ETH_MAX ; size OK ?
- ja @skip ; no, too big
-
- mov ax, [_rxInOfs]
- add ax, RX_SIZE
- cmp ax, LAST_OFS
- jb @noWrap
- mov ax, offset _pktRxBuf
-@noWrap:
- cmp ax, [_rxOutOfs]
- je @dump
- mov di, [_rxInOfs] ; ES:DI -> _pktRxBuf[n]
- mov [newInOffset], ax
-
- mov [di], cx ; remember firstCount.
- mov [di+4], bx ; remember handle.
- add di, 6 ; ES:DI -> _pktRxBuf[n].destinAdr
- pop ds
- popf
- retf ; far return to driver with ES:DI
-
-@dump: add word [_pktDrop+0], 1 ; discard the packet on 1st call
- adc word [_pktDrop+2], 0 ; increment packets lost
-
-@skip: xor di, di ; return ES:DI = NIL pointer
- xor ax, ax
- mov es, ax
- pop ds
- popf
- retf
-
-@post: or si, si ; DS:SI->_pktRxBuf[n][n].destinAdr
- jz @discard ; make sure we don't use NULL-pointer
-
- ;
- ; push si
- ; call bpf_filter_match ; run the filter here some day
- ; pop si
- ; cmp ax, 0
- ; je @discard
-
- mov [si-6+2], cx ; store _pktRxBuf[n].secondCount
- mov ax, [newInOffset]
- mov [_rxInOfs], ax ; update _pktRxBuf input offset
-
- ; call PutTimeStamp
-
-@discard:
- pop ds
- popf
- retf
-
-_pktRxEnd db 0 ; marker for end of r-mode code/data
-
-END
-
diff --git a/msdos/pktdrvr.c b/msdos/pktdrvr.c
deleted file mode 100644
index 8ee5f920..00000000
--- a/msdos/pktdrvr.c
+++ /dev/null
@@ -1,1436 +0,0 @@
-/*
- * File.........: pktdrvr.c
- *
- * Responsible..: Gisle Vanem, giva@bgnett.no
- *
- * Created......: 26.Sept 1995
- *
- * Description..: Packet-driver interface for 16/32-bit C :
- * Borland C/C++ 3.0+ small/large model
- * Watcom C/C++ 11+, DOS4GW flat model
- * Metaware HighC 3.1+ and PharLap 386|DosX
- * GNU C/C++ 2.7+ and djgpp 2.x extender
- *
- * References...: PC/TCP Packet driver Specification. rev 1.09
- * FTP Software Inc.
- *
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <dos.h>
-
-#include "pcap-dos.h"
-#include "pcap-int.h"
-#include "msdos/pktdrvr.h"
-
-#if (DOSX)
-#define NUM_RX_BUF 32 /* # of buffers in Rx FIFO queue */
-#else
-#define NUM_RX_BUF 10
-#endif
-
-#define DIM(x) (sizeof((x)) / sizeof(x[0]))
-#define PUTS(s) do { \
- if (!pktInfo.quiet) \
- pktInfo.error ? \
- printf ("%s: %s\n", s, pktInfo.error) : \
- printf ("%s\n", pktInfo.error = s); \
- } while (0)
-
-#if defined(__HIGHC__)
- extern UINT _mwenv;
-
-#elif defined(__DJGPP__)
- #include <stddef.h>
- #include <dpmi.h>
- #include <go32.h>
- #include <pc.h>
- #include <sys/farptr.h>
-
-#elif defined(__WATCOMC__)
- #include <i86.h>
- #include <stddef.h>
- extern char _Extender;
-
-#else
- extern void far PktReceiver (void);
-#endif
-
-
-#if (DOSX & (DJGPP|DOS4GW))
- #include <sys/pack_on.h>
-
- struct DPMI_regs {
- DWORD r_di;
- DWORD r_si;
- DWORD r_bp;
- DWORD reserved;
- DWORD r_bx;
- DWORD r_dx;
- DWORD r_cx;
- DWORD r_ax;
- WORD r_flags;
- WORD r_es, r_ds, r_fs, r_gs;
- WORD r_ip, r_cs, r_sp, r_ss;
- };
-
- /* Data located in a real-mode segment. This becomes far at runtime
- */
- typedef struct { /* must match data/code in pkt_rx1.s */
- WORD _rxOutOfs;
- WORD _rxInOfs;
- DWORD _pktDrop;
- BYTE _pktTemp [20];
- TX_ELEMENT _pktTxBuf[1];
- RX_ELEMENT _pktRxBuf[NUM_RX_BUF];
- WORD _dummy[2]; /* screenSeg,newInOffset */
- BYTE _fanChars[4];
- WORD _fanIndex;
- BYTE _PktReceiver[15]; /* starts on a paragraph (16byte) */
- } PktRealStub;
- #include <sys/pack_off.h>
-
- static BYTE real_stub_array [] = {
- #include "pkt_stub.inc" /* generated opcode array */
- };
-
- #define rxOutOfs offsetof (PktRealStub,_rxOutOfs)
- #define rxInOfs offsetof (PktRealStub,_rxInOfs)
- #define PktReceiver offsetof (PktRealStub,_PktReceiver [para_skip])
- #define pktDrop offsetof (PktRealStub,_pktDrop)
- #define pktTemp offsetof (PktRealStub,_pktTemp)
- #define pktTxBuf offsetof (PktRealStub,_pktTxBuf)
- #define FIRST_RX_BUF offsetof (PktRealStub,_pktRxBuf [0])
- #define LAST_RX_BUF offsetof (PktRealStub,_pktRxBuf [NUM_RX_BUF-1])
-
-#else
- extern WORD rxOutOfs; /* offsets into pktRxBuf FIFO queue */
- extern WORD rxInOfs;
- extern DWORD pktDrop; /* # packets dropped in PktReceiver() */
- extern BYTE pktRxEnd; /* marks the end of r-mode code/data */
-
- extern RX_ELEMENT pktRxBuf [NUM_RX_BUF]; /* PktDrvr Rx buffers */
- extern TX_ELEMENT pktTxBuf; /* PktDrvr Tx buffer */
- extern char pktTemp[20]; /* PktDrvr temp area */
-
- #define FIRST_RX_BUF (WORD) &pktRxBuf [0]
- #define LAST_RX_BUF (WORD) &pktRxBuf [NUM_RX_BUF-1]
-#endif
-
-
-#ifdef __BORLANDC__ /* Use Borland's inline functions */
- #define memcpy __memcpy__
- #define memcmp __memcmp__
- #define memset __memset__
-#endif
-
-
-#if (DOSX & PHARLAP)
- extern void PktReceiver (void); /* in pkt_rx0.asm */
- static int RealCopy (ULONG, ULONG, REALPTR*, FARPTR*, USHORT*);
-
- #undef FP_SEG
- #undef FP_OFF
- #define FP_OFF(x) ((WORD)(x))
- #define FP_SEG(x) ((WORD)(realBase >> 16))
- #define DOS_ADDR(s,o) (((DWORD)(s) << 16) + (WORD)(o))
- #define r_ax eax
- #define r_bx ebx
- #define r_dx edx
- #define r_cx ecx
- #define r_si esi
- #define r_di edi
- #define r_ds ds
- #define r_es es
- LOCAL FARPTR protBase;
- LOCAL REALPTR realBase;
- LOCAL WORD realSeg; /* DOS para-address of allocated area */
- LOCAL SWI_REGS reg;
-
- static WORD _far *rxOutOfsFp, *rxInOfsFp;
-
-#elif (DOSX & DJGPP)
- static _go32_dpmi_seginfo rm_mem;
- static __dpmi_regs reg;
- static DWORD realBase;
- static int para_skip = 0;
-
- #define DOS_ADDR(s,o) (((WORD)(s) << 4) + (o))
- #define r_ax x.ax
- #define r_bx x.bx
- #define r_dx x.dx
- #define r_cx x.cx
- #define r_si x.si
- #define r_di x.di
- #define r_ds x.ds
- #define r_es x.es
-
-#elif (DOSX & DOS4GW)
- LOCAL struct DPMI_regs reg;
- LOCAL WORD rm_base_seg, rm_base_sel;
- LOCAL DWORD realBase;
- LOCAL int para_skip = 0;
-
- LOCAL DWORD dpmi_get_real_vector (int intr);
- LOCAL WORD dpmi_real_malloc (int size, WORD *selector);
- LOCAL void dpmi_real_free (WORD selector);
- #define DOS_ADDR(s,o) (((DWORD)(s) << 4) + (WORD)(o))
-
-#else /* real-mode Borland etc. */
- static struct {
- WORD r_ax, r_bx, r_cx, r_dx, r_bp;
- WORD r_si, r_di, r_ds, r_es, r_flags;
- } reg;
-#endif
-
-#ifdef __HIGHC__
- #pragma Alias (pktDrop, "_pktDrop")
- #pragma Alias (pktRxBuf, "_pktRxBuf")
- #pragma Alias (pktTxBuf, "_pktTxBuf")
- #pragma Alias (pktTemp, "_pktTemp")
- #pragma Alias (rxOutOfs, "_rxOutOfs")
- #pragma Alias (rxInOfs, "_rxInOfs")
- #pragma Alias (pktRxEnd, "_pktRxEnd")
- #pragma Alias (PktReceiver,"_PktReceiver")
-#endif
-
-
-PUBLIC PKT_STAT pktStat; /* statistics for packets */
-PUBLIC PKT_INFO pktInfo; /* packet-driver information */
-
-PUBLIC PKT_RX_MODE receiveMode = PDRX_DIRECT;
-PUBLIC ETHER myAddress = { 0, 0, 0, 0, 0, 0 };
-PUBLIC ETHER ethBroadcast = { 255,255,255,255,255,255 };
-
-LOCAL struct { /* internal statistics */
- DWORD tooSmall; /* size < ETH_MIN */
- DWORD tooLarge; /* size > ETH_MAX */
- DWORD badSync; /* count_1 != count_2 */
- DWORD wrongHandle; /* upcall to wrong handle */
- } intStat;
-
-/***************************************************************************/
-
-PUBLIC const char *PktGetErrorStr (int errNum)
-{
- static const char *errStr[] = {
- "",
- "Invalid handle number",
- "No interfaces of specified class found",
- "No interfaces of specified type found",
- "No interfaces of specified number found",
- "Bad packet type specified",
- "Interface does not support multicast",
- "Packet driver cannot terminate",
- "Invalid receiver mode specified",
- "Insufficient memory space",
- "Type previously accessed, and not released",
- "Command out of range, or not implemented",
- "Cannot send packet (usually hardware error)",
- "Cannot change hardware address ( > 1 handle open)",
- "Hardware address has bad length or format",
- "Cannot reset interface (more than 1 handle open)",
- "Bad Check-sum",
- "Bad size",
- "Bad sync" ,
- "Source hit"
- };
-
- if (errNum < 0 || errNum >= DIM(errStr))
- return ("Unknown driver error.");
- return (errStr [errNum]);
-}
-
-/**************************************************************************/
-
-PUBLIC const char *PktGetClassName (WORD class)
-{
- switch (class)
- {
- case PD_ETHER:
- return ("DIX-Ether");
- case PD_PRONET10:
- return ("ProNET-10");
- case PD_IEEE8025:
- return ("IEEE 802.5");
- case PD_OMNINET:
- return ("OmniNet");
- case PD_APPLETALK:
- return ("AppleTalk");
- case PD_SLIP:
- return ("SLIP");
- case PD_STARTLAN:
- return ("StartLAN");
- case PD_ARCNET:
- return ("ArcNet");
- case PD_AX25:
- return ("AX.25");
- case PD_KISS:
- return ("KISS");
- case PD_IEEE8023_2:
- return ("IEEE 802.3 w/802.2 hdr");
- case PD_FDDI8022:
- return ("FDDI w/802.2 hdr");
- case PD_X25:
- return ("X.25");
- case PD_LANstar:
- return ("LANstar");
- case PD_PPP:
- return ("PPP");
- default:
- return ("unknown");
- }
-}
-
-/**************************************************************************/
-
-PUBLIC char const *PktRXmodeStr (PKT_RX_MODE mode)
-{
- static const char *modeStr [] = {
- "Receiver turned off",
- "Receive only directly addressed packets",
- "Receive direct & broadcast packets",
- "Receive direct,broadcast and limited multicast packets",
- "Receive direct,broadcast and all multicast packets",
- "Receive all packets (promiscuous mode)"
- };
-
- if (mode > DIM(modeStr))
- return ("??");
- return (modeStr [mode-1]);
-}
-
-/**************************************************************************/
-
-LOCAL __inline BOOL PktInterrupt (void)
-{
- BOOL okay;
-
-#if (DOSX & PHARLAP)
- _dx_real_int ((UINT)pktInfo.intr, &reg);
- okay = ((reg.flags & 1) == 0); /* OK if carry clear */
-
-#elif (DOSX & DJGPP)
- __dpmi_int ((int)pktInfo.intr, &reg);
- okay = ((reg.x.flags & 1) == 0);
-
-#elif (DOSX & DOS4GW)
- union REGS r;
- struct SREGS s;
-
- memset (&r, 0, sizeof(r));
- segread (&s);
- r.w.ax = 0x300;
- r.x.ebx = pktInfo.intr;
- r.w.cx = 0;
- s.es = FP_SEG (&reg);
- r.x.edi = FP_OFF (&reg);
- reg.r_flags = 0;
- reg.r_ss = reg.r_sp = 0; /* DPMI host provides stack */
-
- int386x (0x31, &r, &r, &s);
- okay = (!r.w.cflag);
-
-#else
- reg.r_flags = 0;
- intr (pktInfo.intr, (struct REGPACK*)&reg);
- okay = ((reg.r_flags & 1) == 0);
-#endif
-
- if (okay)
- pktInfo.error = NULL;
- else pktInfo.error = PktGetErrorStr (reg.r_dx >> 8);
- return (okay);
-}
-
-/**************************************************************************/
-
-/*
- * Search for packet driver at interrupt 60h through 80h. If ASCIIZ
- * string "PKT DRVR" found at offset 3 in the interrupt handler, return
- * interrupt number, else return zero in pktInfo.intr
- */
-PUBLIC BOOL PktSearchDriver (void)
-{
- BYTE intr = 0x20;
- BOOL found = FALSE;
-
- while (!found && intr < 0xFF)
- {
- static char str[12]; /* 3 + strlen("PKT DRVR") */
- static char pktStr[9] = "PKT DRVR"; /* ASCIIZ string at ofs 3 */
- DWORD rp; /* in interrupt routine */
-
-#if (DOSX & PHARLAP)
- _dx_rmiv_get (intr, &rp);
- ReadRealMem (&str, (REALPTR)rp, sizeof(str));
-
-#elif (DOSX & DJGPP)
- __dpmi_raddr realAdr;
- __dpmi_get_real_mode_interrupt_vector (intr, &realAdr);
- rp = (realAdr.segment << 4) + realAdr.offset16;
- dosmemget (rp, sizeof(str), &str);
-
-#elif (DOSX & DOS4GW)
- rp = dpmi_get_real_vector (intr);
- memcpy (&str, (void*)rp, sizeof(str));
-
-#else
- _fmemcpy (&str, getvect(intr), sizeof(str));
-#endif
-
- found = memcmp (&str[3],&pktStr,sizeof(pktStr)) == 0;
- intr++;
- }
- pktInfo.intr = (found ? intr-1 : 0);
- return (found);
-}
-
-
-/**************************************************************************/
-
-static BOOL PktSetAccess (void)
-{
- reg.r_ax = 0x0200 + pktInfo.class;
- reg.r_bx = 0xFFFF;
- reg.r_dx = 0;
- reg.r_cx = 0;
-
-#if (DOSX & PHARLAP)
- reg.ds = 0;
- reg.esi = 0;
- reg.es = RP_SEG (realBase);
- reg.edi = (WORD) &PktReceiver;
-
-#elif (DOSX & DJGPP)
- reg.x.ds = 0;
- reg.x.si = 0;
- reg.x.es = rm_mem.rm_segment;
- reg.x.di = PktReceiver;
-
-#elif (DOSX & DOS4GW)
- reg.r_ds = 0;
- reg.r_si = 0;
- reg.r_es = rm_base_seg;
- reg.r_di = PktReceiver;
-
-#else
- reg.r_ds = 0;
- reg.r_si = 0;
- reg.r_es = FP_SEG (&PktReceiver);
- reg.r_di = FP_OFF (&PktReceiver);
-#endif
-
- if (!PktInterrupt())
- return (FALSE);
-
- pktInfo.handle = reg.r_ax;
- return (TRUE);
-}
-
-/**************************************************************************/
-
-PUBLIC BOOL PktReleaseHandle (WORD handle)
-{
- reg.r_ax = 0x0300;
- reg.r_bx = handle;
- return PktInterrupt();
-}
-
-/**************************************************************************/
-
-PUBLIC BOOL PktTransmit (const void *eth, int len)
-{
- if (len > ETH_MTU)
- return (FALSE);
-
- reg.r_ax = 0x0400; /* Function 4, send pkt */
- reg.r_cx = len; /* total size of frame */
-
-#if (DOSX & DJGPP)
- dosmemput (eth, len, realBase+pktTxBuf);
- reg.x.ds = rm_mem.rm_segment; /* DOS data segment and */
- reg.x.si = pktTxBuf; /* DOS offset to buffer */
-
-#elif (DOSX & DOS4GW)
- memcpy ((void*)(realBase+pktTxBuf), eth, len);
- reg.r_ds = rm_base_seg;
- reg.r_si = pktTxBuf;
-
-#elif (DOSX & PHARLAP)
- memcpy (&pktTxBuf, eth, len);
- reg.r_ds = FP_SEG (&pktTxBuf);
- reg.r_si = FP_OFF (&pktTxBuf);
-
-#else
- reg.r_ds = FP_SEG (eth);
- reg.r_si = FP_OFF (eth);
-#endif
-
- return PktInterrupt();
-}
-
-/**************************************************************************/
-
-#if (DOSX & (DJGPP|DOS4GW))
-LOCAL __inline BOOL CheckElement (RX_ELEMENT *rx)
-#else
-LOCAL __inline BOOL CheckElement (RX_ELEMENT _far *rx)
-#endif
-{
- WORD count_1, count_2;
-
- /*
- * We got an upcall to the same RMCB with wrong handle.
- * This can happen if we failed to release handle at program exit
- */
- if (rx->handle != pktInfo.handle)
- {
- pktInfo.error = "Wrong handle";
- intStat.wrongHandle++;
- PktReleaseHandle (rx->handle);
- return (FALSE);
- }
- count_1 = rx->firstCount;
- count_2 = rx->secondCount;
-
- if (count_1 != count_2)
- {
- pktInfo.error = "Bad sync";
- intStat.badSync++;
- return (FALSE);
- }
- if (count_1 > ETH_MAX)
- {
- pktInfo.error = "Large esize";
- intStat.tooLarge++;
- return (FALSE);
- }
-#if 0
- if (count_1 < ETH_MIN)
- {
- pktInfo.error = "Small esize";
- intStat.tooSmall++;
- return (FALSE);
- }
-#endif
- return (TRUE);
-}
-
-/**************************************************************************/
-
-PUBLIC BOOL PktTerminHandle (WORD handle)
-{
- reg.r_ax = 0x0500;
- reg.r_bx = handle;
- return PktInterrupt();
-}
-
-/**************************************************************************/
-
-PUBLIC BOOL PktResetInterface (WORD handle)
-{
- reg.r_ax = 0x0700;
- reg.r_bx = handle;
- return PktInterrupt();
-}
-
-/**************************************************************************/
-
-PUBLIC BOOL PktSetReceiverMode (PKT_RX_MODE mode)
-{
- if (pktInfo.class == PD_SLIP || pktInfo.class == PD_PPP)
- return (TRUE);
-
- reg.r_ax = 0x1400;
- reg.r_bx = pktInfo.handle;
- reg.r_cx = (WORD)mode;
-
- if (!PktInterrupt())
- return (FALSE);
-
- receiveMode = mode;
- return (TRUE);
-}
-
-/**************************************************************************/
-
-PUBLIC BOOL PktGetReceiverMode (PKT_RX_MODE *mode)
-{
- reg.r_ax = 0x1500;
- reg.r_bx = pktInfo.handle;
-
- if (!PktInterrupt())
- return (FALSE);
-
- *mode = reg.r_ax;
- return (TRUE);
-}
-
-/**************************************************************************/
-
-static PKT_STAT initialStat; /* statistics at startup */
-static BOOL resetStat = FALSE; /* statistics reset ? */
-
-PUBLIC BOOL PktGetStatistics (WORD handle)
-{
- reg.r_ax = 0x1800;
- reg.r_bx = handle;
-
- if (!PktInterrupt())
- return (FALSE);
-
-#if (DOSX & PHARLAP)
- ReadRealMem (&pktStat, DOS_ADDR(reg.ds,reg.esi), sizeof(pktStat));
-
-#elif (DOSX & DJGPP)
- dosmemget (DOS_ADDR(reg.x.ds,reg.x.si), sizeof(pktStat), &pktStat);
-
-#elif (DOSX & DOS4GW)
- memcpy (&pktStat, (void*)DOS_ADDR(reg.r_ds,reg.r_si), sizeof(pktStat));
-
-#else
- _fmemcpy (&pktStat, MK_FP(reg.r_ds,reg.r_si), sizeof(pktStat));
-#endif
-
- return (TRUE);
-}
-
-/**************************************************************************/
-
-PUBLIC BOOL PktSessStatistics (WORD handle)
-{
- if (!PktGetStatistics(pktInfo.handle))
- return (FALSE);
-
- if (resetStat)
- {
- pktStat.inPackets -= initialStat.inPackets;
- pktStat.outPackets -= initialStat.outPackets;
- pktStat.inBytes -= initialStat.inBytes;
- pktStat.outBytes -= initialStat.outBytes;
- pktStat.inErrors -= initialStat.inErrors;
- pktStat.outErrors -= initialStat.outErrors;
- pktStat.outErrors -= initialStat.outErrors;
- pktStat.lost -= initialStat.lost;
- }
- return (TRUE);
-}
-
-/**************************************************************************/
-
-PUBLIC BOOL PktResetStatistics (WORD handle)
-{
- if (!PktGetStatistics(pktInfo.handle))
- return (FALSE);
-
- memcpy (&initialStat, &pktStat, sizeof(initialStat));
- resetStat = TRUE;
- return (TRUE);
-}
-
-/**************************************************************************/
-
-PUBLIC BOOL PktGetAddress (ETHER *addr)
-{
- reg.r_ax = 0x0600;
- reg.r_bx = pktInfo.handle;
- reg.r_cx = sizeof (*addr);
-
-#if (DOSX & DJGPP)
- reg.x.es = rm_mem.rm_segment;
- reg.x.di = pktTemp;
-#elif (DOSX & DOS4GW)
- reg.r_es = rm_base_seg;
- reg.r_di = pktTemp;
-#else
- reg.r_es = FP_SEG (&pktTemp);
- reg.r_di = FP_OFF (&pktTemp); /* ES:DI = address for result */
-#endif
-
- if (!PktInterrupt())
- return (FALSE);
-
-#if (DOSX & PHARLAP)
- ReadRealMem (addr, realBase + (WORD)&pktTemp, sizeof(*addr));
-
-#elif (DOSX & DJGPP)
- dosmemget (realBase+pktTemp, sizeof(*addr), addr);
-
-#elif (DOSX & DOS4GW)
- memcpy (addr, (void*)(realBase+pktTemp), sizeof(*addr));
-
-#else
- memcpy ((void*)addr, &pktTemp, sizeof(*addr));
-#endif
-
- return (TRUE);
-}
-
-/**************************************************************************/
-
-PUBLIC BOOL PktSetAddress (const ETHER *addr)
-{
- /* copy addr to real-mode scrath area */
-
-#if (DOSX & PHARLAP)
- WriteRealMem (realBase + (WORD)&pktTemp, (void*)addr, sizeof(*addr));
-
-#elif (DOSX & DJGPP)
- dosmemput (addr, sizeof(*addr), realBase+pktTemp);
-
-#elif (DOSX & DOS4GW)
- memcpy ((void*)(realBase+pktTemp), addr, sizeof(*addr));
-
-#else
- memcpy (&pktTemp, (void*)addr, sizeof(*addr));
-#endif
-
- reg.r_ax = 0x1900;
- reg.r_cx = sizeof (*addr); /* address length */
-
-#if (DOSX & DJGPP)
- reg.x.es = rm_mem.rm_segment; /* DOS offset to param */
- reg.x.di = pktTemp; /* DOS segment to param */
-#elif (DOSX & DOS4GW)
- reg.r_es = rm_base_seg;
- reg.r_di = pktTemp;
-#else
- reg.r_es = FP_SEG (&pktTemp);
- reg.r_di = FP_OFF (&pktTemp);
-#endif
-
- return PktInterrupt();
-}
-
-/**************************************************************************/
-
-PUBLIC BOOL PktGetDriverInfo (void)
-{
- pktInfo.majVer = 0;
- pktInfo.minVer = 0;
- memset (&pktInfo.name, 0, sizeof(pktInfo.name));
- reg.r_ax = 0x01FF;
- reg.r_bx = 0;
-
- if (!PktInterrupt())
- return (FALSE);
-
- pktInfo.number = reg.r_cx & 0xFF;
- pktInfo.class = reg.r_cx >> 8;
-#if 0
- pktInfo.minVer = reg.r_bx % 10;
- pktInfo.majVer = reg.r_bx / 10;
-#else
- pktInfo.majVer = reg.r_bx; // !!
-#endif
- pktInfo.funcs = reg.r_ax & 0xFF;
- pktInfo.type = reg.r_dx & 0xFF;
-
-#if (DOSX & PHARLAP)
- ReadRealMem (&pktInfo.name, DOS_ADDR(reg.ds,reg.esi), sizeof(pktInfo.name));
-
-#elif (DOSX & DJGPP)
- dosmemget (DOS_ADDR(reg.x.ds,reg.x.si), sizeof(pktInfo.name), &pktInfo.name);
-
-#elif (DOSX & DOS4GW)
- memcpy (&pktInfo.name, (void*)DOS_ADDR(reg.r_ds,reg.r_si), sizeof(pktInfo.name));
-
-#else
- _fmemcpy (&pktInfo.name, MK_FP(reg.r_ds,reg.r_si), sizeof(pktInfo.name));
-#endif
- return (TRUE);
-}
-
-/**************************************************************************/
-
-PUBLIC BOOL PktGetDriverParam (void)
-{
- reg.r_ax = 0x0A00;
-
- if (!PktInterrupt())
- return (FALSE);
-
-#if (DOSX & PHARLAP)
- ReadRealMem (&pktInfo.majVer, DOS_ADDR(reg.es,reg.edi), PKT_PARAM_SIZE);
-
-#elif (DOSX & DJGPP)
- dosmemget (DOS_ADDR(reg.x.es,reg.x.di), PKT_PARAM_SIZE, &pktInfo.majVer);
-
-#elif (DOSX & DOS4GW)
- memcpy (&pktInfo.majVer, (void*)DOS_ADDR(reg.r_es,reg.r_di), PKT_PARAM_SIZE);
-
-#else
- _fmemcpy (&pktInfo.majVer, MK_FP(reg.r_es,reg.r_di), PKT_PARAM_SIZE);
-#endif
- return (TRUE);
-}
-
-/**************************************************************************/
-
-#if (DOSX & PHARLAP)
- PUBLIC int PktReceive (BYTE *buf, int max)
- {
- WORD inOfs = *rxInOfsFp;
- WORD outOfs = *rxOutOfsFp;
-
- if (outOfs != inOfs)
- {
- RX_ELEMENT _far *head = (RX_ELEMENT _far*)(protBase+outOfs);
- int size, len = max;
-
- if (CheckElement(head))
- {
- size = min (head->firstCount, sizeof(RX_ELEMENT));
- len = min (size, max);
- _fmemcpy (buf, &head->destin, len);
- }
- else
- size = -1;
-
- outOfs += sizeof (RX_ELEMENT);
- if (outOfs > LAST_RX_BUF)
- outOfs = FIRST_RX_BUF;
- *rxOutOfsFp = outOfs;
- return (size);
- }
- return (0);
- }
-
- PUBLIC void PktQueueBusy (BOOL busy)
- {
- *rxOutOfsFp = busy ? (*rxInOfsFp + sizeof(RX_ELEMENT)) : *rxInOfsFp;
- if (*rxOutOfsFp > LAST_RX_BUF)
- *rxOutOfsFp = FIRST_RX_BUF;
- *(DWORD _far*)(protBase + (WORD)&pktDrop) = 0;
- }
-
- PUBLIC WORD PktBuffersUsed (void)
- {
- WORD inOfs = *rxInOfsFp;
- WORD outOfs = *rxOutOfsFp;
-
- if (inOfs >= outOfs)
- return (inOfs - outOfs) / sizeof(RX_ELEMENT);
- return (NUM_RX_BUF - (outOfs - inOfs) / sizeof(RX_ELEMENT));
- }
-
- PUBLIC DWORD PktRxDropped (void)
- {
- return (*(DWORD _far*)(protBase + (WORD)&pktDrop));
- }
-
-#elif (DOSX & DJGPP)
- PUBLIC int PktReceive (BYTE *buf, int max)
- {
- WORD ofs = _farpeekw (_dos_ds, realBase+rxOutOfs);
-
- if (ofs != _farpeekw (_dos_ds, realBase+rxInOfs))
- {
- RX_ELEMENT head;
- int size, len = max;
-
- head.firstCount = _farpeekw (_dos_ds, realBase+ofs);
- head.secondCount = _farpeekw (_dos_ds, realBase+ofs+2);
- head.handle = _farpeekw (_dos_ds, realBase+ofs+4);
-
- if (CheckElement(&head))
- {
- size = min (head.firstCount, sizeof(RX_ELEMENT));
- len = min (size, max);
- dosmemget (realBase+ofs+6, len, buf);
- }
- else
- size = -1;
-
- ofs += sizeof (RX_ELEMENT);
- if (ofs > LAST_RX_BUF)
- _farpokew (_dos_ds, realBase+rxOutOfs, FIRST_RX_BUF);
- else _farpokew (_dos_ds, realBase+rxOutOfs, ofs);
- return (size);
- }
- return (0);
- }
-
- PUBLIC void PktQueueBusy (BOOL busy)
- {
- WORD ofs;
-
- disable();
- ofs = _farpeekw (_dos_ds, realBase+rxInOfs);
- if (busy)
- ofs += sizeof (RX_ELEMENT);
-
- if (ofs > LAST_RX_BUF)
- _farpokew (_dos_ds, realBase+rxOutOfs, FIRST_RX_BUF);
- else _farpokew (_dos_ds, realBase+rxOutOfs, ofs);
- _farpokel (_dos_ds, realBase+pktDrop, 0UL);
- enable();
- }
-
- PUBLIC WORD PktBuffersUsed (void)
- {
- WORD inOfs, outOfs;
-
- disable();
- inOfs = _farpeekw (_dos_ds, realBase+rxInOfs);
- outOfs = _farpeekw (_dos_ds, realBase+rxOutOfs);
- enable();
- if (inOfs >= outOfs)
- return (inOfs - outOfs) / sizeof(RX_ELEMENT);
- return (NUM_RX_BUF - (outOfs - inOfs) / sizeof(RX_ELEMENT));
- }
-
- PUBLIC DWORD PktRxDropped (void)
- {
- return _farpeekl (_dos_ds, realBase+pktDrop);
- }
-
-#elif (DOSX & DOS4GW)
- PUBLIC int PktReceive (BYTE *buf, int max)
- {
- WORD ofs = *(WORD*) (realBase+rxOutOfs);
-
- if (ofs != *(WORD*) (realBase+rxInOfs))
- {
- RX_ELEMENT head;
- int size, len = max;
-
- head.firstCount = *(WORD*) (realBase+ofs);
- head.secondCount = *(WORD*) (realBase+ofs+2);
- head.handle = *(WORD*) (realBase+ofs+4);
-
- if (CheckElement(&head))
- {
- size = min (head.firstCount, sizeof(RX_ELEMENT));
- len = min (size, max);
- memcpy (buf, (const void*)(realBase+ofs+6), len);
- }
- else
- size = -1;
-
- ofs += sizeof (RX_ELEMENT);
- if (ofs > LAST_RX_BUF)
- *(WORD*) (realBase+rxOutOfs) = FIRST_RX_BUF;
- else *(WORD*) (realBase+rxOutOfs) = ofs;
- return (size);
- }
- return (0);
- }
-
- PUBLIC void PktQueueBusy (BOOL busy)
- {
- WORD ofs;
-
- _disable();
- ofs = *(WORD*) (realBase+rxInOfs);
- if (busy)
- ofs += sizeof (RX_ELEMENT);
-
- if (ofs > LAST_RX_BUF)
- *(WORD*) (realBase+rxOutOfs) = FIRST_RX_BUF;
- else *(WORD*) (realBase+rxOutOfs) = ofs;
- *(DWORD*) (realBase+pktDrop) = 0UL;
- _enable();
- }
-
- PUBLIC WORD PktBuffersUsed (void)
- {
- WORD inOfs, outOfs;
-
- _disable();
- inOfs = *(WORD*) (realBase+rxInOfs);
- outOfs = *(WORD*) (realBase+rxOutOfs);
- _enable();
- if (inOfs >= outOfs)
- return (inOfs - outOfs) / sizeof(RX_ELEMENT);
- return (NUM_RX_BUF - (outOfs - inOfs) / sizeof(RX_ELEMENT));
- }
-
- PUBLIC DWORD PktRxDropped (void)
- {
- return *(DWORD*) (realBase+pktDrop);
- }
-
-#else /* real-mode small/large model */
-
- PUBLIC int PktReceive (BYTE *buf, int max)
- {
- if (rxOutOfs != rxInOfs)
- {
- RX_ELEMENT far *head = (RX_ELEMENT far*) MK_FP (_DS,rxOutOfs);
- int size, len = max;
-
- if (CheckElement(head))
- {
- size = min (head->firstCount, sizeof(RX_ELEMENT));
- len = min (size, max);
- _fmemcpy (buf, &head->destin, len);
- }
- else
- size = -1;
-
- rxOutOfs += sizeof (RX_ELEMENT);
- if (rxOutOfs > LAST_RX_BUF)
- rxOutOfs = FIRST_RX_BUF;
- return (size);
- }
- return (0);
- }
-
- PUBLIC void PktQueueBusy (BOOL busy)
- {
- rxOutOfs = busy ? (rxInOfs + sizeof(RX_ELEMENT)) : rxInOfs;
- if (rxOutOfs > LAST_RX_BUF)
- rxOutOfs = FIRST_RX_BUF;
- pktDrop = 0L;
- }
-
- PUBLIC WORD PktBuffersUsed (void)
- {
- WORD inOfs = rxInOfs;
- WORD outOfs = rxOutOfs;
-
- if (inOfs >= outOfs)
- return ((inOfs - outOfs) / sizeof(RX_ELEMENT));
- return (NUM_RX_BUF - (outOfs - inOfs) / sizeof(RX_ELEMENT));
- }
-
- PUBLIC DWORD PktRxDropped (void)
- {
- return (pktDrop);
- }
-#endif
-
-/**************************************************************************/
-
-LOCAL __inline void PktFreeMem (void)
-{
-#if (DOSX & PHARLAP)
- if (realSeg)
- {
- _dx_real_free (realSeg);
- realSeg = 0;
- }
-#elif (DOSX & DJGPP)
- if (rm_mem.rm_segment)
- {
- unsigned ofs; /* clear the DOS-mem to prevent further upcalls */
-
- for (ofs = 0; ofs < 16 * rm_mem.size / 4; ofs += 4)
- _farpokel (_dos_ds, realBase + ofs, 0);
- _go32_dpmi_free_dos_memory (&rm_mem);
- rm_mem.rm_segment = 0;
- }
-#elif (DOSX & DOS4GW)
- if (rm_base_sel)
- {
- dpmi_real_free (rm_base_sel);
- rm_base_sel = 0;
- }
-#endif
-}
-
-/**************************************************************************/
-
-PUBLIC BOOL PktExitDriver (void)
-{
- if (pktInfo.handle)
- {
- if (!PktSetReceiverMode(PDRX_BROADCAST))
- PUTS ("Error restoring receiver mode.");
-
- if (!PktReleaseHandle(pktInfo.handle))
- PUTS ("Error releasing PKT-DRVR handle.");
-
- PktFreeMem();
- pktInfo.handle = 0;
- }
-
- if (pcap_pkt_debug >= 1)
- printf ("Internal stats: too-small %lu, too-large %lu, bad-sync %lu, "
- "wrong-handle %lu\n",
- intStat.tooSmall, intStat.tooLarge,
- intStat.badSync, intStat.wrongHandle);
- return (TRUE);
-}
-
-#if (DOSX & (DJGPP|DOS4GW))
-static void dump_pkt_stub (void)
-{
- int i;
-
- fprintf (stderr, "PktReceiver %lu, pkt_stub[PktReceiver] =\n",
- PktReceiver);
- for (i = 0; i < 15; i++)
- fprintf (stderr, "%02X, ", real_stub_array[i+PktReceiver]);
- fputs ("\n", stderr);
-}
-#endif
-
-/*
- * Front end initialization routine
- */
-PUBLIC BOOL PktInitDriver (PKT_RX_MODE mode)
-{
- PKT_RX_MODE rxMode;
- BOOL writeInfo = (pcap_pkt_debug >= 3);
-
- pktInfo.quiet = (pcap_pkt_debug < 3);
-
-#if (DOSX & PHARLAP) && defined(__HIGHC__)
- if (_mwenv != 2)
- {
- fprintf (stderr, "Only Pharlap DOS extender supported.\n");
- return (FALSE);
- }
-#endif
-
-#if (DOSX & PHARLAP) && defined(__WATCOMC__)
- if (_Extender != 1)
- {
- fprintf (stderr, "Only DOS4GW style extenders supported.\n");
- return (FALSE);
- }
-#endif
-
- if (!PktSearchDriver())
- {
- PUTS ("Packet driver not found.");
- PktFreeMem();
- return (FALSE);
- }
-
- if (!PktGetDriverInfo())
- {
- PUTS ("Error getting pkt-drvr information.");
- PktFreeMem();
- return (FALSE);
- }
-
-#if (DOSX & PHARLAP)
- if (RealCopy((ULONG)&rxOutOfs, (ULONG)&pktRxEnd,
- &realBase, &protBase, (USHORT*)&realSeg))
- {
- rxOutOfsFp = (WORD _far *) (protBase + (WORD) &rxOutOfs);
- rxInOfsFp = (WORD _far *) (protBase + (WORD) &rxInOfs);
- *rxOutOfsFp = FIRST_RX_BUF;
- *rxInOfsFp = FIRST_RX_BUF;
- }
- else
- {
- PUTS ("Cannot allocate real-mode stub.");
- return (FALSE);
- }
-
-#elif (DOSX & (DJGPP|DOS4GW))
- if (sizeof(real_stub_array) > 0xFFFF)
- {
- fprintf (stderr, "`real_stub_array[]' too big.\n");
- return (FALSE);
- }
-#if (DOSX & DJGPP)
- rm_mem.size = (sizeof(real_stub_array) + 15) / 16;
-
- if (_go32_dpmi_allocate_dos_memory(&rm_mem) || rm_mem.rm_offset != 0)
- {
- PUTS ("real-mode init failed.");
- return (FALSE);
- }
- realBase = (rm_mem.rm_segment << 4);
- dosmemput (&real_stub_array, sizeof(real_stub_array), realBase);
- _farpokel (_dos_ds, realBase+rxOutOfs, FIRST_RX_BUF);
- _farpokel (_dos_ds, realBase+rxInOfs, FIRST_RX_BUF);
-
-#elif (DOSX & DOS4GW)
- rm_base_seg = dpmi_real_malloc (sizeof(real_stub_array), &rm_base_sel);
- if (!rm_base_seg)
- {
- PUTS ("real-mode init failed.");
- return (FALSE);
- }
- realBase = (rm_base_seg << 4);
- memcpy ((void*)realBase, &real_stub_array, sizeof(real_stub_array));
- *(WORD*) (realBase+rxOutOfs) = FIRST_RX_BUF;
- *(WORD*) (realBase+rxInOfs) = FIRST_RX_BUF;
-
-#endif
- {
- int pushf = PktReceiver;
-
- while (real_stub_array[pushf++] != 0x9C && /* pushf */
- real_stub_array[pushf] != 0xFA) /* cli */
- {
- if (++para_skip > 16)
- {
- fprintf (stderr, "Something wrong with `pkt_stub.inc'.\n");
- para_skip = 0;
- dump_pkt_stub();
- return (FALSE);
- }
- }
- if (*(WORD*)(real_stub_array + offsetof(PktRealStub,_dummy)) != 0xB800)
- {
- fprintf (stderr, "`real_stub_array[]' is misaligned.\n");
- return (FALSE);
- }
- }
-
- if (pcap_pkt_debug > 2)
- dump_pkt_stub();
-
-#else
- rxOutOfs = FIRST_RX_BUF;
- rxInOfs = FIRST_RX_BUF;
-#endif
-
- if (!PktSetAccess())
- {
- PUTS ("Error setting pkt-drvr access.");
- PktFreeMem();
- return (FALSE);
- }
-
- if (!PktGetAddress(&myAddress))
- {
- PUTS ("Error fetching adapter address.");
- PktFreeMem();
- return (FALSE);
- }
-
- if (!PktSetReceiverMode(mode))
- {
- PUTS ("Error setting receiver mode.");
- PktFreeMem();
- return (FALSE);
- }
-
- if (!PktGetReceiverMode(&rxMode))
- {
- PUTS ("Error getting receiver mode.");
- PktFreeMem();
- return (FALSE);
- }
-
- if (writeInfo)
- printf ("Pkt-driver information:\n"
- " Version : %d.%d\n"
- " Name : %.15s\n"
- " Class : %u (%s)\n"
- " Type : %u\n"
- " Number : %u\n"
- " Funcs : %u\n"
- " Intr : %Xh\n"
- " Handle : %u\n"
- " Extended : %s\n"
- " Hi-perf : %s\n"
- " RX mode : %s\n"
- " Eth-addr : %02X:%02X:%02X:%02X:%02X:%02X\n",
-
- pktInfo.majVer, pktInfo.minVer, pktInfo.name,
- pktInfo.class, PktGetClassName(pktInfo.class),
- pktInfo.type, pktInfo.number,
- pktInfo.funcs, pktInfo.intr, pktInfo.handle,
- pktInfo.funcs == 2 || pktInfo.funcs == 6 ? "Yes" : "No",
- pktInfo.funcs == 5 || pktInfo.funcs == 6 ? "Yes" : "No",
- PktRXmodeStr(rxMode),
- myAddress[0], myAddress[1], myAddress[2],
- myAddress[3], myAddress[4], myAddress[5]);
-
-#if defined(DEBUG) && (DOSX & PHARLAP)
- if (writeInfo)
- {
- DWORD rAdr = realBase + (WORD)&PktReceiver;
- unsigned sel, ofs;
-
- printf ("\nReceiver at %04X:%04X\n", RP_SEG(rAdr), RP_OFF(rAdr));
- printf ("Realbase = %04X:%04X\n", RP_SEG(realBase),RP_OFF(realBase));
-
- sel = _FP_SEG (protBase);
- ofs = _FP_OFF (protBase);
- printf ("Protbase = %04X:%08X\n", sel,ofs);
- printf ("RealSeg = %04X\n", realSeg);
-
- sel = _FP_SEG (rxOutOfsFp);
- ofs = _FP_OFF (rxOutOfsFp);
- printf ("rxOutOfsFp = %04X:%08X\n", sel,ofs);
-
- sel = _FP_SEG (rxInOfsFp);
- ofs = _FP_OFF (rxInOfsFp);
- printf ("rxInOfsFp = %04X:%08X\n", sel,ofs);
-
- printf ("Ready: *rxOutOfsFp = %04X *rxInOfsFp = %04X\n",
- *rxOutOfsFp, *rxInOfsFp);
-
- PktQueueBusy (TRUE);
- printf ("Busy: *rxOutOfsFp = %04X *rxInOfsFp = %04X\n",
- *rxOutOfsFp, *rxInOfsFp);
- }
-#endif
-
- memset (&pktStat, 0, sizeof(pktStat)); /* clear statistics */
- PktQueueBusy (TRUE);
- return (TRUE);
-}
-
-
-/*
- * DPMI functions only for Watcom + DOS4GW extenders
- */
-#if (DOSX & DOS4GW)
-LOCAL DWORD dpmi_get_real_vector (int intr)
-{
- union REGS r;
-
- r.x.eax = 0x200;
- r.x.ebx = (DWORD) intr;
- int386 (0x31, &r, &r);
- return ((r.w.cx << 4) + r.w.dx);
-}
-
-LOCAL WORD dpmi_real_malloc (int size, WORD *selector)
-{
- union REGS r;
-
- r.x.eax = 0x0100; /* DPMI allocate DOS memory */
- r.x.ebx = (size + 15) / 16; /* Number of paragraphs requested */
- int386 (0x31, &r, &r);
- if (r.w.cflag & 1)
- return (0);
-
- *selector = r.w.dx;
- return (r.w.ax); /* Return segment address */
-}
-
-LOCAL void dpmi_real_free (WORD selector)
-{
- union REGS r;
-
- r.x.eax = 0x101; /* DPMI free DOS memory */
- r.x.ebx = selector; /* Selector to free */
- int386 (0x31, &r, &r);
-}
-#endif
-
-
-#if defined(DOSX) && (DOSX & PHARLAP)
-/*
- * Description:
- * This routine allocates conventional memory for the specified block
- * of code (which must be within the first 64K of the protected mode
- * program segment) and copies the code to it.
- *
- * The caller should free up the conventional memory block when it
- * is done with the conventional memory.
- *
- * NOTE THIS ROUTINE REQUIRES 386|DOS-EXTENDER 3.0 OR LATER.
- *
- * Calling arguments:
- * start_offs start of real mode code in program segment
- * end_offs 1 byte past end of real mode code in program segment
- * real_basep returned; real mode ptr to use as a base for the
- * real mode code (eg, to get the real mode FAR
- * addr of a function foo(), take
- * real_basep + (ULONG) foo).
- * This pointer is constructed such that
- * offsets within the real mode segment are
- * the same as the link-time offsets in the
- * protected mode program segment
- * prot_basep returned; prot mode ptr to use as a base for getting
- * to the conventional memory, also constructed
- * so that adding the prot mode offset of a
- * function or variable to the base gets you a
- * ptr to the function or variable in the
- * conventional memory block.
- * rmem_adrp returned; real mode para addr of allocated
- * conventional memory block, to be used to free
- * up the conventional memory when done. DO NOT
- * USE THIS TO CONSTRUCT A REAL MODE PTR, USE
- * REAL_BASEP INSTEAD SO THAT OFFSETS WORK OUT
- * CORRECTLY.
- *
- * Returned values:
- * 0 if error
- * 1 if success
- */
-int RealCopy (ULONG start_offs,
- ULONG end_offs,
- REALPTR *real_basep,
- FARPTR *prot_basep,
- USHORT *rmem_adrp)
-{
- ULONG rm_base; /* base real mode para addr for accessing */
- /* allocated conventional memory */
- UCHAR *source; /* source pointer for copy */
- FARPTR destin; /* destination pointer for copy */
- ULONG len; /* number of bytes to copy */
- ULONG temp;
- USHORT stemp;
-
- /* First check for valid inputs
- */
- if (start_offs >= end_offs || end_offs > 0x10000)
- return (FALSE);
-
- /* Round start_offs down to a paragraph (16-byte) boundary so we can set up
- * the real mode pointer easily. Round up end_offs to make sure we allocate
- * enough paragraphs
- */
- start_offs &= ~15;
- end_offs = (15 + (end_offs << 4)) >> 4;
-
- /* Allocate the conventional memory for our real mode code. Remember to
- * round byte count UP to 16-byte paragraph size. We alloc it
- * above the DOS data buffer so both the DOS data buffer and the appl
- * conventional mem block can still be resized.
- *
- * First just try to alloc it; if we can't get it, shrink the appl mem
- * block down to the minimum, try to alloc the memory again, then grow the
- * appl mem block back to the maximum. (Don't try to shrink the DOS data
- * buffer to free conventional memory; it wouldn't be good for this routine
- * to have the possible side effect of making file I/O run slower.)
- */
- len = ((end_offs - start_offs) + 15) >> 4;
- if (_dx_real_above(len, rmem_adrp, &stemp) != _DOSE_NONE)
- {
- if (_dx_cmem_usage(0, 0, &temp, &temp) != _DOSE_NONE)
- return (FALSE);
-
- if (_dx_real_above(len, rmem_adrp, &stemp) != _DOSE_NONE)
- *rmem_adrp = 0;
-
- if (_dx_cmem_usage(0, 1, &temp, &temp) != _DOSE_NONE)
- {
- if (*rmem_adrp != 0)
- _dx_real_free (*rmem_adrp);
- return (FALSE);
- }
-
- if (*rmem_adrp == 0)
- return (FALSE);
- }
-
- /* Construct real mode & protected mode pointers to access the allocated
- * memory. Note we know start_offs is aligned on a paragraph (16-byte)
- * boundary, because we rounded it down.
- *
- * We make the offsets come out rights by backing off the real mode selector
- * by start_offs.
- */
- rm_base = ((ULONG) *rmem_adrp) - (start_offs >> 4);
- RP_SET (*real_basep, 0, rm_base);
- FP_SET (*prot_basep, rm_base << 4, SS_DOSMEM);
-
- /* Copy the real mode code/data to the allocated memory
- */
- source = (UCHAR *) start_offs;
- destin = *prot_basep;
- FP_SET (destin, FP_OFF(*prot_basep) + start_offs, FP_SEL(*prot_basep));
- len = end_offs - start_offs;
- WriteFarMem (destin, source, len);
-
- return (TRUE);
-}
-#endif /* DOSX && (DOSX & PHARLAP) */
diff --git a/msdos/pktdrvr.h b/msdos/pktdrvr.h
deleted file mode 100644
index 82a10265..00000000
--- a/msdos/pktdrvr.h
+++ /dev/null
@@ -1,153 +0,0 @@
-#ifndef __PKTDRVR_H
-#define __PKTDRVR_H
-
-#define PUBLIC
-#define LOCAL static
-
-#define RX_BUF_SIZE ETH_MTU /* buffer size variables. NB !! */
-#define TX_BUF_SIZE ETH_MTU /* must be same as in pkt_rx*.* */
-
-#ifdef __HIGHC__
-#pragma Off(Align_members)
-#else
-#pragma pack(1)
-#endif
-
-typedef enum { /* Packet-driver classes */
- PD_ETHER = 1,
- PD_PRONET10 = 2,
- PD_IEEE8025 = 3,
- PD_OMNINET = 4,
- PD_APPLETALK = 5,
- PD_SLIP = 6,
- PD_STARTLAN = 7,
- PD_ARCNET = 8,
- PD_AX25 = 9,
- PD_KISS = 10,
- PD_IEEE8023_2 = 11,
- PD_FDDI8022 = 12,
- PD_X25 = 13,
- PD_LANstar = 14,
- PD_PPP = 18
- } PKT_CLASS;
-
-typedef enum { /* Packet-driver receive modes */
- PDRX_OFF = 1, /* turn off receiver */
- PDRX_DIRECT, /* receive only to this interface */
- PDRX_BROADCAST, /* DIRECT + broadcast packets */
- PDRX_MULTICAST1, /* BROADCAST + limited multicast */
- PDRX_MULTICAST2, /* BROADCAST + all multicast */
- PDRX_ALL_PACKETS, /* receive all packets on network */
- } PKT_RX_MODE;
-
-typedef struct {
- char type[8];
- char len;
- } PKT_FRAME;
-
-
-typedef struct {
- BYTE class; /* = 1 for DEC/Intel/Xerox Ethernet */
- BYTE number; /* = 0 for single LAN adapter */
- WORD type; /* = 13 for 3C523 */
- BYTE funcs; /* Basic/Extended/HiPerf functions */
- WORD intr; /* user interrupt vector number */
- WORD handle; /* Handle associated with session */
- BYTE name [15]; /* Name of adapter interface,ie.3C523*/
- BOOL quiet; /* (don't) print errors to stdout */
- const char *error; /* address of error string */
- BYTE majVer; /* Major driver implementation ver. */
- BYTE minVer; /* Minor driver implementation ver. */
- BYTE dummyLen; /* length of following data */
- WORD MAClength; /* HiPerformance data, N/A */
- WORD MTU; /* HiPerformance data, N/A */
- WORD multicast; /* HiPerformance data, N/A */
- WORD rcvrBuffers; /* valid for */
- WORD UMTbufs; /* High Performance drivers only */
- WORD postEOIintr; /* Usage ?? */
- } PKT_INFO;
-
-#define PKT_PARAM_SIZE 14 /* members majVer - postEOIintr */
-
-
-typedef struct {
- DWORD inPackets; /* # of packets received */
- DWORD outPackets; /* # of packets transmitted */
- DWORD inBytes; /* # of bytes received */
- DWORD outBytes; /* # of bytes transmitted */
- DWORD inErrors; /* # of reception errors */
- DWORD outErrors; /* # of transmission errors */
- DWORD lost; /* # of packets lost (RX) */
- } PKT_STAT;
-
-
-typedef struct {
- ETHER destin;
- ETHER source;
- WORD proto;
- BYTE data [TX_BUF_SIZE];
- } TX_ELEMENT;
-
-typedef struct {
- WORD firstCount; /* # of bytes on 1st */
- WORD secondCount; /* and 2nd upcall */
- WORD handle; /* instance that upcalled */
- ETHER destin; /* E-net destination address */
- ETHER source; /* E-net source address */
- WORD proto; /* protocol number */
- BYTE data [RX_BUF_SIZE];
- } RX_ELEMENT;
-
-
-#ifdef __HIGHC__
-#pragma pop(Align_members)
-#else
-#pragma pack()
-#endif
-
-
-/*
- * Prototypes for publics
- */
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-extern PKT_STAT pktStat; /* statistics for packets */
-extern PKT_INFO pktInfo; /* packet-driver information */
-
-extern PKT_RX_MODE receiveMode;
-extern ETHER myAddress, ethBroadcast;
-
-extern BOOL PktInitDriver (PKT_RX_MODE mode);
-extern BOOL PktExitDriver (void);
-
-extern const char *PktGetErrorStr (int errNum);
-extern const char *PktGetClassName (WORD class);
-extern const char *PktRXmodeStr (PKT_RX_MODE mode);
-extern BOOL PktSearchDriver (void);
-extern int PktReceive (BYTE *buf, int max);
-extern BOOL PktTransmit (const void *eth, int len);
-extern DWORD PktRxDropped (void);
-extern BOOL PktReleaseHandle (WORD handle);
-extern BOOL PktTerminHandle (WORD handle);
-extern BOOL PktResetInterface (WORD handle);
-extern BOOL PktSetReceiverMode(PKT_RX_MODE mode);
-extern BOOL PktGetReceiverMode(PKT_RX_MODE *mode);
-extern BOOL PktGetStatistics (WORD handle);
-extern BOOL PktSessStatistics (WORD handle);
-extern BOOL PktResetStatistics(WORD handle);
-extern BOOL PktGetAddress (ETHER *addr);
-extern BOOL PktSetAddress (const ETHER *addr);
-extern BOOL PktGetDriverInfo (void);
-extern BOOL PktGetDriverParam (void);
-extern void PktQueueBusy (BOOL busy);
-extern WORD PktBuffersUsed (void);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* __PKTDRVR_H */
-
diff --git a/msdos/readme.dos b/msdos/readme.dos
deleted file mode 100644
index d2bb2112..00000000
--- a/msdos/readme.dos
+++ /dev/null
@@ -1,166 +0,0 @@
-libpcap for DOS
----------------
-
-This file contains some notes on building and using libpcap for MS-DOS.
-Look in `README' and `pcap.man' for usage and details. These targets are
-supported:
-
- - Borland C 4.0+ small or large model.
- - Metaware HighC 3.1+ with PharLap DOS-extender
- - GNU C 2.7+ with djgpp 2.01+ DOS extender
- - Watcom C 11.x with DOS4GW extender
-
-Note: the files in the libpcap.zip contains short truncated filenames.
- So for djgpp to work with these, disable the use of long file names by
- setting "LFN=n" in the environment. On the other hand, if you get libpcap
- from GitHub or the official libpcap.tar.gz, some filenames are beyond 8+3.
- In this case set "LFN=y".
-
-Files specific to DOS are pcap-dos.[ch] and the assembly and C files in
-the MSDOS sub-directory. Remember to built the libpcap library from the top
-install directory. And not from the MSDOS sub-directory.
-
-Note for djgpp users:
- If you got the libpcap from the official site www.tcpdump, then that
- distribution does NOT contain any sources for building 32-bit drivers.
- Instead get the full version at
- https://www.watt-32.net/pcap/libpcap.zip
-
- and set "USE_32BIT_DRIVERS = 1" in msdos\common.dj.
-
-
-
-Requirements
-------------
-
-DOS-libpcap currently only works reliably with a real-mode Ethernet packet-
-driver. This driver must be installed prior to using any program (e.g.
-tcpdump) compiled with libpcap. Work is underway to implement protected-
-mode drivers for 32-bit targets (djgpp only). The 3Com 3c509 driver is
-working almost perfectly. Due to lack of LAN-cards, I've not had the
-opportunity to test other drivers. These 32-bit drivers are modified
-Linux drivers.
-
-
-Required packages
------------------
-
-The following packages and tools must be present for all targets.
-
-1. Watt-32 tcp/ip library. This library is *not* used to send or
- receive network data. It's mostly used to access the 'hosts'
- file and other <netdb.h> features. Get 'watt32s*.zip' at:
-
- https://www.watt-32.net
-
-2. Exception handler and disassembler library (libexc.a) is needed if
- "USE_EXCEPT = 1" in common.dj. Available at:
-
- https://www.watt-32.net/misc/exc_dx07.zip
-
-3. Flex & Bison is used to generate parser for the filter handler
- pcap_compile:
- ftp://ftp.delorie.com/pub/djgpp/current/v2gnu/flx254b.zip
- ftp://ftp.delorie.com/pub/djgpp/current/v2gnu/bsn241b.zip
-
-4. NASM assembler v 0.98 or later is required when building djgpp and
- Watcom targets:
- https://www.nasm.us/
-
-5. sed (Stream Editor) is required for doing `make depend'.
- It's available at:
- ftp://ftp.delorie.com/pub/djgpp/current/v2gnu/sed422b.zip
-
- A touch tool to update the time-stamp of a file. E.g.:
- ftp://ftp.delorie.com/pub/djgpp/current/v2gnu/grep29b.zip
-
-6. For djgpp rm.exe and cp.exe are required. These should already be
- part of your djgpp installation. Also required (experimental at the
- time) for djgpp is DLX 2.91 or later. This tool is for the generation
- of dynamically loadable modules.
-
-
-Compiling libpcap
------------------
-
-Follow these steps in building libpcap:
-
-1. Make sure you've installed Watt-32 properly (see it's `INSTALL' file).
- During that installation a environment variable `WATT_ROOT' is set.
- This variable is used for building libpcap also (`WATT_INC' is
- deducted from `WATT_ROOT'). djgpp users should also define environment
- variables `C_INCLUDE_PATH' and `LIBRARY_PATH' to point to the include
- directory and library directory respectively. E.g. put this in your
- AUTOEXEC.BAT:
- set C_INCLUDE_PATH=c:/net/watt/inc
- set LIBRARY_PATH=c:/net/watt/lib
-
-2. Revise the msdos/common.dj file for your djgpp/gcc installation;
- - change the value of `GCCLIB' to match location of libgcc.a.
- - set `USE_32BIT_DRIVERS = 1' to build 32-bit driver objects.
-
-
-3. Build pcap by using appropriate makefile. For djgpp, use:
- `make -f msdos/makefile.dj' (i.e. GNU `make')
-
- For a Watcom target say:
- `wmake -f msdos\makefile.wc'
-
- For a Borland target say:
- `maker -f msdos\Makefile pcap_bc.lib' (Borland's `maker.exe')
-
- And for a HighC/Pharlap target say:
- `maker -f msdos\Makefile pcap_hc.lib' (Borland's `maker.exe')
-
- You might like to change some `CFLAGS' -- only `DEBUG' define currently
- have any effect. It shows a rotating "fan" in upper right corner of
- screen. Remove `DEBUG' if you don't like it. You could add
- `-fomit-frame-pointer' to `CFLAGS' to speed up the generated code.
- But note, this makes debugging and crash-traceback difficult. Only
- add it if you're fully confident your application is 100% stable.
-
- Note: Code in `USE_NDIS2' does not work at the moment.
-
-4. The resulting library is put in current directory. There's some
- test-program for `libpcap': `filtertest.exe', `findalldevstest.exe',
- `nonblocktest.exe' and `opentest.exe'.
-
- But linking the library with `tcpdump' is the ultimate test. DOS/djgpp
- should now hopefully be a supported target. Get the sources at:
- https://www.tcpdump.org/
- or
- https://github.com/the-tcpdump-group/tcpdump/
-
- (click on the 'Download ZIP' on the right side of that page.)
-
-
-Extensions to libpcap
----------------------
-
-I've included some extra functions to DOS-libpcap:
-
- `pcap_config_hook (const char *keyword, const char *value)' :
-
- Allows an application to set values of internal libpcap variables.
- `keyword' and an associated `value' should be present in the `debug_tab[]'
- array in pcap-dos.c (currently only used to set debug-levels and parameters
- for the 32-bit network drivers.) Thus an application using DOS-libpcap can
- override the default value during it's configure process (see tcpdump's
- msdos/config.c file for an extended example).
-
- `pcap_set_wait (pcap_t *, void (*)(void), int)' :
-
- Only effective when reading offline traffic from dump-files.
- Function `pcap_offline_read()' will wait (and optionally yield)
- before printing next packet. This will simulate the pace the packets
- where actually recorded.
-
-
-
-Happy sniffing !
-
-
-Gisle Vanem <gvanem@yahoo.no>
-
-October 1999, 2004, 2006, 2013
-
diff --git a/optimize.c b/optimize.c
index 6adcbc12..f22a092d 100644
--- a/optimize.c
+++ b/optimize.c
@@ -141,22 +141,6 @@ lowest_set_bit(int mask)
abort(); /* mask is zero */
return (u_int)bit;
}
-#elif (defined(MSDOS) && defined(__WATCOMC__)) || defined(STRINGS_H_DECLARES_FFS)
- /*
- * MS-DOS with Watcom C, which has <strings.h> and declares ffs() there,
- * or some other platform (UN*X conforming to a sufficient recent version
- * of the Single UNIX Specification).
- */
- #include <strings.h>
- #define lowest_set_bit(mask) (u_int)((ffs((mask)) - 1))
-#elif (defined(MSDOS) && defined(__DJGPP__)) || defined(__hpux)
- /*
- * MS-DOS with DJGPP or HP-UX 11i v3, which declare ffs() in <string.h>,
- * which we've already included. Place this branch after the <strings.h>
- * branch, in case a later release of HP-UX makes the declaration available
- * via the standard header.
- */
- #define lowest_set_bit(mask) ((u_int)(ffs((mask)) - 1))
#else
/*
* None of the above.
diff --git a/pcap-dos.c b/pcap-dos.c
deleted file mode 100644
index 5093c5f0..00000000
--- a/pcap-dos.c
+++ /dev/null
@@ -1,1550 +0,0 @@
-/*
- * This file is part of DOS-libpcap
- * Ported to DOS/DOSX by G. Vanem <gvanem@yahoo.no>
- *
- * pcap-dos.c: Interface to PKTDRVR, NDIS2 and 32-bit pmode
- * network drivers.
- */
-
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <signal.h>
-#include <float.h>
-#include <fcntl.h>
-#include <limits.h> /* for INT_MAX */
-#include <io.h>
-
-#if defined(USE_32BIT_DRIVERS)
- #include "msdos/pm_drvr/pmdrvr.h"
- #include "msdos/pm_drvr/pci.h"
- #include "msdos/pm_drvr/bios32.h"
- #include "msdos/pm_drvr/module.h"
- #include "msdos/pm_drvr/3c501.h"
- #include "msdos/pm_drvr/3c503.h"
- #include "msdos/pm_drvr/3c509.h"
- #include "msdos/pm_drvr/3c59x.h"
- #include "msdos/pm_drvr/3c515.h"
- #include "msdos/pm_drvr/3c90x.h"
- #include "msdos/pm_drvr/3c575_cb.h"
- #include "msdos/pm_drvr/ne.h"
- #include "msdos/pm_drvr/wd.h"
- #include "msdos/pm_drvr/accton.h"
- #include "msdos/pm_drvr/cs89x0.h"
- #include "msdos/pm_drvr/rtl8139.h"
- #include "msdos/pm_drvr/ne2k-pci.h"
-#endif
-
-#include "pcap.h"
-#include "pcap-dos.h"
-#include "pcap-int.h"
-#include "msdos/pktdrvr.h"
-
-#ifdef USE_NDIS2
-#include "msdos/ndis2.h"
-#endif
-
-#include <arpa/inet.h>
-#include <net/if.h>
-#include <net/if_arp.h>
-#include <net/if_ether.h>
-#include <net/if_packe.h>
-#include <tcp.h>
-
-#if defined(USE_32BIT_DRIVERS)
- #define FLUSHK() do { _printk_safe = 1; _printk_flush(); } while (0)
- #define NDIS_NEXT_DEV &rtl8139_dev
-
- static char *rx_pool = NULL;
- static void init_32bit (void);
-
- static int pktq_init (struct rx_ringbuf *q, int size, int num, char *pool);
- static int pktq_check (struct rx_ringbuf *q);
- static int pktq_inc_out (struct rx_ringbuf *q);
- static int pktq_in_index (struct rx_ringbuf *q) LOCKED_FUNC;
- static void pktq_clear (struct rx_ringbuf *q) LOCKED_FUNC;
-
- static struct rx_elem *pktq_in_elem (struct rx_ringbuf *q) LOCKED_FUNC;
- static struct rx_elem *pktq_out_elem (struct rx_ringbuf *q);
-
-#else
- #define FLUSHK() ((void)0)
- #define NDIS_NEXT_DEV NULL
-#endif
-
-/*
- * Internal variables/functions in Watt-32
- */
-extern WORD _pktdevclass;
-extern BOOL _eth_is_init;
-extern int _w32_dynamic_host;
-extern int _watt_do_exit;
-extern int _watt_is_init;
-extern int _w32__bootp_on, _w32__dhcp_on, _w32__rarp_on, _w32__do_mask_req;
-extern void (*_w32_usr_post_init) (void);
-extern void (*_w32_print_hook)();
-
-extern void dbug_write (const char *); /* Watt-32 lib, pcdbug.c */
-extern int pkt_get_mtu (void);
-
-static int ref_count = 0;
-
-static u_long mac_count = 0;
-static u_long filter_count = 0;
-
-static volatile BOOL exc_occurred = 0;
-
-static struct device *handle_to_device [20];
-
-static int pcap_activate_dos (pcap_t *p);
-static int pcap_read_dos (pcap_t *p, int cnt, pcap_handler callback,
- u_char *data);
-static void pcap_cleanup_dos (pcap_t *p);
-static int pcap_stats_dos (pcap_t *p, struct pcap_stat *ps);
-static int pcap_sendpacket_dos (pcap_t *p, const void *buf, size_t len);
-static int pcap_setfilter_dos (pcap_t *p, struct bpf_program *fp);
-
-static int ndis_probe (struct device *dev);
-static int pkt_probe (struct device *dev);
-
-static void close_driver (void);
-static int init_watt32 (struct pcap *pcap, const char *dev_name, char *err_buf);
-static int first_init (const char *name, char *ebuf, int promisc);
-
-static void watt32_recv_hook (u_char *dummy, const struct pcap_pkthdr *pcap,
- const u_char *buf);
-
-/*
- * These are the device we always support
- */
-static struct device ndis_dev = {
- "ndis",
- "NDIS2 LanManager",
- 0,
- 0,0,0,0,0,0,
- NDIS_NEXT_DEV, /* NULL or a 32-bit device */
- ndis_probe
- };
-
-static struct device pkt_dev = {
- "pkt",
- "Packet-Driver",
- 0,
- 0,0,0,0,0,0,
- &ndis_dev,
- pkt_probe
- };
-
-static struct device *get_device (int fd)
-{
- if (fd <= 0 || fd >= sizeof(handle_to_device)/sizeof(handle_to_device[0]))
- return (NULL);
- return handle_to_device [fd-1];
-}
-
-/*
- * Private data for capturing on MS-DOS.
- */
-struct pcap_dos {
- void (*wait_proc)(void); /* call proc while waiting */
- struct pcap_stat stat;
-};
-
-pcap_t *pcap_create_interface (const char *device _U_, char *ebuf)
-{
- pcap_t *p;
-
- p = PCAP_CREATE_COMMON(ebuf, struct pcap_dos);
- if (p == NULL)
- return (NULL);
-
- p->activate_op = pcap_activate_dos;
- return (p);
-}
-
-/*
- * Open MAC-driver with name 'device_name' for live capture of
- * network packets.
- */
-static int pcap_activate_dos (pcap_t *pcap)
-{
- if (pcap->opt.rfmon) {
- /*
- * No monitor mode on DOS.
- */
- return (PCAP_ERROR_RFMON_NOTSUP);
- }
-
- /*
- * Turn a negative snapshot value (invalid), a snapshot value of
- * 0 (unspecified), or a value bigger than the normal maximum
- * value, into the maximum allowed value.
- *
- * If some application really *needs* a bigger snapshot
- * length, we should just increase MAXIMUM_SNAPLEN.
- */
- if (pcap->snapshot <= 0 || pcap->snapshot > MAXIMUM_SNAPLEN)
- pcap->snapshot = MAXIMUM_SNAPLEN;
-
- if (pcap->snapshot < ETH_MIN+8)
- pcap->snapshot = ETH_MIN+8;
-
- if (pcap->snapshot > ETH_MAX) /* silently accept and truncate large MTUs */
- pcap->snapshot = ETH_MAX;
-
- pcap->linktype = DLT_EN10MB; /* !! */
- pcap->cleanup_op = pcap_cleanup_dos;
- pcap->read_op = pcap_read_dos;
- pcap->stats_op = pcap_stats_dos;
- pcap->inject_op = pcap_sendpacket_dos;
- pcap->setfilter_op = pcap_setfilter_dos;
- pcap->setdirection_op = NULL; /* Not implemented.*/
- pcap->fd = ++ref_count;
-
- pcap->bufsize = ETH_MAX+100; /* add some margin */
- pcap->buffer = calloc (pcap->bufsize, 1);
-
- if (pcap->fd == 1) /* first time we're called */
- {
- if (!init_watt32(pcap, pcap->opt.device, pcap->errbuf) ||
- !first_init(pcap->opt.device, pcap->errbuf, pcap->opt.promisc))
- {
- /* XXX - free pcap->buffer? */
- return (PCAP_ERROR);
- }
- atexit (close_driver);
- }
- else if (stricmp(active_dev->name,pcap->opt.device))
- {
- snprintf (pcap->errbuf, PCAP_ERRBUF_SIZE,
- "Cannot use different devices simultaneously "
- "(`%s' vs. `%s')", active_dev->name, pcap->opt.device);
- /* XXX - free pcap->buffer? */
- return (PCAP_ERROR);
- }
- handle_to_device [pcap->fd-1] = active_dev;
- return (0);
-}
-
-/*
- * Poll the receiver queue and call the pcap callback-handler
- * with the packet.
- */
-static int
-pcap_read_one (pcap_t *p, pcap_handler callback, u_char *data)
-{
- struct pcap_dos *pd = p->priv;
- struct pcap_pkthdr pcap;
- struct timeval now, expiry = { 0,0 };
- int rx_len = 0;
-
- if (p->opt.timeout > 0)
- {
- gettimeofday2 (&now, NULL);
- expiry.tv_usec = now.tv_usec + 1000UL * p->opt.timeout;
- expiry.tv_sec = now.tv_sec;
- while (expiry.tv_usec >= 1000000L)
- {
- expiry.tv_usec -= 1000000L;
- expiry.tv_sec++;
- }
- }
-
- while (!exc_occurred)
- {
- volatile struct device *dev; /* might be reset by sig_handler */
-
- dev = get_device (p->fd);
- if (!dev)
- break;
-
- PCAP_ASSERT (dev->copy_rx_buf || dev->peek_rx_buf);
- FLUSHK();
-
- /* If driver has a zero-copy receive facility, peek at the queue,
- * filter it, do the callback and release the buffer.
- */
- if (dev->peek_rx_buf)
- {
- PCAP_ASSERT (dev->release_rx_buf);
- rx_len = (*dev->peek_rx_buf) (&p->buffer);
- }
- else
- {
- rx_len = (*dev->copy_rx_buf) (p->buffer, p->snapshot);
- }
-
- if (rx_len > 0) /* got a packet */
- {
- mac_count++;
-
- FLUSHK();
-
- pcap.caplen = min (rx_len, p->snapshot);
- pcap.len = rx_len;
-
- if (callback &&
- (!p->fcode.bf_insns || pcap_filter(p->fcode.bf_insns, p->buffer, pcap.len, pcap.caplen)))
- {
- filter_count++;
-
- /* Fix-me!! Should be time of arrival. Not time of
- * capture.
- */
- gettimeofday2 (&pcap.ts, NULL);
- (*callback) (data, &pcap, p->buffer);
- }
-
- if (dev->release_rx_buf)
- (*dev->release_rx_buf) (p->buffer);
-
- if (pcap_pkt_debug > 0)
- {
- if (callback == watt32_recv_hook)
- dbug_write ("pcap_recv_hook\n");
- else dbug_write ("pcap_read_op\n");
- }
- FLUSHK();
- return (1);
- }
-
- /* Has "pcap_breakloop()" been called?
- */
- if (p->break_loop) {
- /*
- * Yes - clear the flag that indicates that it
- * has, and return -2 to indicate that we were
- * told to break out of the loop.
- */
- p->break_loop = 0;
- return (-2);
- }
-
- /* If not to wait for a packet or pcap_cleanup_dos() called from
- * e.g. SIGINT handler, exit loop now.
- */
- if (p->opt.timeout <= 0 || (volatile int)p->fd <= 0)
- break;
-
- gettimeofday2 (&now, NULL);
-
- if (timercmp(&now, &expiry, >))
- break;
-
-#ifndef DJGPP
- kbhit(); /* a real CPU hog */
-#endif
-
- if (pd->wait_proc)
- (*pd->wait_proc)(); /* call yield func */
- }
-
- if (rx_len < 0) /* receive error */
- {
- pd->stat.ps_drop++;
-#ifdef USE_32BIT_DRIVERS
- if (pcap_pkt_debug > 1)
- printk ("pkt-err %s\n", pktInfo.error);
-#endif
- return (-1);
- }
- return (0);
-}
-
-static int
-pcap_read_dos (pcap_t *p, int cnt, pcap_handler callback, u_char *data)
-{
- int rc, num = 0;
-
- /*
- * This can conceivably process more than INT_MAX packets,
- * which would overflow the packet count, causing it either
- * to look like a negative number, and thus cause us to
- * return a value that looks like an error, or overflow
- * back into positive territory, and thus cause us to
- * return a too-low count.
- *
- * Therefore, if the packet count is unlimited, we clip
- * it at INT_MAX; this routine is not expected to
- * process packets indefinitely, so that's not an issue.
- */
- if (PACKET_COUNT_IS_UNLIMITED(cnt))
- cnt = INT_MAX;
-
- while (num <= cnt)
- {
- if (p->fd <= 0)
- return (-1);
- rc = pcap_read_one (p, callback, data);
- if (rc > 0)
- num++;
- if (rc < 0)
- break;
- _w32_os_yield(); /* allow SIGINT generation, yield to Win95/NT */
- }
- return (num);
-}
-
-/*
- * Return network statistics
- */
-static int pcap_stats_dos (pcap_t *p, struct pcap_stat *ps)
-{
- struct net_device_stats *stats;
- struct pcap_dos *pd;
- struct device *dev = p ? get_device(p->fd) : NULL;
-
- if (!dev)
- {
- strcpy (p->errbuf, "illegal pcap handle");
- return (-1);
- }
-
- if (!dev->get_stats || (stats = (*dev->get_stats)(dev)) == NULL)
- {
- strcpy (p->errbuf, "device statistics not available");
- return (-1);
- }
-
- FLUSHK();
-
- pd = p->priv;
- pd->stat.ps_recv = stats->rx_packets;
- pd->stat.ps_drop += stats->rx_missed_errors;
- pd->stat.ps_ifdrop = stats->rx_dropped + /* queue full */
- stats->rx_errors; /* HW errors */
- if (ps)
- *ps = pd->stat;
-
- return (0);
-}
-
-/*
- * Return detailed network/device statistics.
- * May be called after 'dev->close' is called.
- */
-int pcap_stats_ex (pcap_t *p, struct pcap_stat_ex *se)
-{
- struct device *dev = p ? get_device (p->fd) : NULL;
-
- if (!dev || !dev->get_stats)
- {
- pcap_strlcpy (p->errbuf, "detailed device statistics not available",
- PCAP_ERRBUF_SIZE);
- return (-1);
- }
-
- if (!strnicmp(dev->name,"pkt",3))
- {
- pcap_strlcpy (p->errbuf, "pktdrvr doesn't have detailed statistics",
- PCAP_ERRBUF_SIZE);
- return (-1);
- }
- memcpy (se, (*dev->get_stats)(dev), sizeof(*se));
- return (0);
-}
-
-/*
- * Simply store the filter-code for the pcap_read_dos() callback
- * Some day the filter-code could be handed down to the active
- * device (pkt_rx1.s or 32-bit device interrupt handler).
- */
-static int pcap_setfilter_dos (pcap_t *p, struct bpf_program *fp)
-{
- if (!p)
- return (-1);
- p->fcode = *fp;
- return (0);
-}
-
-/*
- * Return # of packets received in pcap_read_dos()
- */
-u_long pcap_mac_packets (void)
-{
- return (mac_count);
-}
-
-/*
- * Return # of packets passed through filter in pcap_read_dos()
- */
-u_long pcap_filter_packets (void)
-{
- return (filter_count);
-}
-
-/*
- * Close pcap device. Not called for offline captures.
- */
-static void pcap_cleanup_dos (pcap_t *p)
-{
- struct pcap_dos *pd;
-
- if (!exc_occurred)
- {
- pd = p->priv;
- if (pcap_stats(p,NULL) < 0)
- pd->stat.ps_drop = 0;
- if (!get_device(p->fd))
- return;
-
- handle_to_device [p->fd-1] = NULL;
- p->fd = 0;
- if (ref_count > 0)
- ref_count--;
- if (ref_count > 0)
- return;
- }
- close_driver();
- /* XXX - call pcap_cleanup_live_common? */
-}
-
-/*
- * Return the name of the 1st network interface,
- * or NULL if none can be found.
- */
-char *pcap_lookupdev (char *ebuf)
-{
- struct device *dev;
-
-#ifdef USE_32BIT_DRIVERS
- init_32bit();
-#endif
-
- for (dev = (struct device*)dev_base; dev; dev = dev->next)
- {
- PCAP_ASSERT (dev->probe);
-
- if ((*dev->probe)(dev))
- {
- FLUSHK();
- probed_dev = (struct device*) dev; /* remember last probed device */
- return (char*) dev->name;
- }
- }
-
- if (ebuf)
- strcpy (ebuf, "No driver found");
- return (NULL);
-}
-
-/*
- * Gets localnet & netmask from Watt-32.
- */
-int pcap_lookupnet (const char *device, bpf_u_int32 *localnet,
- bpf_u_int32 *netmask, char *errbuf)
-{
- DWORD mask, net;
-
- if (!_watt_is_init)
- {
- strcpy (errbuf, "pcap_open_offline() or pcap_activate() must be "
- "called first");
- return (-1);
- }
-
- mask = _w32_sin_mask;
- net = my_ip_addr & mask;
- if (net == 0)
- {
- if (IN_CLASSA(*netmask))
- net = IN_CLASSA_NET;
- else if (IN_CLASSB(*netmask))
- net = IN_CLASSB_NET;
- else if (IN_CLASSC(*netmask))
- net = IN_CLASSC_NET;
- else
- {
- snprintf (errbuf, PCAP_ERRBUF_SIZE, "inet class for 0x%lx unknown", mask);
- return (-1);
- }
- }
- *localnet = htonl (net);
- *netmask = htonl (mask);
-
- ARGSUSED (device);
- return (0);
-}
-
-/*
- * Get a list of all interfaces that are present and that we probe okay.
- * Returns -1 on error, 0 otherwise.
- * The list may be NULL empty if no interfaces were up and could be opened.
- */
-int pcap_platform_finddevs (pcap_if_list_t *devlistp, char *errbuf)
-{
- struct device *dev;
- pcap_if_t *curdev;
-#if 0 /* Pkt drivers should have no addresses */
- struct sockaddr_in sa_ll_1, sa_ll_2;
- struct sockaddr *addr, *netmask, *broadaddr, *dstaddr;
-#endif
- int ret = 0;
- int found = 0;
-
- for (dev = (struct device*)dev_base; dev; dev = dev->next)
- {
- PCAP_ASSERT (dev->probe);
-
- if (!(*dev->probe)(dev))
- continue;
-
- PCAP_ASSERT (dev->close); /* set by probe routine */
- FLUSHK();
- (*dev->close) (dev);
-
- /*
- * XXX - find out whether it's up or running? Does that apply here?
- * Can we find out if anything's plugged into the adapter, if it's
- * a wired device, and set PCAP_IF_CONNECTION_STATUS_CONNECTED
- * or PCAP_IF_CONNECTION_STATUS_DISCONNECTED?
- */
- if ((curdev = pcap_add_dev(devlistp, dev->name, 0,
- dev->long_name, errbuf)) == NULL)
- {
- ret = -1;
- break;
- }
- found = 1;
-#if 0 /* Pkt drivers should have no addresses */
- memset (&sa_ll_1, 0, sizeof(sa_ll_1));
- memset (&sa_ll_2, 0, sizeof(sa_ll_2));
- sa_ll_1.sin_family = AF_INET;
- sa_ll_2.sin_family = AF_INET;
-
- addr = (struct sockaddr*) &sa_ll_1;
- netmask = (struct sockaddr*) &sa_ll_1;
- dstaddr = (struct sockaddr*) &sa_ll_1;
- broadaddr = (struct sockaddr*) &sa_ll_2;
- memset (&sa_ll_2.sin_addr, 0xFF, sizeof(sa_ll_2.sin_addr));
-
- if (pcap_add_addr_to_dev(curdev, addr, sizeof(*addr),
- netmask, sizeof(*netmask),
- broadaddr, sizeof(*broadaddr),
- dstaddr, sizeof(*dstaddr), errbuf) < 0)
- {
- ret = -1;
- break;
- }
-#endif
- }
-
- if (ret == 0 && !found)
- strcpy (errbuf, "No drivers found");
-
- return (ret);
-}
-
-/*
- * pcap_assert() is mainly used for debugging
- */
-void pcap_assert (const char *what, const char *file, unsigned line)
-{
- FLUSHK();
- fprintf (stderr, "%s (%u): Assertion \"%s\" failed\n",
- file, line, what);
- close_driver();
- _exit (-1);
-}
-
-/*
- * For pcap_offline_read(): wait and yield between printing packets
- * to simulate the pace packets where actually recorded.
- */
-void pcap_set_wait (pcap_t *p, void (*yield)(void), int wait)
-{
- if (p)
- {
- struct pcap_dos *pd = p->priv;
-
- pd->wait_proc = yield;
- p->opt.timeout = wait;
- }
-}
-
-/*
- * Initialize a named network device.
- */
-static struct device *
-open_driver (const char *dev_name, char *ebuf, int promisc)
-{
- struct device *dev;
-
- for (dev = (struct device*)dev_base; dev; dev = dev->next)
- {
- PCAP_ASSERT (dev->name);
-
- if (strcmp (dev_name,dev->name))
- continue;
-
- if (!probed_dev) /* user didn't call pcap_lookupdev() first */
- {
- PCAP_ASSERT (dev->probe);
-
- if (!(*dev->probe)(dev)) /* call the xx_probe() function */
- {
- snprintf (ebuf, PCAP_ERRBUF_SIZE, "failed to detect device `%s'", dev_name);
- return (NULL);
- }
- probed_dev = dev; /* device is probed okay and may be used */
- }
- else if (dev != probed_dev)
- {
- goto not_probed;
- }
-
- FLUSHK();
-
- /* Select what traffic to receive
- */
- if (promisc)
- dev->flags |= (IFF_ALLMULTI | IFF_PROMISC);
- else dev->flags &= ~(IFF_ALLMULTI | IFF_PROMISC);
-
- PCAP_ASSERT (dev->open);
-
- if (!(*dev->open)(dev))
- {
- snprintf (ebuf, PCAP_ERRBUF_SIZE, "failed to activate device `%s'", dev_name);
- if (pktInfo.error && !strncmp(dev->name,"pkt",3))
- {
- strcat (ebuf, ": ");
- strcat (ebuf, pktInfo.error);
- }
- return (NULL);
- }
-
- /* Some devices need this to operate in promiscuous mode
- */
- if (promisc && dev->set_multicast_list)
- (*dev->set_multicast_list) (dev);
-
- active_dev = dev; /* remember our active device */
- break;
- }
-
- /* 'dev_name' not matched in 'dev_base' list.
- */
- if (!dev)
- {
- snprintf (ebuf, PCAP_ERRBUF_SIZE, "device `%s' not supported", dev_name);
- return (NULL);
- }
-
-not_probed:
- if (!probed_dev)
- {
- snprintf (ebuf, PCAP_ERRBUF_SIZE, "device `%s' not probed", dev_name);
- return (NULL);
- }
- return (dev);
-}
-
-/*
- * Deinitialize MAC driver.
- * Set receive mode back to default mode.
- */
-static void close_driver (void)
-{
- /* !!todo: loop over all 'handle_to_device[]' ? */
- struct device *dev = active_dev;
-
- if (dev && dev->close)
- {
- (*dev->close) (dev);
- FLUSHK();
- }
-
- active_dev = NULL;
-
-#ifdef USE_32BIT_DRIVERS
- if (rx_pool)
- {
- k_free (rx_pool);
- rx_pool = NULL;
- }
- if (dev)
- pcibios_exit();
-#endif
-}
-
-
-#ifdef __DJGPP__
-static void setup_signals (void (*handler)(int))
-{
- signal (SIGSEGV,handler);
- signal (SIGILL, handler);
- signal (SIGFPE, handler);
-}
-
-static void exc_handler (int sig)
-{
-#ifdef USE_32BIT_DRIVERS
- if (active_dev->irq > 0) /* excludes IRQ 0 */
- {
- disable_irq (active_dev->irq);
- irq_eoi_cmd (active_dev->irq);
- _printk_safe = 1;
- }
-#endif
-
- switch (sig)
- {
- case SIGSEGV:
- fputs ("Catching SIGSEGV.\n", stderr);
- break;
- case SIGILL:
- fputs ("Catching SIGILL.\n", stderr);
- break;
- case SIGFPE:
- _fpreset();
- fputs ("Catching SIGFPE.\n", stderr);
- break;
- default:
- fprintf (stderr, "Catching signal %d.\n", sig);
- }
- exc_occurred = 1;
- close_driver();
-}
-#endif /* __DJGPP__ */
-
-
-/*
- * Open the pcap device for the first client calling pcap_activate()
- */
-static int first_init (const char *name, char *ebuf, int promisc)
-{
- struct device *dev;
-
-#ifdef USE_32BIT_DRIVERS
- rx_pool = k_calloc (RECEIVE_BUF_SIZE, RECEIVE_QUEUE_SIZE);
- if (!rx_pool)
- {
- strcpy (ebuf, "Not enough memory (Rx pool)");
- return (0);
- }
-#endif
-
-#ifdef __DJGPP__
- setup_signals (exc_handler);
-#endif
-
-#ifdef USE_32BIT_DRIVERS
- init_32bit();
-#endif
-
- dev = open_driver (name, ebuf, promisc);
- if (!dev)
- {
-#ifdef USE_32BIT_DRIVERS
- k_free (rx_pool);
- rx_pool = NULL;
-#endif
-
-#ifdef __DJGPP__
- setup_signals (SIG_DFL);
-#endif
- return (0);
- }
-
-#ifdef USE_32BIT_DRIVERS
- /*
- * If driver is NOT a 16-bit "pkt/ndis" driver (having a 'copy_rx_buf'
- * set in it's probe handler), initialize near-memory ring-buffer for
- * the 32-bit device.
- */
- if (dev->copy_rx_buf == NULL)
- {
- dev->get_rx_buf = get_rxbuf;
- dev->peek_rx_buf = peek_rxbuf;
- dev->release_rx_buf = release_rxbuf;
- pktq_init (&dev->queue, RECEIVE_BUF_SIZE, RECEIVE_QUEUE_SIZE, rx_pool);
- }
-#endif
- return (1);
-}
-
-#ifdef USE_32BIT_DRIVERS
-static void init_32bit (void)
-{
- static int init_pci = 0;
-
- if (!_printk_file)
- _printk_init (64*1024, NULL); /* calls atexit(printk_exit) */
-
- if (!init_pci)
- (void)pci_init(); /* init BIOS32+PCI interface */
- init_pci = 1;
-}
-#endif
-
-
-/*
- * Hook functions for using Watt-32 together with pcap
- */
-static char rxbuf [ETH_MAX+100]; /* rx-buffer with some margin */
-static WORD etype;
-static pcap_t pcap_save;
-
-static void watt32_recv_hook (u_char *dummy, const struct pcap_pkthdr *pcap,
- const u_char *buf)
-{
- /* Fix me: assumes Ethernet II only */
- struct ether_header *ep = (struct ether_header*) buf;
-
- memcpy (rxbuf, buf, pcap->caplen);
- etype = ep->ether_type;
- ARGSUSED (dummy);
-}
-
-#if (WATTCP_VER >= 0x0224)
-/*
- * This function is used by Watt-32 to poll for a packet.
- * i.e. it's set to bypass _eth_arrived()
- */
-static void *pcap_recv_hook (WORD *type)
-{
- int len = pcap_read_dos (&pcap_save, 1, watt32_recv_hook, NULL);
-
- if (len < 0)
- return (NULL);
-
- *type = etype;
- return (void*) &rxbuf;
-}
-
-/*
- * This function is called by Watt-32 (via _eth_xmit_hook).
- * If dbug_init() was called, we should trace packets sent.
- */
-static int pcap_xmit_hook (const void *buf, unsigned len)
-{
- int rc = 0;
-
- if (pcap_pkt_debug > 0)
- dbug_write ("pcap_xmit_hook: ");
-
- if (active_dev && active_dev->xmit)
- if ((*active_dev->xmit) (active_dev, buf, len) > 0)
- rc = len;
-
- if (pcap_pkt_debug > 0)
- dbug_write (rc ? "ok\n" : "fail\n");
- return (rc);
-}
-#endif
-
-static int pcap_sendpacket_dos (pcap_t *p, const void *buf, size_t len)
-{
- struct device *dev = p ? get_device(p->fd) : NULL;
-
- if (!dev || !dev->xmit)
- return (-1);
- return (*dev->xmit) (dev, buf, len);
-}
-
-/*
- * This function is called by Watt-32 in tcp_post_init().
- * We should prevent Watt-32 from using BOOTP/DHCP/RARP etc.
- */
-static void (*prev_post_hook) (void);
-
-static void pcap_init_hook (void)
-{
- _w32__bootp_on = _w32__dhcp_on = _w32__rarp_on = 0;
- _w32__do_mask_req = 0;
- _w32_dynamic_host = 0;
- if (prev_post_hook)
- (*prev_post_hook)();
-}
-
-/*
- * Suppress PRINT message from Watt-32's sock_init()
- */
-static void null_print (void) {}
-
-/*
- * To use features of Watt-32 (netdb functions and socket etc.)
- * we must call sock_init(). But we set various hooks to prevent
- * using normal PKTDRVR functions in pcpkt.c. This should hopefully
- * make Watt-32 and pcap co-operate.
- */
-static int init_watt32 (struct pcap *pcap, const char *dev_name, char *err_buf)
-{
- char *env;
- int rc, MTU, has_ip_addr;
- int using_pktdrv = 1;
-
- /* If user called sock_init() first, we need to reinit in
- * order to open debug/trace-file properly
- */
- if (_watt_is_init)
- sock_exit();
-
- env = getenv ("PCAP_TRACE");
- if (env && atoi(env) > 0 &&
- pcap_pkt_debug < 0) /* if not already set */
- {
- dbug_init();
- pcap_pkt_debug = atoi (env);
- }
-
- _watt_do_exit = 0; /* prevent sock_init() calling exit() */
- prev_post_hook = _w32_usr_post_init;
- _w32_usr_post_init = pcap_init_hook;
- _w32_print_hook = null_print;
-
- if (dev_name && strncmp(dev_name,"pkt",3))
- using_pktdrv = FALSE;
-
- rc = sock_init();
- has_ip_addr = (rc != 8); /* IP-address assignment failed */
-
- /* if pcap is using a 32-bit driver w/o a pktdrvr loaded, we
- * just pretend Watt-32 is initialized okay.
- *
- * !! fix-me: The Watt-32 config isn't done if no pktdrvr
- * was found. In that case my_ip_addr + sin_mask
- * have default values. Should be taken from another
- * ini-file/environment in any case (ref. tcpdump.ini)
- */
- _watt_is_init = 1;
-
- if (!using_pktdrv || !has_ip_addr) /* for now .... */
- {
- static const char myip[] = "192.168.0.1";
- static const char mask[] = "255.255.255.0";
-
- printf ("Just guessing, using IP %s and netmask %s\n", myip, mask);
- my_ip_addr = aton (myip);
- _w32_sin_mask = aton (mask);
- }
- else if (rc && using_pktdrv)
- {
- snprintf (err_buf, PCAP_ERRBUF_SIZE, "sock_init() failed, code %d", rc);
- return (0);
- }
-
- /* Set recv-hook for peeking in _eth_arrived().
- */
-#if (WATTCP_VER >= 0x0224)
- _eth_recv_hook = pcap_recv_hook;
- _eth_xmit_hook = pcap_xmit_hook;
-#endif
-
- /* Free the pkt-drvr handle allocated in pkt_init().
- * The above hooks should thus use the handle reopened in open_driver()
- */
- if (using_pktdrv)
- {
- _eth_release();
-/* _eth_is_init = 1; */ /* hack to get Rx/Tx-hooks in Watt-32 working */
- }
-
- memcpy (&pcap_save, pcap, sizeof(pcap_save));
- MTU = pkt_get_mtu();
- pcap_save.fcode.bf_insns = NULL;
- pcap_save.linktype = _eth_get_hwtype (NULL, NULL);
- pcap_save.snapshot = MTU > 0 ? MTU : ETH_MAX; /* assume 1514 */
-
- /* prevent use of resolve() and resolve_ip()
- */
- last_nameserver = 0;
- return (1);
-}
-
-int EISA_bus = 0; /* Where is natural place for this? */
-
-/*
- * Application config hooks to set various driver parameters.
- */
-
-static const struct config_table debug_tab[] = {
- { "PKT.DEBUG", ARG_ATOI, &pcap_pkt_debug },
- { "PKT.VECTOR", ARG_ATOX_W, NULL },
- { "NDIS.DEBUG", ARG_ATOI, NULL },
-#ifdef USE_32BIT_DRIVERS
- { "3C503.DEBUG", ARG_ATOI, &ei_debug },
- { "3C503.IO_BASE", ARG_ATOX_W, &el2_dev.base_addr },
- { "3C503.MEMORY", ARG_ATOX_W, &el2_dev.mem_start },
- { "3C503.IRQ", ARG_ATOI, &el2_dev.irq },
- { "3C505.DEBUG", ARG_ATOI, NULL },
- { "3C505.BASE", ARG_ATOX_W, NULL },
- { "3C507.DEBUG", ARG_ATOI, NULL },
- { "3C509.DEBUG", ARG_ATOI, &el3_debug },
- { "3C509.ILOOP", ARG_ATOI, &el3_max_loop },
- { "3C529.DEBUG", ARG_ATOI, NULL },
- { "3C575.DEBUG", ARG_ATOI, &debug_3c575 },
- { "3C59X.DEBUG", ARG_ATOI, &vortex_debug },
- { "3C59X.IFACE0", ARG_ATOI, &vortex_options[0] },
- { "3C59X.IFACE1", ARG_ATOI, &vortex_options[1] },
- { "3C59X.IFACE2", ARG_ATOI, &vortex_options[2] },
- { "3C59X.IFACE3", ARG_ATOI, &vortex_options[3] },
- { "3C90X.DEBUG", ARG_ATOX_W, &tc90xbc_debug },
- { "ACCT.DEBUG", ARG_ATOI, &ethpk_debug },
- { "CS89.DEBUG", ARG_ATOI, &cs89_debug },
- { "RTL8139.DEBUG", ARG_ATOI, &rtl8139_debug },
- /* { "RTL8139.FDUPLEX", ARG_ATOI, &rtl8139_options }, */
- { "SMC.DEBUG", ARG_ATOI, &ei_debug },
- /* { "E100.DEBUG", ARG_ATOI, &e100_debug }, */
- { "PCI.DEBUG", ARG_ATOI, &pci_debug },
- { "BIOS32.DEBUG", ARG_ATOI, &bios32_debug },
- { "IRQ.DEBUG", ARG_ATOI, &irq_debug },
- { "TIMER.IRQ", ARG_ATOI, &timer_irq },
-#endif
- { NULL }
- };
-
-/*
- * pcap_config_hook() is an extension to application's config
- * handling. Uses Watt-32's config-table function.
- */
-int pcap_config_hook (const char *keyword, const char *value)
-{
- return parse_config_table (debug_tab, NULL, keyword, value);
-}
-
-/*
- * Linked list of supported devices
- */
-struct device *active_dev = NULL; /* the device we have opened */
-struct device *probed_dev = NULL; /* the device we have probed */
-const struct device *dev_base = &pkt_dev; /* list of network devices */
-
-/*
- * PKTDRVR device functions
- */
-int pcap_pkt_debug = -1;
-
-static void pkt_close (struct device *dev)
-{
- BOOL okay = PktExitDriver();
-
- if (pcap_pkt_debug > 1)
- fprintf (stderr, "pkt_close(): %d\n", okay);
-
- if (dev->priv)
- free (dev->priv);
- dev->priv = NULL;
-}
-
-static int pkt_open (struct device *dev)
-{
- PKT_RX_MODE mode;
-
- if (dev->flags & IFF_PROMISC)
- mode = PDRX_ALL_PACKETS;
- else mode = PDRX_BROADCAST;
-
- if (!PktInitDriver(mode))
- return (0);
-
- PktResetStatistics (pktInfo.handle);
- PktQueueBusy (FALSE);
- return (1);
-}
-
-static int pkt_xmit (struct device *dev, const void *buf, int len)
-{
- struct net_device_stats *stats = (struct net_device_stats*) dev->priv;
-
- if (pcap_pkt_debug > 0)
- dbug_write ("pcap_xmit\n");
-
- if (!PktTransmit(buf,len))
- {
- stats->tx_errors++;
- return (0);
- }
- return (len);
-}
-
-static void *pkt_stats (struct device *dev)
-{
- struct net_device_stats *stats = (struct net_device_stats*) dev->priv;
-
- if (!stats || !PktSessStatistics(pktInfo.handle))
- return (NULL);
-
- stats->rx_packets = pktStat.inPackets;
- stats->rx_errors = pktStat.lost;
- stats->rx_missed_errors = PktRxDropped();
- return (stats);
-}
-
-static int pkt_probe (struct device *dev)
-{
- if (!PktSearchDriver())
- return (0);
-
- dev->open = pkt_open;
- dev->xmit = pkt_xmit;
- dev->close = pkt_close;
- dev->get_stats = pkt_stats;
- dev->copy_rx_buf = PktReceive; /* farmem peek and copy routine */
- dev->get_rx_buf = NULL;
- dev->peek_rx_buf = NULL;
- dev->release_rx_buf = NULL;
- dev->priv = calloc (sizeof(struct net_device_stats), 1);
- if (!dev->priv)
- return (0);
- return (1);
-}
-
-/*
- * NDIS device functions
- */
-static void ndis_close (struct device *dev)
-{
-#ifdef USE_NDIS2
- NdisShutdown();
-#endif
- ARGSUSED (dev);
-}
-
-static int ndis_open (struct device *dev)
-{
- int promisc = (dev->flags & IFF_PROMISC);
-
-#ifdef USE_NDIS2
- if (!NdisInit(promisc))
- return (0);
- return (1);
-#else
- ARGSUSED (promisc);
- return (0);
-#endif
-}
-
-static void *ndis_stats (struct device *dev)
-{
- static struct net_device_stats stats;
-
- /* to-do */
- ARGSUSED (dev);
- return (&stats);
-}
-
-static int ndis_probe (struct device *dev)
-{
-#ifdef USE_NDIS2
- if (!NdisOpen())
- return (0);
-#endif
-
- dev->open = ndis_open;
- dev->xmit = NULL;
- dev->close = ndis_close;
- dev->get_stats = ndis_stats;
- dev->copy_rx_buf = NULL; /* to-do */
- dev->get_rx_buf = NULL; /* upcall is from rmode driver */
- dev->peek_rx_buf = NULL;
- dev->release_rx_buf = NULL;
- return (0);
-}
-
-/*
- * Search & probe for supported 32-bit (pmode) pcap devices
- */
-#if defined(USE_32BIT_DRIVERS)
-
-struct device el2_dev LOCKED_VAR = {
- "3c503",
- "EtherLink II",
- 0,
- 0,0,0,0,0,0,
- NULL,
- el2_probe
- };
-
-struct device el3_dev LOCKED_VAR = {
- "3c509",
- "EtherLink III",
- 0,
- 0,0,0,0,0,0,
- &el2_dev,
- el3_probe
- };
-
-struct device tc515_dev LOCKED_VAR = {
- "3c515",
- "EtherLink PCI",
- 0,
- 0,0,0,0,0,0,
- &el3_dev,
- tc515_probe
- };
-
-struct device tc59_dev LOCKED_VAR = {
- "3c59x",
- "EtherLink PCI",
- 0,
- 0,0,0,0,0,0,
- &tc515_dev,
- tc59x_probe
- };
-
-struct device tc90xbc_dev LOCKED_VAR = {
- "3c90x",
- "EtherLink 90X",
- 0,
- 0,0,0,0,0,0,
- &tc59_dev,
- tc90xbc_probe
- };
-
-struct device wd_dev LOCKED_VAR = {
- "wd",
- "Western Digital",
- 0,
- 0,0,0,0,0,0,
- &tc90xbc_dev,
- wd_probe
- };
-
-struct device ne_dev LOCKED_VAR = {
- "ne",
- "NEx000",
- 0,
- 0,0,0,0,0,0,
- &wd_dev,
- ne_probe
- };
-
-struct device acct_dev LOCKED_VAR = {
- "acct",
- "Accton EtherPocket",
- 0,
- 0,0,0,0,0,0,
- &ne_dev,
- ethpk_probe
- };
-
-struct device cs89_dev LOCKED_VAR = {
- "cs89",
- "Crystal Semiconductor",
- 0,
- 0,0,0,0,0,0,
- &acct_dev,
- cs89x0_probe
- };
-
-struct device rtl8139_dev LOCKED_VAR = {
- "rtl8139",
- "RealTek PCI",
- 0,
- 0,0,0,0,0,0,
- &cs89_dev,
- rtl8139_probe /* dev->probe routine */
- };
-
-/*
- * Dequeue routine is called by polling.
- * NOTE: the queue-element is not copied, only a pointer is
- * returned at '*buf'
- */
-int peek_rxbuf (BYTE **buf)
-{
- struct rx_elem *tail, *head;
-
- PCAP_ASSERT (pktq_check (&active_dev->queue));
-
- DISABLE();
- tail = pktq_out_elem (&active_dev->queue);
- head = pktq_in_elem (&active_dev->queue);
- ENABLE();
-
- if (head != tail)
- {
- PCAP_ASSERT (tail->size < active_dev->queue.elem_size-4-2);
-
- *buf = &tail->data[0];
- return (tail->size);
- }
- *buf = NULL;
- return (0);
-}
-
-/*
- * Release buffer we peeked at above.
- */
-int release_rxbuf (BYTE *buf)
-{
-#ifndef NDEBUG
- struct rx_elem *tail = pktq_out_elem (&active_dev->queue);
-
- PCAP_ASSERT (&tail->data[0] == buf);
-#else
- ARGSUSED (buf);
-#endif
- pktq_inc_out (&active_dev->queue);
- return (1);
-}
-
-/*
- * get_rxbuf() routine (in locked code) is called from IRQ handler
- * to request a buffer. Interrupts are disabled and we have a 32kB stack.
- */
-BYTE *get_rxbuf (int len)
-{
- int idx;
-
- if (len < ETH_MIN || len > ETH_MAX)
- return (NULL);
-
- idx = pktq_in_index (&active_dev->queue);
-
-#ifdef DEBUG
- {
- static int fan_idx LOCKED_VAR = 0;
- writew ("-\\|/"[fan_idx++] | (15 << 8), /* white on black colour */
- 0xB8000 + 2*79); /* upper-right corner, 80-col colour screen */
- fan_idx &= 3;
- }
-/* writew (idx + '0' + 0x0F00, 0xB8000 + 2*78); */
-#endif
-
- if (idx != active_dev->queue.out_index)
- {
- struct rx_elem *head = pktq_in_elem (&active_dev->queue);
-
- head->size = len;
- active_dev->queue.in_index = idx;
- return (&head->data[0]);
- }
-
- /* !!to-do: drop 25% of the oldest element
- */
- pktq_clear (&active_dev->queue);
- return (NULL);
-}
-
-/*
- * Simple ring-buffer queue handler for reception of packets
- * from network driver.
- */
-#define PKTQ_MARKER 0xDEADBEEF
-
-static int pktq_check (struct rx_ringbuf *q)
-{
-#ifndef NDEBUG
- int i;
- char *buf;
-#endif
-
- if (!q || !q->num_elem || !q->buf_start)
- return (0);
-
-#ifndef NDEBUG
- buf = q->buf_start;
-
- for (i = 0; i < q->num_elem; i++)
- {
- buf += q->elem_size;
- if (*(DWORD*)(buf - sizeof(DWORD)) != PKTQ_MARKER)
- return (0);
- }
-#endif
- return (1);
-}
-
-static int pktq_init (struct rx_ringbuf *q, int size, int num, char *pool)
-{
- int i;
-
- q->elem_size = size;
- q->num_elem = num;
- q->buf_start = pool;
- q->in_index = 0;
- q->out_index = 0;
-
- PCAP_ASSERT (size >= sizeof(struct rx_elem) + sizeof(DWORD));
- PCAP_ASSERT (num);
- PCAP_ASSERT (pool);
-
- for (i = 0; i < num; i++)
- {
-#if 0
- struct rx_elem *elem = (struct rx_elem*) pool;
-
- /* assert dword aligned elements
- */
- PCAP_ASSERT (((unsigned)(&elem->data[0]) & 3) == 0);
-#endif
- pool += size;
- *(DWORD*) (pool - sizeof(DWORD)) = PKTQ_MARKER;
- }
- return (1);
-}
-
-/*
- * Increment the queue 'out_index' (tail).
- * Check for wraps.
- */
-static int pktq_inc_out (struct rx_ringbuf *q)
-{
- q->out_index++;
- if (q->out_index >= q->num_elem)
- q->out_index = 0;
- return (q->out_index);
-}
-
-/*
- * Return the queue's next 'in_index' (head).
- * Check for wraps.
- */
-static int pktq_in_index (struct rx_ringbuf *q)
-{
- volatile int index = q->in_index + 1;
-
- if (index >= q->num_elem)
- index = 0;
- return (index);
-}
-
-/*
- * Return the queue's head-buffer.
- */
-static struct rx_elem *pktq_in_elem (struct rx_ringbuf *q)
-{
- return (struct rx_elem*) (q->buf_start + (q->elem_size * q->in_index));
-}
-
-/*
- * Return the queue's tail-buffer.
- */
-static struct rx_elem *pktq_out_elem (struct rx_ringbuf *q)
-{
- return (struct rx_elem*) (q->buf_start + (q->elem_size * q->out_index));
-}
-
-/*
- * Clear the queue ring-buffer by setting head=tail.
- */
-static void pktq_clear (struct rx_ringbuf *q)
-{
- q->in_index = q->out_index;
-}
-
-/*
- * Symbols that must be linkable for "gcc -O0"
- */
-#undef __IOPORT_H
-#undef __DMA_H
-
-#define extern
-#define __inline__
-
-#include "msdos/pm_drvr/ioport.h"
-#include "msdos/pm_drvr/dma.h"
-
-#endif /* USE_32BIT_DRIVERS */
-
-/*
- * Libpcap version string.
- */
-const char *
-pcap_lib_version(void)
-{
- return ("DOS-" PCAP_VERSION_STRING);
-}
diff --git a/pcap-dos.h b/pcap-dos.h
deleted file mode 100644
index bf47fb51..00000000
--- a/pcap-dos.h
+++ /dev/null
@@ -1,225 +0,0 @@
-/*
- * Internal details for libpcap on DOS.
- * 32-bit targets: djgpp, Pharlap or DOS4GW.
- */
-
-#ifndef __PCAP_DOS_H
-#define __PCAP_DOS_H
-
-#ifdef __DJGPP__
-#include <pc.h> /* simple non-conio kbhit */
-#else
-#include <conio.h>
-#endif
-
-typedef int BOOL;
-typedef unsigned char BYTE;
-typedef unsigned short WORD;
-typedef unsigned long DWORD;
-typedef BYTE ETHER[6];
-
-#define ETH_ALEN sizeof(ETHER) /* Ether address length */
-#define ETH_HLEN (2*ETH_ALEN+2) /* Ether header length */
-#define ETH_MTU 1500
-#define ETH_MIN 60
-#define ETH_MAX (ETH_MTU+ETH_HLEN)
-
-#ifndef TRUE
- #define TRUE 1
- #define FALSE 0
-#endif
-
-#define PHARLAP 1
-#define DJGPP 2
-#define DOS4GW 4
-
-#ifdef __DJGPP__
- #undef DOSX
- #define DOSX DJGPP
-#endif
-
-#ifdef __WATCOMC__
- #undef DOSX
- #define DOSX DOS4GW
-#endif
-
-#ifdef __HIGHC__
- #include <pharlap.h>
- #undef DOSX
- #define DOSX PHARLAP
- #define inline
-#else
- typedef unsigned int UINT;
-#endif
-
-
-#if defined(__GNUC__) || defined(__HIGHC__)
- typedef unsigned long long uint64;
- typedef unsigned long long QWORD;
-#endif
-
-#if defined(__WATCOMC__)
- typedef unsigned __int64 uint64;
- typedef unsigned __int64 QWORD;
-#endif
-
-#define ARGSUSED(x) (void) x
-
-#if defined (__SMALL__) || defined(__LARGE__)
- #define DOSX 0
-
-#elif !defined(DOSX)
- #error DOSX not defined; 1 = PharLap, 2 = djgpp, 4 = DOS4GW
-#endif
-
-#ifdef __HIGHC__
-#define min(a,b) _min(a,b)
-#define max(a,b) _max(a,b)
-#endif
-
-#ifndef min
-#define min(a,b) ((a) < (b) ? (a) : (b))
-#endif
-
-#ifndef max
-#define max(a,b) ((a) < (b) ? (b) : (a))
-#endif
-
-#if !defined(_U_) && defined(__GNUC__)
-#define _U_ __attribute__((unused))
-#endif
-
-#ifndef _U_
-#define _U_
-#endif
-
-#if defined(USE_32BIT_DRIVERS)
- #include "msdos/pm_drvr/lock.h"
-
- #ifndef RECEIVE_QUEUE_SIZE
- #define RECEIVE_QUEUE_SIZE 60
- #endif
-
- #ifndef RECEIVE_BUF_SIZE
- #define RECEIVE_BUF_SIZE (ETH_MAX+20)
- #endif
-
- extern struct device el2_dev LOCKED_VAR; /* 3Com EtherLink II */
- extern struct device el3_dev LOCKED_VAR; /* EtherLink III */
- extern struct device tc59_dev LOCKED_VAR; /* 3Com Vortex Card (?) */
- extern struct device tc515_dev LOCKED_VAR;
- extern struct device tc90x_dev LOCKED_VAR;
- extern struct device tc90bcx_dev LOCKED_VAR;
- extern struct device wd_dev LOCKED_VAR;
- extern struct device ne_dev LOCKED_VAR;
- extern struct device acct_dev LOCKED_VAR;
- extern struct device cs89_dev LOCKED_VAR;
- extern struct device rtl8139_dev LOCKED_VAR;
-
- struct rx_ringbuf {
- volatile int in_index; /* queue index head */
- int out_index; /* queue index tail */
- int elem_size; /* size of each element */
- int num_elem; /* number of elements */
- char *buf_start; /* start of buffer pool */
- };
-
- struct rx_elem {
- DWORD size; /* size copied to this element */
- BYTE data[ETH_MAX+10]; /* add some margin. data[0] should be */
- }; /* dword aligned */
-
- extern BYTE *get_rxbuf (int len) LOCKED_FUNC;
- extern int peek_rxbuf (BYTE **buf);
- extern int release_rxbuf (BYTE *buf);
-
-#else
- #define LOCKED_VAR
- #define LOCKED_FUNC
-
- struct device {
- const char *name;
- const char *long_name;
- DWORD base_addr; /* device I/O address */
- int irq; /* device IRQ number */
- int dma; /* DMA channel */
- DWORD mem_start; /* shared mem start */
- DWORD mem_end; /* shared mem end */
- DWORD rmem_start; /* shmem "recv" start */
- DWORD rmem_end; /* shared "recv" end */
-
- struct device *next; /* next device in list */
-
- /* interface service routines */
- int (*probe)(struct device *dev);
- int (*open) (struct device *dev);
- void (*close)(struct device *dev);
- int (*xmit) (struct device *dev, const void *buf, int len);
- void *(*get_stats)(struct device *dev);
- void (*set_multicast_list)(struct device *dev);
-
- /* driver-to-pcap receive buffer routines */
- int (*copy_rx_buf) (BYTE *buf, int max); /* rx-copy (pktdrvr only) */
- BYTE *(*get_rx_buf) (int len); /* rx-buf fetch/enqueue */
- int (*peek_rx_buf) (BYTE **buf); /* rx-non-copy at queue */
- int (*release_rx_buf) (BYTE *buf); /* release after peek */
-
- WORD flags; /* Low-level status flags. */
- void *priv; /* private data */
- };
-
- /*
- * Network device statistics
- */
- typedef struct net_device_stats {
- DWORD rx_packets; /* total packets received */
- DWORD tx_packets; /* total packets transmitted */
- DWORD rx_bytes; /* total bytes received */
- DWORD tx_bytes; /* total bytes transmitted */
- DWORD rx_errors; /* bad packets received */
- DWORD tx_errors; /* packet transmit problems */
- DWORD rx_dropped; /* no space in Rx buffers */
- DWORD tx_dropped; /* no space available for Tx */
- DWORD multicast; /* multicast packets received */
-
- /* detailed rx_errors: */
- DWORD rx_length_errors;
- DWORD rx_over_errors; /* recv'r overrun error */
- DWORD rx_osize_errors; /* recv'r over-size error */
- DWORD rx_crc_errors; /* recv'd pkt with crc error */
- DWORD rx_frame_errors; /* recv'd frame alignment error */
- DWORD rx_fifo_errors; /* recv'r fifo overrun */
- DWORD rx_missed_errors; /* recv'r missed packet */
-
- /* detailed tx_errors */
- DWORD tx_aborted_errors;
- DWORD tx_carrier_errors;
- DWORD tx_fifo_errors;
- DWORD tx_heartbeat_errors;
- DWORD tx_window_errors;
- DWORD tx_collisions;
- DWORD tx_jabbers;
- } NET_STATS;
-#endif
-
-extern struct device *active_dev LOCKED_VAR;
-extern const struct device *dev_base LOCKED_VAR;
-extern struct device *probed_dev;
-
-extern int pcap_pkt_debug;
-
-extern void _w32_os_yield (void); /* Watt-32's misc.c */
-
-#ifdef NDEBUG
- #define PCAP_ASSERT(x) ((void)0)
-
-#else
- void pcap_assert (const char *what, const char *file, unsigned line);
-
- #define PCAP_ASSERT(x) do { \
- if (!(x)) \
- pcap_assert (#x, __FILE__, __LINE__); \
- } while (0)
-#endif
-
-#endif /* __PCAP_DOS_H */
diff --git a/pcap-int.h b/pcap-int.h
index 48948238..c4f5e713 100644
--- a/pcap-int.h
+++ b/pcap-int.h
@@ -40,11 +40,6 @@
#include <pcap/pcap.h>
-#ifdef MSDOS
- #include <fcntl.h>
- #include <io.h>
-#endif
-
#include "varattrs.h"
#include "fmtutils.h"
@@ -293,7 +288,7 @@ struct pcap {
*/
int bpf_codegen_flags;
-#if !defined(_WIN32) && !defined(MSDOS)
+#if !defined(_WIN32)
int selectable_fd; /* FD on which select()/poll()/epoll_wait()/kevent()/etc. can be done */
/*
@@ -469,7 +464,7 @@ int pcap_offline_read(pcap_t *, int, pcap_handler, u_char *);
/*
* Routines that most pcap implementations can use for non-blocking mode.
*/
-#if !defined(_WIN32) && !defined(MSDOS)
+#if !defined(_WIN32)
int pcap_getnonblock_fd(pcap_t *);
int pcap_setnonblock_fd(pcap_t *p, int);
#endif
@@ -533,7 +528,7 @@ struct pcap_if_list;
typedef struct pcap_if_list pcap_if_list_t;
typedef int (*get_if_flags_func)(const char *, bpf_u_int32 *, char *);
int pcap_platform_finddevs(pcap_if_list_t *, char *);
-#if !defined(_WIN32) && !defined(MSDOS)
+#if !defined(_WIN32)
int pcap_findalldevs_interfaces(pcap_if_list_t *, char *,
int (*)(const char *), get_if_flags_func);
#endif
diff --git a/pcap.c b/pcap.c
index 2db694a2..d8b0e775 100644
--- a/pcap.c
+++ b/pcap.c
@@ -38,9 +38,7 @@
#include <pcap-types.h>
#ifndef _WIN32
#include <sys/param.h>
-#ifndef MSDOS
#include <sys/file.h>
-#endif
#include <sys/ioctl.h>
#include <sys/socket.h>
#ifdef HAVE_SYS_SOCKIO_H
@@ -71,10 +69,6 @@ struct rtentry; /* declarations in <net/if.h> */
#include "os-proto.h"
#endif
-#ifdef MSDOS
-#include "pcap-dos.h"
-#endif
-
#include "pcap-int.h"
#include "optimize.h"
@@ -1508,13 +1502,10 @@ pcap_freealldevs(pcap_if_t *alldevs)
* it actually returns the names of all interfaces, with a NUL separator
* between them; some callers may depend on that.
*
- * MS-DOS has its own pcap_lookupdev(), but that might be useful only
- * as an optimization.
- *
* In all other cases, we just use pcap_findalldevs() to get a list of
* devices, and pick from that list.
*/
-#if !defined(HAVE_PACKET32) && !defined(MSDOS)
+#if !defined(HAVE_PACKET32)
/*
* Return the name of a network interface attached to the system, or NULL
* if none can be found. The interface must be configured up; the
@@ -1585,9 +1576,9 @@ pcap_lookupdev(char *errbuf)
pcap_freealldevs(alldevs);
return (ret);
}
-#endif /* !defined(HAVE_PACKET32) && !defined(MSDOS) */
+#endif /* !defined(HAVE_PACKET32) */
-#if !defined(_WIN32) && !defined(MSDOS)
+#if !defined(_WIN32)
/*
* We don't just fetch the entire list of devices, search for the
* particular device, and use its first IPv4 address, as that's too
@@ -1709,7 +1700,7 @@ pcap_lookupnet(const char *device, bpf_u_int32 *netp, bpf_u_int32 *maskp,
*netp &= *maskp;
return (0);
}
-#endif /* !defined(_WIN32) && !defined(MSDOS) */
+#endif /* !defined(_WIN32) */
#ifdef ENABLE_REMOTE
#include "pcap-rpcap.h"
@@ -2512,10 +2503,8 @@ pcap_alloc_pcap_t(char *ebuf, size_t total_size, size_t private_offset)
p->handle = INVALID_HANDLE_VALUE; /* not opened yet */
#else /* _WIN32 */
p->fd = -1; /* not opened yet */
-#ifndef MSDOS
p->selectable_fd = -1;
p->required_select_timeout = NULL;
-#endif /* MSDOS */
#endif /* _WIN32 */
/*
@@ -3565,7 +3554,7 @@ pcap_fileno(pcap_t *p)
}
#endif /* _WIN32 */
-#if !defined(_WIN32) && !defined(MSDOS)
+#if !defined(_WIN32)
int
pcap_get_selectable_fd(pcap_t *p)
{
@@ -3616,7 +3605,7 @@ pcap_getnonblock(pcap_t *p, char *errbuf)
* Get the current non-blocking mode setting, under the assumption that
* it's just the standard POSIX non-blocking flag.
*/
-#if !defined(_WIN32) && !defined(MSDOS)
+#if !defined(_WIN32)
int
pcap_getnonblock_fd(pcap_t *p)
{
@@ -3656,7 +3645,7 @@ pcap_setnonblock(pcap_t *p, int nonblock, char *errbuf)
return (ret);
}
-#if !defined(_WIN32) && !defined(MSDOS)
+#if !defined(_WIN32)
/*
* Set non-blocking mode, under the assumption that it's just the
* standard POSIX non-blocking flag. (This can be called by the
@@ -4094,7 +4083,7 @@ pcap_cleanup_live_common(pcap_t *p)
p->tstamp_precision_count = 0;
}
pcap_freecode(&p->fcode);
-#if !defined(_WIN32) && !defined(MSDOS)
+#if !defined(_WIN32)
if (p->fd >= 0) {
close(p->fd);
p->fd = -1;
diff --git a/savefile.c b/savefile.c
index 3bf2e77b..1fc7e011 100644
--- a/savefile.c
+++ b/savefile.c
@@ -77,12 +77,6 @@ static pcap_t *pcap_fopen_offline_with_tstamp_precision(FILE *, u_int, char *);
*/
#if defined(_WIN32)
#define SET_BINMODE(f) _setmode(_fileno(f), _O_BINARY)
-#elif defined(MSDOS)
- #if defined(__HIGHC__)
- #define SET_BINMODE(f) setmode(f, O_BINARY)
- #else
- #define SET_BINMODE(f) setmode(fileno(f), O_BINARY)
- #endif
#endif
static int
diff --git a/sf-pcap.c b/sf-pcap.c
index 54b5c851..2c310773 100644
--- a/sf-pcap.c
+++ b/sf-pcap.c
@@ -61,12 +61,6 @@
*/
#if defined(_WIN32)
#define SET_BINMODE(f) _setmode(_fileno(f), _O_BINARY)
-#elif defined(MSDOS)
- #if defined(__HIGHC__)
- #define SET_BINMODE(f) setmode(f, O_BINARY)
- #else
- #define SET_BINMODE(f) setmode(fileno(f), O_BINARY)
- #endif
#endif
/*