From Gisle Vanem: MS-DOS support.
This commit is contained in:
parent
f912cc399c
commit
f8a76d1d76
15
FILES
15
FILES
|
@ -53,6 +53,19 @@ lbl/os-ultrix4.h
|
|||
llc.h
|
||||
missing/snprintf.c
|
||||
mkdep
|
||||
msdos/bin2c.c
|
||||
msdos/common.dj
|
||||
msdos/makefile
|
||||
msdos/makefile.dj
|
||||
msdos/makefile.wc
|
||||
msdos/ndis2.c
|
||||
msdos/ndis2.h
|
||||
msdos/ndis_0.asm
|
||||
msdos/pkt_rx0.asm
|
||||
msdos/pkt_rx1.s
|
||||
msdos/pktdrvr.c
|
||||
msdos/pktdrvr.h
|
||||
msdos/readme.dos
|
||||
nametoaddr.c
|
||||
nlpid.h
|
||||
optimize.c
|
||||
|
@ -63,6 +76,8 @@ pcap-bpf.h
|
|||
pcap-dag.c
|
||||
pcap-dag.h
|
||||
pcap-dlpi.c
|
||||
pcap-dos.c
|
||||
pcap-dos.h
|
||||
pcap-enet.c
|
||||
pcap-int.h
|
||||
pcap-linux.c
|
||||
|
|
|
@ -1,4 +1,4 @@
|
|||
@(#) $Header: /tcpdump/master/libpcap/INSTALL.txt,v 1.11 2004-10-18 09:51:02 guy Exp $ (LBL)
|
||||
@(#) $Header: /tcpdump/master/libpcap/INSTALL.txt,v 1.12 2004-12-18 08:52:08 guy Exp $ (LBL)
|
||||
|
||||
To build libpcap, run "./configure" (a shell script). The configure
|
||||
script will determine your system attributes and generate an
|
||||
|
@ -341,6 +341,7 @@ lbl/os-*.h - OS-dependent defines and prototypes
|
|||
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
|
||||
nlpid.h - OSI network layer protocol identifier definitions
|
||||
net - symlink to bpf/net
|
||||
|
@ -351,6 +352,8 @@ pcap-bpf.h - BPF definitions
|
|||
pcap-dag.c - Endace DAG device capture support
|
||||
pcap-dag.h - Endace DAG device 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-enet.c - enet support
|
||||
pcap-int.h - internal libpcap definitions
|
||||
pcap-linux.c - Linux packet socket support
|
||||
|
|
|
@ -21,7 +21,7 @@
|
|||
*/
|
||||
#ifndef lint
|
||||
static const char rcsid[] _U_ =
|
||||
"@(#) $Header: /tcpdump/master/libpcap/gencode.c,v 1.214 2004-12-17 20:16:44 guy Exp $ (LBL)";
|
||||
"@(#) $Header: /tcpdump/master/libpcap/gencode.c,v 1.215 2004-12-18 08:52:09 guy Exp $ (LBL)";
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
|
@ -58,6 +58,10 @@ static const char rcsid[] _U_ =
|
|||
#include <setjmp.h>
|
||||
#include <stdarg.h>
|
||||
|
||||
#ifdef MSDOS
|
||||
#include "pcap-dos.h"
|
||||
#endif
|
||||
|
||||
#include "pcap-int.h"
|
||||
|
||||
#include "ethertype.h"
|
||||
|
|
14
inet.c
14
inet.c
|
@ -34,7 +34,7 @@
|
|||
|
||||
#ifndef lint
|
||||
static const char rcsid[] _U_ =
|
||||
"@(#) $Header: /tcpdump/master/libpcap/inet.c,v 1.62 2004-12-17 20:32:35 guy Exp $ (LBL)";
|
||||
"@(#) $Header: /tcpdump/master/libpcap/inet.c,v 1.63 2004-12-18 08:52:09 guy Exp $ (LBL)";
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
|
@ -46,7 +46,9 @@ static const char rcsid[] _U_ =
|
|||
#else /* 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
|
||||
|
@ -65,9 +67,9 @@ struct rtentry; /* declarations in <net/if.h> */
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#ifndef WIN32
|
||||
#if !defined(WIN32) && !defined(__BORLANDC__)
|
||||
#include <unistd.h>
|
||||
#endif /* WIN32 */
|
||||
#endif /* !WIN32 && !__BORLANDC__ */
|
||||
#ifdef HAVE_LIMITS_H
|
||||
#include <limits.h>
|
||||
#else
|
||||
|
@ -446,7 +448,7 @@ pcap_freealldevs(pcap_if_t *alldevs)
|
|||
}
|
||||
}
|
||||
|
||||
#ifndef WIN32
|
||||
#if !defined(WIN32) && !defined(MSDOS)
|
||||
|
||||
/*
|
||||
* Return the name of a network interface attached to the system, or NULL
|
||||
|
@ -570,7 +572,7 @@ pcap_lookupnet(device, netp, maskp, errbuf)
|
|||
return (0);
|
||||
}
|
||||
|
||||
#else /* WIN32 */
|
||||
#elif defined(WIN32)
|
||||
|
||||
/*
|
||||
* Return the name of a network interface attached to the system, or NULL
|
||||
|
@ -696,4 +698,4 @@ pcap_lookupnet(device, netp, maskp, errbuf)
|
|||
return (0);
|
||||
}
|
||||
|
||||
#endif /* WIN32 */
|
||||
#endif /* !WIN32 && !MSDOS */
|
||||
|
|
|
@ -0,0 +1,43 @@
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <stdarg.h>
|
||||
#include <time.h>
|
||||
|
||||
static void Abort (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);
|
||||
}
|
|
@ -0,0 +1,79 @@
|
|||
#
|
||||
# Common defines for libpcap and 16/32-bit network drivers (djgpp)
|
||||
#
|
||||
|
||||
.SUFFIXES: .exe .wlm .dxe .l .y
|
||||
.PHONY: check_gcclib
|
||||
|
||||
default: check_gcclib all
|
||||
|
||||
GCCLIB = /djgpp/lib/gcc-lib/djgpp/3.31
|
||||
MAKEFILE = Makefile.dj
|
||||
|
||||
#
|
||||
# DLX 2.91+ lib. Change path to suite.
|
||||
# Not used anymore. Uses DXE3 now.
|
||||
#
|
||||
# DLX_LIB = $(DJDIR)/contrib/dlx.291/libdlx.a
|
||||
# DLX_LINK = $(DJDIR)/bin/dlxgen.exe
|
||||
|
||||
WATT32_ROOT = $(subst \,/,$(WATT_ROOT))
|
||||
|
||||
|
||||
ifeq ($(wildcard $(GCCLIB)/libgcc.a),)
|
||||
check_gcclib:
|
||||
@echo libgcc.a not found. Set \"$(GCCLIB)\" to \"/djgpp/lib/gcc-lib/djgpp/3.X\"
|
||||
endif
|
||||
|
||||
|
||||
#
|
||||
# Include 32-bit driver support
|
||||
#
|
||||
USE_32BIT_DRIVERS = 1
|
||||
|
||||
#
|
||||
# Use loadable driver modules instead of statically linking
|
||||
# all drivers.
|
||||
#
|
||||
USE_32BIT_MODULES = 0
|
||||
|
||||
#
|
||||
# Put interrupt sensitive code/data in locked sections
|
||||
# Do `make clean' in all affected directories after changing this.
|
||||
#
|
||||
USE_SECTION_LOCKING = 0
|
||||
|
||||
#
|
||||
# Set to 1 to use exception handler lib (only for me)
|
||||
#
|
||||
USE_EXCEPT = 0
|
||||
|
||||
CC = gcc.exe
|
||||
LD = ld.exe
|
||||
ASM = nasm.exe -fbin -dDEBUG
|
||||
YACC = bison.exe
|
||||
LEX = flex.exe
|
||||
|
||||
CFLAGS = -g -gcoff -O2 -Wall -I. -I$(WATT32_ROOT)/inc
|
||||
|
||||
ifeq ($(USE_EXCEPT),1)
|
||||
CFLAGS += -DUSE_EXCEPT
|
||||
EXC_LIB = d:/prog/mw/except/lib/libexc.a
|
||||
endif
|
||||
|
||||
ifeq ($(USE_SECTION_LOCKING),1)
|
||||
CFLAGS += -DUSE_SECTION_LOCKING
|
||||
endif
|
||||
|
||||
ifeq ($(USE_32BIT_DRIVERS),1)
|
||||
CFLAGS += -DUSE_32BIT_DRIVERS
|
||||
endif
|
||||
|
||||
%.o: %.c
|
||||
$(CC) -c $(CFLAGS) $<
|
||||
@echo
|
||||
|
||||
%.o: %.s
|
||||
$(CC) -c $(CFLAGS) -x assembler-with-cpp -o $@ $<
|
||||
@echo
|
||||
|
|
@ -0,0 +1,184 @@
|
|||
#
|
||||
# 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 inet.c msdos\ndis2.c msdos\pktdrvr.c \
|
||||
missing\snprintf.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 optimiser 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 gnuc.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
|
||||
|
||||
inet.obj: inet.c 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 gnuc.h 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 gnuc.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
|
||||
|
||||
inet.o32: inet.c 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 gnuc.h 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
|
||||
|
|
@ -0,0 +1,147 @@
|
|||
#
|
||||
# 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
|
||||
#
|
||||
|
||||
VPATH = missing msdos
|
||||
|
||||
PREREQUISITES = scanner.c grammar.c tokdefs.h msdos/pkt_stub.inc
|
||||
|
||||
include msdos/common.dj
|
||||
|
||||
DRIVER_DIR = ./msdos/pm_drvr
|
||||
|
||||
CFLAGS += -DDEBUG -DNDIS_DEBUG -DHAVE_LIMITS_H -DHAVE_STRERROR \
|
||||
-D_U_='__attribute__((unused))'
|
||||
|
||||
# CFLAGS += -Dyylval=pcap_lval -DBDEBUG -DNDEBUG
|
||||
|
||||
SOURCES = 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 inet.c msdos\pktdrvr.c msdos/ndis2.c \
|
||||
missing/snprintf.c
|
||||
|
||||
OBJECTS = $(notdir $(SOURCES:.c=.o))
|
||||
TEMPBIN = tmp.bin
|
||||
|
||||
ifeq ($(USE_32BIT_DRIVERS),1)
|
||||
PM_OBJECTS = $(addprefix $(DRIVER_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 $(DRIVER_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
|
||||
|
||||
all: libpcap.a
|
||||
|
||||
ifeq ($(USE_32BIT_DRIVERS),1)
|
||||
$(PM_OBJECTS):
|
||||
$(MAKE) -f Makefile.dj -C $(DRIVER_DIR) $(notdir $@)
|
||||
endif
|
||||
|
||||
libpcap.a: $(OBJECTS) $(PM_OBJECTS)
|
||||
rm -f $@
|
||||
ar rs $@ $^
|
||||
|
||||
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
|
||||
|
||||
scanner.c: scanner.l
|
||||
$(LEX) -Ppcap_ -7 -t $^ > $@
|
||||
@echo
|
||||
|
||||
msdos/bin2c.exe: msdos/bin2c.c
|
||||
$(CC) $*.c -o $*.exe
|
||||
|
||||
clean:
|
||||
$(MAKE) -f Makefile.dj -C $(DRIVER_DIR) clean
|
||||
$(MAKE) -f Makefile.dj -C libcpcap clean
|
||||
rm -f $(OBJECTS) msdos/pkt_rx1.lst Makefile.bak $(PREREQUISITES)
|
||||
|
||||
vclean: clean
|
||||
rm -f libpcap.a msdos/bin2c.exe
|
||||
|
||||
#
|
||||
# Generated dependencies; Due to some hacks in gcc 2.95 and djgpp 2.03
|
||||
# we must prevent "$(DJDIR)/bin/../include/sys/version.h" from beeing
|
||||
# included in dependency output (or else this makefile cannot be used on
|
||||
# another machine). We therefore use a special 'specs' file during
|
||||
# pre-processing.
|
||||
#
|
||||
MM_SPECS = specs.tmp
|
||||
MAKEFILE = msdos/Makefile.dj
|
||||
|
||||
depend: $(PREREQUISITES)
|
||||
@echo Generating dependencies..
|
||||
@cp $(MAKEFILE) Makefile.bak
|
||||
@echo "*cpp: %(cpp_cpu) %{posix:-D_POSIX_SOURCE} -remap" > $(MM_SPECS)
|
||||
sed -e "/^# DO NOT DELETE THIS LINE/,$$d" < Makefile.bak > $(MAKEFILE)
|
||||
echo "# DO NOT DELETE THIS LINE" >> $(MAKEFILE)
|
||||
$(CC) -MM -specs=$(MM_SPECS) $(CFLAGS) $(SOURCES) >> $(MAKEFILE)
|
||||
rm -f $(MM_SPECS)
|
||||
|
||||
#
|
||||
# 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 gnuc.h
|
||||
grammar.y: pcap-int.h gencode.h pcap-namedb.h gnuc.h
|
||||
|
||||
#
|
||||
# Automatically generated dependencies
|
||||
#
|
||||
# DO NOT DELETE THIS LINE
|
||||
grammar.o: grammar.c pcap-int.h pcap.h pcap-bpf.h gencode.h pf.h \
|
||||
pcap-namedb.h
|
||||
scanner.o: scanner.c pcap-int.h pcap.h pcap-bpf.h gencode.h pcap-namedb.h \
|
||||
tokdefs.h
|
||||
bpf_filt.o: bpf_filt.c pcap-int.h pcap.h pcap-bpf.h gnuc.h
|
||||
bpf_imag.o: bpf_imag.c pcap-int.h pcap.h pcap-bpf.h
|
||||
bpf_dump.o: bpf_dump.c pcap.h pcap-bpf.h
|
||||
etherent.o: etherent.c pcap-int.h pcap.h pcap-bpf.h pcap-namedb.h
|
||||
gencode.o: gencode.c pcap-dos.h msdos/pm_drvr/lock.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.o: nametoad.c pcap-int.h pcap.h pcap-bpf.h gencode.h \
|
||||
pcap-namedb.h ethertype.h
|
||||
pcap-dos.o: pcap-dos.c msdos/pm_drvr/pmdrvr.h msdos/pm_drvr/iface.h \
|
||||
msdos/pm_drvr/lock.h msdos/pm_drvr/ioport.h pcap-dos.h pcap-int.h \
|
||||
pcap.h pcap-bpf.h msdos/pm_drvr/kmalloc.h msdos/pm_drvr/bitops.h \
|
||||
msdos/pm_drvr/timer.h msdos/pm_drvr/dma.h msdos/pm_drvr/irq.h \
|
||||
msdos/pm_drvr/printk.h msdos/pm_drvr/pci.h msdos/pm_drvr/bios32.h \
|
||||
msdos/pm_drvr/module.h msdos/pm_drvr/3c501.h msdos/pm_drvr/3c503.h \
|
||||
msdos/pm_drvr/3c509.h msdos/pm_drvr/3c59x.h msdos/pm_drvr/3c515.h \
|
||||
msdos/pm_drvr/3c90x.h msdos/pm_drvr/3c575_cb.h msdos/pm_drvr/ne.h \
|
||||
msdos/pm_drvr/wd.h msdos/pm_drvr/accton.h msdos/pm_drvr/cs89x0.h \
|
||||
msdos/pm_drvr/rtl8139.h msdos/pm_drvr/ne2k-pci.h msdos/pktdrvr.h
|
||||
optimize.o: optimize.c pcap-int.h pcap.h pcap-bpf.h gencode.h
|
||||
savefile.o: savefile.c pcap-int.h pcap.h pcap-bpf.h
|
||||
pcap.o: pcap.c pcap-dos.h msdos/pm_drvr/lock.h pcap-int.h pcap.h \
|
||||
pcap-bpf.h
|
||||
inet.o: inet.c pcap-int.h pcap.h pcap-bpf.h
|
||||
pktdrvr.o: msdos/pktdrvr.c gnuc.h pcap-dos.h msdos/pm_drvr/lock.h \
|
||||
pcap-int.h pcap.h pcap-bpf.h msdos/pktdrvr.h msdos/pkt_stub.inc
|
||||
ndis2.o: msdos/ndis2.c pcap-dos.h msdos/pm_drvr/lock.h pcap-int.h pcap.h \
|
||||
pcap-bpf.h msdos/ndis2.h
|
||||
snprintf.o: missing/snprintf.c pcap-int.h pcap.h pcap-bpf.h
|
|
@ -0,0 +1,131 @@
|
|||
#
|
||||
# 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_filt.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)\inet.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 gnuc.h &
|
||||
pcap-dos.h pcap-int.h pcap.h msdos\pktdrvr.h
|
||||
*$(CC) $(CFLAGS) msdos\pktdrvr.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_filt.obj: bpf_filt.c pcap-int.h pcap.h pcap-bpf.h gnuc.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-nam.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)\inet.obj: inet.c pcap-int.h pcap.h pcap-bpf.h
|
||||
|
||||
$(OBJDIR)\grammar.obj: grammar.c pcap-int.h pcap.h pcap-bpf.h gencode.h &
|
||||
pf.h pcap-nam.h
|
||||
|
||||
$(OBJDIR)\scanner.obj: scanner.c pcap-int.h pcap.h pcap-bpf.h gencode.h &
|
||||
pcap-nam.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 pf.h pcap-nam.h
|
||||
|
||||
$(OBJDIR)\nametoad.obj: nametoad.c pcap-int.h pcap.h pcap-bpf.h gencode.h &
|
||||
pcap-nam.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 gnuc.h 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
|
||||
|
|
@ -0,0 +1,860 @@
|
|||
/*
|
||||
* Copyright (c) 1993,1994
|
||||
* Texas A&M University. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by Texas A&M University
|
||||
* and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* Developers:
|
||||
* David K. Hess, Douglas Lee Schales, David R. Safford
|
||||
*
|
||||
* Heavily modified for Metaware HighC + GNU C 2.8+
|
||||
* Gisle Vanem 1998
|
||||
*/
|
||||
|
||||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <dos.h>
|
||||
#include <io.h>
|
||||
#include <fcntl.h>
|
||||
#include <malloc.h>
|
||||
#include <string.h>
|
||||
|
||||
#include "pcap-dos.h"
|
||||
#include "pcap-int.h"
|
||||
#include "msdos/ndis2.h"
|
||||
|
||||
#if defined(USE_NDIS2)
|
||||
|
||||
/*
|
||||
* Packet buffer handling
|
||||
*/
|
||||
extern int FreePktBuf (PktBuf *buf);
|
||||
extern int EnquePktBuf (PktBuf *buf);
|
||||
extern PktBuf* AllocPktBuf (void);
|
||||
|
||||
/*
|
||||
* Various defines
|
||||
*/
|
||||
#define MAX_NUM_DEBUG_STRINGS 90
|
||||
#define DEBUG_STRING_LENGTH 80
|
||||
#define STACK_POOL_SIZE 6
|
||||
#define STACK_SIZE 256
|
||||
|
||||
#define MEDIA_FDDI 1
|
||||
#define MEDIA_ETHERNET 2
|
||||
#define MEDIA_TOKEN 3
|
||||
|
||||
static int startDebug = 0;
|
||||
static int stopDebug = 0;
|
||||
|
||||
static DWORD droppedPackets = 0L;
|
||||
static WORD frameSize = 0;
|
||||
static WORD headerSize = 0;
|
||||
static int mediaType = 0;
|
||||
static char *lastErr = NULL;
|
||||
|
||||
static BYTE debugStrings [MAX_NUM_DEBUG_STRINGS][DEBUG_STRING_LENGTH];
|
||||
static BYTE *freeStacks [STACK_POOL_SIZE];
|
||||
static int freeStackPtr = STACK_POOL_SIZE - 1;
|
||||
|
||||
static ProtMan protManEntry = NULL;
|
||||
static WORD protManDS = 0;
|
||||
static volatile int xmitPending;
|
||||
|
||||
static struct _PktBuf *txBufPending;
|
||||
static struct _CardHandle *handle;
|
||||
static struct _CommonChars common;
|
||||
static struct _ProtocolChars protChars;
|
||||
static struct _ProtDispatch lowerTable;
|
||||
|
||||
static struct _FailingModules failingModules;
|
||||
static struct _BindingsList bindings;
|
||||
|
||||
static struct {
|
||||
WORD err_num;
|
||||
char *err_text;
|
||||
} ndis_errlist[] = {
|
||||
|
||||
{ ERR_SUCCESS,
|
||||
"The function completed successfully.\n" },
|
||||
|
||||
{ ERR_WAIT_FOR_RELEASE,
|
||||
"The ReceiveChain completed successfully but the protocol has\n"
|
||||
"retained control of the buffer.\n" },
|
||||
|
||||
{ ERR_REQUEST_QUEUED,
|
||||
"The current request has been queued.\n" },
|
||||
|
||||
{ ERR_FRAME_NOT_RECOGNIZED,
|
||||
"Frame not recognized.\n" },
|
||||
|
||||
{ ERR_FRAME_REJECTED,
|
||||
"Frame was discarded.\n" },
|
||||
|
||||
{ ERR_FORWARD_FRAME,
|
||||
"Protocol wishes to forward frame to another protocol.\n" },
|
||||
|
||||
{ ERR_OUT_OF_RESOURCE,
|
||||
"Out of resource.\n" },
|
||||
|
||||
{ ERR_INVALID_PARAMETER,
|
||||
"Invalid parameter.\n" },
|
||||
|
||||
{ ERR_INVALID_FUNCTION,
|
||||
"Invalid function.\n" },
|
||||
|
||||
{ ERR_NOT_SUPPORTED,
|
||||
"Not supported.\n" },
|
||||
|
||||
{ ERR_HARDWARE_ERROR,
|
||||
"Hardware error.\n" },
|
||||
|
||||
{ ERR_TRANSMIT_ERROR,
|
||||
"The packet was not transmitted due to an error.\n" },
|
||||
|
||||
{ ERR_NO_SUCH_DESTINATION,
|
||||
"Token ring packet was not recognized when transmitted.\n" },
|
||||
|
||||
{ ERR_BUFFER_TOO_SMALL,
|
||||
"Provided buffer was too small.\n" },
|
||||
|
||||
{ ERR_ALREADY_STARTED,
|
||||
"Network drivers already started.\n" },
|
||||
|
||||
{ ERR_INCOMPLETE_BINDING,
|
||||
"Protocol driver could not complete its bindings.\n" },
|
||||
|
||||
{ ERR_DRIVER_NOT_INITIALIZED,
|
||||
"MAC did not initialize properly.\n" },
|
||||
|
||||
{ ERR_HARDWARE_NOT_FOUND,
|
||||
"Hardware not found.\n" },
|
||||
|
||||
{ ERR_HARDWARE_FAILURE,
|
||||
"Hardware failure.\n" },
|
||||
|
||||
{ ERR_CONFIGURATION_FAILURE,
|
||||
"Configuration failure.\n" },
|
||||
|
||||
{ ERR_INTERRUPT_CONFLICT,
|
||||
"Interrupt conflict.\n" },
|
||||
|
||||
{ ERR_INCOMPATIBLE_MAC,
|
||||
"The MAC is not compatible with the protocol.\n" },
|
||||
|
||||
{ ERR_INITIALIZATION_FAILED,
|
||||
"Initialization failed.\n" },
|
||||
|
||||
{ ERR_NO_BINDING,
|
||||
"Binding did not occur.\n" },
|
||||
|
||||
{ ERR_NETWORK_MAY_NOT_BE_CONNECTED,
|
||||
"The network may not be connected to the adapter.\n" },
|
||||
|
||||
{ ERR_INCOMPATIBLE_OS_VERSION,
|
||||
"The version of the operating system is incompatible with the protocol.\n" },
|
||||
|
||||
{ ERR_ALREADY_REGISTERED,
|
||||
"The protocol is already registered.\n" },
|
||||
|
||||
{ ERR_PATH_NOT_FOUND,
|
||||
"PROTMAN.EXE could not be found.\n" },
|
||||
|
||||
{ ERR_INSUFFICIENT_MEMORY,
|
||||
"Insufficient memory.\n" },
|
||||
|
||||
{ ERR_INFO_NOT_FOUND,
|
||||
"Protocol Mananger info structure is lost or corrupted.\n" },
|
||||
|
||||
{ ERR_GENERAL_FAILURE,
|
||||
"General failure.\n" }
|
||||
};
|
||||
|
||||
/*
|
||||
* Some handy macros
|
||||
*/
|
||||
#define PERROR(str) printf("%s (%d): %s\n", __FILE__,__LINE__,str)
|
||||
#define DEBUG_RING() (debugStrings[stopDebug+1 == MAX_NUM_DEBUG_STRINGS ? \
|
||||
stopDebug = 0 : ++stopDebug])
|
||||
|
||||
/*
|
||||
* needs rewrite for DOSX
|
||||
*/
|
||||
#define MAC_DISPATCH(hnd) ((struct _MacUpperDispatch*)(hnd)->common->upperDispatchTable)
|
||||
#define MAC_STATUS(hnd) ((struct _MacStatusTable*) (hnd)->common->serviceStatus)
|
||||
#define MAC_CHAR(hnd) ((struct _MacChars*) (hnd)->common->serviceChars)
|
||||
|
||||
#ifdef NDIS_DEBUG
|
||||
#define DEBUG0(str) printf (str)
|
||||
#define DEBUG1(fmt,a) printf (fmt,a)
|
||||
#define DEBUG2(fmt,a,b) printf (fmt,a,b)
|
||||
#define TRACE0(str) sprintf (DEBUG_RING(),str)
|
||||
#define TRACE1(fmt,a) sprintf (DEBUG_RING(),fmt,a)
|
||||
#else
|
||||
#define DEBUG0(str) ((void)0)
|
||||
#define DEBUG1(fmt,a) ((void)0)
|
||||
#define DEBUG2(fmt,a,b) ((void)0)
|
||||
#define TRACE0(str) ((void)0)
|
||||
#define TRACE1(fmt,a) ((void)0)
|
||||
#endif
|
||||
|
||||
/*
|
||||
* This routine is called from both threads
|
||||
*/
|
||||
void NdisFreeStack (BYTE *aStack)
|
||||
{
|
||||
GUARD();
|
||||
|
||||
if (freeStackPtr == STACK_POOL_SIZE - 1)
|
||||
PERROR ("tried to free too many stacks");
|
||||
|
||||
freeStacks[++freeStackPtr] = aStack;
|
||||
|
||||
if (freeStackPtr == 0)
|
||||
TRACE0 ("freeStackPtr went positive\n");
|
||||
|
||||
UNGUARD();
|
||||
}
|
||||
|
||||
/*
|
||||
* This routine is called from callbacks to allocate local data
|
||||
*/
|
||||
BYTE *NdisAllocStack (void)
|
||||
{
|
||||
BYTE *stack;
|
||||
|
||||
GUARD();
|
||||
|
||||
if (freeStackPtr < 0)
|
||||
{
|
||||
/* Ran out of stack buffers. Return NULL which will start
|
||||
* dropping packets
|
||||
*/
|
||||
TRACE0 ("freeStackPtr went negative\n");
|
||||
stack = 0;
|
||||
}
|
||||
else
|
||||
stack = freeStacks[freeStackPtr--];
|
||||
|
||||
UNGUARD();
|
||||
return (stack);
|
||||
}
|
||||
|
||||
CALLBACK (NdisSystemRequest (DWORD param1, DWORD param2, WORD param3,
|
||||
WORD opcode, WORD targetDS))
|
||||
{
|
||||
static int bindEntry = 0;
|
||||
struct _CommonChars *macCommon;
|
||||
volatile WORD result;
|
||||
|
||||
switch (opcode)
|
||||
{
|
||||
case REQ_INITIATE_BIND:
|
||||
macCommon = (struct _CommonChars*) param2;
|
||||
if (macCommon == NULL)
|
||||
{
|
||||
printf ("There is an NDIS misconfiguration.\n");
|
||||
result = ERR_GENERAL_FAILURE;
|
||||
break;
|
||||
}
|
||||
DEBUG2 ("module name %s\n"
|
||||
"module type %s\n",
|
||||
macCommon->moduleName,
|
||||
((MacChars*) macCommon->serviceChars)->macName);
|
||||
|
||||
/* Binding to the MAC */
|
||||
result = macCommon->systemRequest ((DWORD)&common, (DWORD)&macCommon,
|
||||
0, REQ_BIND,
|
||||
macCommon->moduleDS);
|
||||
|
||||
if (!strcmp(bindings.moduleName[bindEntry], handle->moduleName))
|
||||
handle->common = macCommon;
|
||||
else PERROR ("unknown module");
|
||||
++bindEntry;
|
||||
break;
|
||||
|
||||
case REQ_INITIATE_UNBIND:
|
||||
macCommon = (struct _CommonChars*) param2;
|
||||
result = macCommon->systemRequest ((DWORD)&common, 0,
|
||||
0, REQ_UNBIND,
|
||||
macCommon->moduleDS);
|
||||
break;
|
||||
|
||||
default:
|
||||
result = ERR_GENERAL_FAILURE;
|
||||
break;
|
||||
}
|
||||
ARGSUSED (param1);
|
||||
ARGSUSED (param3);
|
||||
ARGSUSED (targetDS);
|
||||
return (result);
|
||||
}
|
||||
|
||||
CALLBACK (NdisRequestConfirm (WORD protId, WORD macId, WORD reqHandle,
|
||||
WORD status, WORD request, WORD protDS))
|
||||
{
|
||||
ARGSUSED (protId); ARGSUSED (macId);
|
||||
ARGSUSED (reqHandle); ARGSUSED (status);
|
||||
ARGSUSED (request); ARGSUSED (protDS);
|
||||
return (ERR_SUCCESS);
|
||||
}
|
||||
|
||||
CALLBACK (NdisTransmitConfirm (WORD protId, WORD macId, WORD reqHandle,
|
||||
WORD status, WORD protDS))
|
||||
{
|
||||
xmitPending--;
|
||||
FreePktBuf (txBufPending); /* Add passed ECB back to the free list */
|
||||
|
||||
ARGSUSED (reqHandle);
|
||||
ARGSUSED (status);
|
||||
ARGSUSED (protDS);
|
||||
return (ERR_SUCCESS);
|
||||
}
|
||||
|
||||
|
||||
/*
|
||||
* The primary function for receiving packets
|
||||
*/
|
||||
CALLBACK (NdisReceiveLookahead (WORD macId, WORD frameSize,
|
||||
WORD bytesAvail, BYTE *buffer,
|
||||
BYTE *indicate, WORD protDS))
|
||||
{
|
||||
int result;
|
||||
PktBuf *pktBuf;
|
||||
WORD bytesCopied;
|
||||
struct _TDBufDescr tDBufDescr;
|
||||
|
||||
#if 0
|
||||
TRACE1 ("lookahead length = %d, ", bytesAvail);
|
||||
TRACE1 ("ecb = %08lX, ", *ecb);
|
||||
TRACE1 ("count = %08lX\n", count);
|
||||
TRACE1 ("offset = %08lX, ", offset);
|
||||
TRACE1 ("timesAllowed = %d, ", timesAllowed);
|
||||
TRACE1 ("packet size = %d\n", look->dataLookAheadLen);
|
||||
#endif
|
||||
|
||||
/* Allocate a buffer for the packet
|
||||
*/
|
||||
if ((pktBuf = AllocPktBuf()) == NULL)
|
||||
{
|
||||
droppedPackets++;
|
||||
return (ERR_FRAME_REJECTED);
|
||||
}
|
||||
|
||||
/*
|
||||
* Now kludge things. Note we will have to undo this later. This will
|
||||
* make the packet contiguous after the MLID has done the requested copy.
|
||||
*/
|
||||
|
||||
tDBufDescr.tDDataCount = 1;
|
||||
tDBufDescr.tDBufDescrRec[0].tDPtrType = NDIS_PTR_PHYSICAL;
|
||||
tDBufDescr.tDBufDescrRec[0].tDDataPtr = pktBuf->buffer;
|
||||
tDBufDescr.tDBufDescrRec[0].tDDataLen = pktBuf->length;
|
||||
tDBufDescr.tDBufDescrRec[0].dummy = 0;
|
||||
|
||||
result = MAC_DISPATCH(handle)->transferData (&bytesCopied, 0, &tDBufDescr,
|
||||
handle->common->moduleDS);
|
||||
pktBuf->packetLength = bytesCopied;
|
||||
|
||||
if (result == ERR_SUCCESS)
|
||||
EnquePktBuf(pktBuf);
|
||||
else FreePktBuf (pktBuf);
|
||||
|
||||
ARGSUSED (frameSize);
|
||||
ARGSUSED (bytesAvail);
|
||||
ARGSUSED (indicate);
|
||||
ARGSUSED (protDS);
|
||||
|
||||
return (ERR_SUCCESS);
|
||||
}
|
||||
|
||||
CALLBACK (NdisIndicationComplete (WORD macId, WORD protDS))
|
||||
{
|
||||
ARGSUSED (macId);
|
||||
ARGSUSED (protDS);
|
||||
|
||||
/* We don't give a hoot about these. Just return
|
||||
*/
|
||||
return (ERR_SUCCESS);
|
||||
}
|
||||
|
||||
/*
|
||||
* This is the OTHER way we may receive packets
|
||||
*/
|
||||
CALLBACK (NdisReceiveChain (WORD macId, WORD frameSize, WORD reqHandle,
|
||||
struct _RxBufDescr *rxBufDescr,
|
||||
BYTE *indicate, WORD protDS))
|
||||
{
|
||||
struct _PktBuf *pktBuf;
|
||||
int i;
|
||||
|
||||
/*
|
||||
* For now we copy the entire packet over to a PktBuf structure. This may be
|
||||
* a performance hit but this routine probably isn't called very much, and
|
||||
* it is a lot of work to do it otherwise. Also if it is a filter protocol
|
||||
* packet we could end up sucking up MAC buffes.
|
||||
*/
|
||||
|
||||
if ((pktBuf = AllocPktBuf()) == NULL)
|
||||
{
|
||||
droppedPackets++;
|
||||
return (ERR_FRAME_REJECTED);
|
||||
}
|
||||
pktBuf->packetLength = 0;
|
||||
|
||||
/* Copy the packet to the buffer
|
||||
*/
|
||||
for (i = 0; i < rxBufDescr->rxDataCount; ++i)
|
||||
{
|
||||
struct _RxBufDescrRec *rxDescr = &rxBufDescr->rxBufDescrRec[i];
|
||||
|
||||
memcpy (pktBuf->buffer + pktBuf->packetLength,
|
||||
rxDescr->rxDataPtr, rxDescr->rxDataLen);
|
||||
pktBuf->packetLength += rxDescr->rxDataLen;
|
||||
}
|
||||
|
||||
EnquePktBuf (pktBuf);
|
||||
|
||||
ARGSUSED (frameSize);
|
||||
ARGSUSED (reqHandle);
|
||||
ARGSUSED (indicate);
|
||||
ARGSUSED (protDS);
|
||||
|
||||
/* This frees up the buffer for the MAC to use
|
||||
*/
|
||||
return (ERR_SUCCESS);
|
||||
}
|
||||
|
||||
CALLBACK (NdisStatusProc (WORD macId, WORD param1, BYTE *indicate,
|
||||
WORD opcode, WORD protDS))
|
||||
{
|
||||
switch (opcode)
|
||||
{
|
||||
case STATUS_RING_STATUS:
|
||||
break;
|
||||
case STATUS_ADAPTER_CHECK:
|
||||
break;
|
||||
case STATUS_START_RESET:
|
||||
break;
|
||||
case STATUS_INTERRUPT:
|
||||
break;
|
||||
case STATUS_END_RESET:
|
||||
break;
|
||||
default:
|
||||
break;
|
||||
}
|
||||
ARGSUSED (macId);
|
||||
ARGSUSED (param1);
|
||||
ARGSUSED (indicate);
|
||||
ARGSUSED (opcode);
|
||||
ARGSUSED (protDS);
|
||||
|
||||
/* We don't need to do anything about this stuff yet
|
||||
*/
|
||||
return (ERR_SUCCESS);
|
||||
}
|
||||
|
||||
/*
|
||||
* Tell the NDIS driver to start the delivery of the packet
|
||||
*/
|
||||
int NdisSendPacket (struct _PktBuf *pktBuf, int macId)
|
||||
{
|
||||
struct _TxBufDescr txBufDescr;
|
||||
int result;
|
||||
|
||||
xmitPending++;
|
||||
txBufPending = pktBuf; /* we only have 1 pending Tx at a time */
|
||||
|
||||
txBufDescr.txImmedLen = 0;
|
||||
txBufDescr.txImmedPtr = NULL;
|
||||
txBufDescr.txDataCount = 1;
|
||||
txBufDescr.txBufDescrRec[0].txPtrType = NDIS_PTR_PHYSICAL;
|
||||
txBufDescr.txBufDescrRec[0].dummy = 0;
|
||||
txBufDescr.txBufDescrRec[0].txDataLen = pktBuf->packetLength;
|
||||
txBufDescr.txBufDescrRec[0].txDataPtr = pktBuf->buffer;
|
||||
|
||||
result = MAC_DISPATCH(handle)->transmitChain (common.moduleId,
|
||||
pktBuf->handle,
|
||||
&txBufDescr,
|
||||
handle->common->moduleDS);
|
||||
switch (result)
|
||||
{
|
||||
case ERR_OUT_OF_RESOURCE:
|
||||
/* Note that this should not happen but if it does there is not
|
||||
* much we can do about it
|
||||
*/
|
||||
printf ("ERROR: transmit queue overflowed\n");
|
||||
return (0);
|
||||
|
||||
case ERR_SUCCESS:
|
||||
/* Everything was hunky dory and synchronous. Free up the
|
||||
* packet buffer
|
||||
*/
|
||||
xmitPending--;
|
||||
FreePktBuf (pktBuf);
|
||||
return (1);
|
||||
|
||||
case ERR_REQUEST_QUEUED:
|
||||
/* Everything was hunky dory and asynchronous. Do nothing
|
||||
*/
|
||||
return (1);
|
||||
|
||||
default:
|
||||
printf ("Tx fail, code = %04X\n", result);
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
|
||||
static int ndis_nerr = sizeof(ndis_errlist) / sizeof(ndis_errlist[0]);
|
||||
|
||||
static char *Ndis_strerror (WORD errorCode)
|
||||
{
|
||||
static char buf[30];
|
||||
int i;
|
||||
|
||||
for (i = 0; i < ndis_nerr; i++)
|
||||
if (errorCode == ndis_errlist[i].err_num)
|
||||
return (ndis_errlist[i].err_text);
|
||||
|
||||
sprintf (buf,"unknown error %d",errorCode);
|
||||
return (buf);
|
||||
}
|
||||
|
||||
|
||||
char *NdisLastError (void)
|
||||
{
|
||||
char *errStr = lastErr;
|
||||
lastErr = NULL;
|
||||
return (errStr);
|
||||
}
|
||||
|
||||
int NdisOpen (void)
|
||||
{
|
||||
struct _ReqBlock reqBlock;
|
||||
int result;
|
||||
int ndisFd = open (NDIS_PATH, O_RDONLY);
|
||||
|
||||
if (ndisFd < 0)
|
||||
{
|
||||
printf ("Could not open NDIS Protocol Manager device.\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
memset (&reqBlock, 0, sizeof(ReqBlock));
|
||||
|
||||
reqBlock.opcode = PM_GET_PROTOCOL_MANAGER_LINKAGE;
|
||||
|
||||
result = NdisGetLinkage (ndisFd, (char*)&reqBlock, sizeof(ReqBlock));
|
||||
if (result != 0)
|
||||
{
|
||||
printf ("Could not get Protocol Manager linkage.\n");
|
||||
close (ndisFd);
|
||||
return (0);
|
||||
}
|
||||
|
||||
close (ndisFd);
|
||||
protManEntry = (ProtMan) reqBlock.pointer1;
|
||||
protManDS = reqBlock.word1;
|
||||
|
||||
DEBUG2 ("Entry Point = %04X:%04X\n", FP_SEG(protManEntry),FP_OFF(protManEntry));
|
||||
DEBUG1 ("ProtMan DS = %04X\n", protManDS);
|
||||
return (1);
|
||||
}
|
||||
|
||||
|
||||
int NdisRegisterAndBind (int promis)
|
||||
{
|
||||
struct _ReqBlock reqBlock;
|
||||
WORD result;
|
||||
|
||||
memset (&common,0,sizeof(common));
|
||||
|
||||
common.tableSize = sizeof (common);
|
||||
|
||||
common.majorNdisVersion = 2;
|
||||
common.minorNdisVersion = 0;
|
||||
common.majorModuleVersion = 2;
|
||||
common.minorModuleVersion = 0;
|
||||
|
||||
/* Indicates binding from below and dynamically loaded
|
||||
*/
|
||||
common.moduleFlags = 0x00000006L;
|
||||
|
||||
strcpy (common.moduleName, "PCAP");
|
||||
|
||||
common.protocolLevelUpper = 0xFF;
|
||||
common.protocolLevelLower = 1;
|
||||
common.interfaceLower = 1;
|
||||
#ifdef __DJGPP__
|
||||
common.moduleDS = _dos_ds; /* the callback data segment */
|
||||
#else
|
||||
common.moduleDS = _DS;
|
||||
#endif
|
||||
|
||||
common.systemRequest = (SystemRequest) systemRequestGlue;
|
||||
common.serviceChars = (BYTE*) &protChars;
|
||||
common.serviceStatus = NULL;
|
||||
common.upperDispatchTable = NULL;
|
||||
common.lowerDispatchTable = (BYTE*) &lowerTable;
|
||||
|
||||
protChars.length = sizeof (protChars);
|
||||
protChars.name[0] = 0;
|
||||
protChars.type = 0;
|
||||
|
||||
lowerTable.backPointer = &common;
|
||||
lowerTable.requestConfirm = requestConfirmGlue;
|
||||
lowerTable.transmitConfirm = transmitConfirmGlue;
|
||||
lowerTable.receiveLookahead = receiveLookaheadGlue;
|
||||
lowerTable.indicationComplete = indicationCompleteGlue;
|
||||
lowerTable.receiveChain = receiveChainGlue;
|
||||
lowerTable.status = statusGlue;
|
||||
lowerTable.flags = 3;
|
||||
if (promis)
|
||||
lowerTable.flags |= 4; /* promiscous mode (receive everything) */
|
||||
|
||||
bindings.numBindings = 1;
|
||||
strcpy (bindings.moduleName[0], handle->moduleName);
|
||||
|
||||
/* Register ourselves with NDIS
|
||||
*/
|
||||
reqBlock.opcode = PM_REGISTER_MODULE;
|
||||
reqBlock.pointer1 = (BYTE FAR*) &common;
|
||||
reqBlock.pointer2 = (BYTE FAR*) &bindings;
|
||||
|
||||
result = (*protManEntry) (&reqBlock, protManDS);
|
||||
if (result)
|
||||
{
|
||||
printf ("Protman registering failed: %s\n", Ndis_strerror(result));
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Start the binding process
|
||||
*/
|
||||
reqBlock.opcode = PM_BIND_AND_START;
|
||||
reqBlock.pointer1 = (BYTE FAR*) &failingModules;
|
||||
|
||||
result = (*protManEntry) (&reqBlock, protManDS);
|
||||
if (result)
|
||||
{
|
||||
printf ("Start binding failed: %s\n", Ndis_strerror(result));
|
||||
return (0);
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
static int CheckMacFeatures (CardHandle *card)
|
||||
{
|
||||
DWORD serviceFlags;
|
||||
BYTE _far *mediaString;
|
||||
BYTE _far *mac_addr;
|
||||
|
||||
DEBUG2 ("checking card features\n"
|
||||
"common table address = %08lX, macId = %d\n",
|
||||
card->common, card->common->moduleId);
|
||||
|
||||
serviceFlags = MAC_CHAR (handle)->serviceFlags;
|
||||
|
||||
if ((serviceFlags & SF_PROMISCUOUS) == 0)
|
||||
{
|
||||
printf ("The MAC %s does not support promiscuous mode.\n",
|
||||
card->moduleName);
|
||||
return (0);
|
||||
}
|
||||
|
||||
mediaString = MAC_CHAR (handle)->macName;
|
||||
|
||||
DEBUG1 ("media type = %s\n",mediaString);
|
||||
|
||||
/* Get the media type. And set the header size
|
||||
*/
|
||||
if (!strncmp(mediaString,"802.3",5) ||
|
||||
!strncmp(mediaString,"DIX",3) ||
|
||||
!strncmp(mediaString,"DIX+802.3",9))
|
||||
headerSize = sizeof (EthernetIIHeader);
|
||||
|
||||
else if (!strncmp(mediaString,"FDDI",4))
|
||||
headerSize = sizeof (FddiHeader) +
|
||||
sizeof (Ieee802Dot2SnapHeader);
|
||||
else
|
||||
{
|
||||
printf ("Unsupported MAC type: `%s'\n", mediaString);
|
||||
return (0);
|
||||
}
|
||||
|
||||
frameSize = MAC_CHAR (handle)->maxFrameSize;
|
||||
mac_addr = MAC_CHAR (handle)->currentAddress;
|
||||
|
||||
printf ("Hardware address: %02X:%02X:%02X:%02X:%02X:%02X\n",
|
||||
mac_addr[0], mac_addr[1], mac_addr[2],
|
||||
mac_addr[3], mac_addr[4], mac_addr[5]);
|
||||
return (1);
|
||||
}
|
||||
|
||||
static int NdisStartMac (CardHandle *card)
|
||||
{
|
||||
WORD result;
|
||||
|
||||
/* Set the lookahead length
|
||||
*/
|
||||
result = MAC_DISPATCH(handle)->request (common.moduleId, 0,
|
||||
headerSize, 0,
|
||||
REQ_SET_LOOKAHEAD,
|
||||
card->common->moduleDS);
|
||||
|
||||
/* We assume that if we got INVALID PARAMETER then either this
|
||||
* is not supported or will work anyway. NE2000 does this.
|
||||
*/
|
||||
if (result != ERR_SUCCESS && result != ERR_INVALID_PARAMETER)
|
||||
{
|
||||
DEBUG1 ("Set lookahead failed: %s\n", Ndis_strerror(result));
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* Set the packet filter. Note that for some medias and drivers we
|
||||
* must specify all three flags or the card(s) will not operate correctly.
|
||||
*/
|
||||
result = MAC_DISPATCH(handle)->request (common.moduleId, 0,
|
||||
/* all packets */ FILTER_PROMISCUOUS |
|
||||
/* packets to us */ FILTER_DIRECTED |
|
||||
/* broadcasts */ FILTER_BROADCAST,
|
||||
0, REQ_SET_PACKET_FILTER,
|
||||
card->common->moduleDS);
|
||||
if (result != ERR_SUCCESS)
|
||||
{
|
||||
DEBUG1 ("Set packet filter failed: %s\n", Ndis_strerror(result));
|
||||
return (0);
|
||||
}
|
||||
|
||||
/* If OPEN/CLOSE supported then open the adapter
|
||||
*/
|
||||
if (MAC_CHAR(handle)->serviceFlags & SF_OPEN_CLOSE)
|
||||
{
|
||||
result = MAC_DISPATCH(handle)->request (common.moduleId, 0, 0, NULL,
|
||||
REQ_OPEN_ADAPTER,
|
||||
card->common->moduleDS);
|
||||
if (result != ERR_SUCCESS)
|
||||
{
|
||||
DEBUG1 ("Opening the MAC failed: %s\n", Ndis_strerror(result));
|
||||
return (0);
|
||||
}
|
||||
}
|
||||
return (1);
|
||||
}
|
||||
|
||||
void NdisShutdown (void)
|
||||
{
|
||||
struct _ReqBlock reqBlock;
|
||||
int result, i;
|
||||
|
||||
if (!handle)
|
||||
return;
|
||||
|
||||
/* If the adapters support open and are open then close them
|
||||
*/
|
||||
if ((MAC_CHAR(handle)->serviceFlags & SF_OPEN_CLOSE) &&
|
||||
(MAC_STATUS(handle)->macStatus & MAC_OPEN))
|
||||
{
|
||||
result = MAC_DISPATCH(handle)->request (common.moduleId, 0, 0, 0,
|
||||
REQ_CLOSE_ADAPTER,
|
||||
handle->common->moduleDS);
|
||||
if (result != ERR_SUCCESS)
|
||||
{
|
||||
printf ("Closing the MAC failed: %s\n", Ndis_strerror(result));
|
||||
return;
|
||||
}
|
||||
}
|
||||
|
||||
/* Tell the Protocol Manager to unbind and stop
|
||||
*/
|
||||
reqBlock.opcode = PM_UNBIND_AND_STOP;
|
||||
reqBlock.pointer1 = (BYTE FAR*) &failingModules;
|
||||
reqBlock.pointer2 = NULL;
|
||||
|
||||
result = (*protManEntry) (&reqBlock, protManDS);
|
||||
if (result)
|
||||
printf ("Unbind failed: %s\n", Ndis_strerror(result));
|
||||
|
||||
for (i = 0; i < STACK_POOL_SIZE; ++i)
|
||||
free (freeStacks[i] - STACK_SIZE);
|
||||
|
||||
handle = NULL;
|
||||
}
|
||||
|
||||
int NdisInit (int promis)
|
||||
{
|
||||
int i, result;
|
||||
|
||||
/* Allocate the real mode stacks used for NDIS callbacks
|
||||
*/
|
||||
for (i = 0; i < STACK_POOL_SIZE; ++i)
|
||||
{
|
||||
freeStacks[i] = malloc (STACK_SIZE);
|
||||
if (!freeStacks[i])
|
||||
return (0);
|
||||
freeStacks[i] += STACK_SIZE;
|
||||
}
|
||||
|
||||
if (!NdisOpen())
|
||||
return (0);
|
||||
|
||||
if (!NdisRegisterAndBind(promis))
|
||||
return (0);
|
||||
|
||||
DEBUG1 ("My module id: %d\n", common.moduleId);
|
||||
DEBUG1 ("Handle id; %d\n", handle->common->moduleId);
|
||||
DEBUG1 ("MAC card: %-16s - ", handle->moduleName);
|
||||
|
||||
atexit (NdisShutdown);
|
||||
|
||||
if (!CheckMacFeatures(&handle))
|
||||
return (0);
|
||||
|
||||
switch (mediaType)
|
||||
{
|
||||
case MEDIA_FDDI:
|
||||
DEBUG0 ("Media type: FDDI");
|
||||
break;
|
||||
case MEDIA_ETHERNET:
|
||||
DEBUG0 ("Media type: ETHERNET");
|
||||
break;
|
||||
default:
|
||||
DEBUG0 ("Unsupported media.\n");
|
||||
return (0);
|
||||
}
|
||||
|
||||
DEBUG1 (" - Frame size: %d\n", frameSize);
|
||||
|
||||
if (!NdisStartMac(&handle))
|
||||
return (0);
|
||||
return (1);
|
||||
}
|
||||
#endif /* USE_NDIS2 */
|
||||
|
|
@ -0,0 +1,559 @@
|
|||
/*
|
||||
* Copyright (c) 1993,1994
|
||||
* Texas A&M University. All rights reserved.
|
||||
*
|
||||
* Redistribution and use in source and binary forms, with or without
|
||||
* modification, are permitted provided that the following conditions
|
||||
* are met:
|
||||
* 1. Redistributions of source code must retain the above copyright
|
||||
* notice, this list of conditions and the following disclaimer.
|
||||
* 2. Redistributions in binary form must reproduce the above copyright
|
||||
* notice, this list of conditions and the following disclaimer in the
|
||||
* documentation and/or other materials provided with the distribution.
|
||||
* 3. All advertising materials mentioning features or use of this software
|
||||
* must display the following acknowledgement:
|
||||
* This product includes software developed by Texas A&M University
|
||||
* and its contributors.
|
||||
* 4. Neither the name of the University nor the names of its contributors
|
||||
* may be used to endorse or promote products derived from this software
|
||||
* without specific prior written permission.
|
||||
*
|
||||
* THIS SOFTWARE IS PROVIDED BY THE UNIVERSITY AND CONTRIBUTORS ``AS IS'' AND
|
||||
* ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
|
||||
* IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
|
||||
* ARE DISCLAIMED. IN NO EVENT SHALL THE UNIVERSITY OR CONTRIBUTORS BE LIABLE
|
||||
* FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
|
||||
* DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
|
||||
* OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
|
||||
* HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
|
||||
* LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
|
||||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* Developers:
|
||||
* David K. Hess, Douglas Lee Schales, David R. Safford
|
||||
*
|
||||
* Heavily modified for Metaware HighC + GNU C 2.8+
|
||||
* Gisle Vanem 1998
|
||||
*/
|
||||
|
||||
#ifndef __PCAP_NDIS_H
|
||||
#define __PCAP_NDIS_H
|
||||
|
||||
#if defined (__HIGHC__)
|
||||
#define pascal _CC(_CALLEE_POPS_STACK & ~_REVERSE_PARMS) /* calling convention */
|
||||
#define CALLBACK(foo) pascal WORD foo
|
||||
#define PAS_PTR(x,arg) typedef FAR WORD pascal (*x) arg
|
||||
#define GUARD() _inline (0x9C,0xFA) /* pushfd, cli */
|
||||
#define UNGUARD() _inline (0x9D) /* popfd */
|
||||
#define FAR _far
|
||||
|
||||
#elif defined(__GNUC__)
|
||||
#define CALLBACK(foo) WORD foo __attribute__((stdcall))
|
||||
#define PAS_PTR(x,arg) typedef WORD (*x) arg __attribute__((stdcall))
|
||||
#define GUARD() __asm__ __volatile__ ("pushfd; cli")
|
||||
#define UNGUARD() __asm__ __volatile__ ("popfd")
|
||||
#define FAR
|
||||
|
||||
#elif defined (__TURBOC__)
|
||||
#define CALLBACK(foo) WORD pascal foo
|
||||
#define PAS_PTR(x,arg) typedef WORD pascal (_far *x) arg
|
||||
#define GUARD() _asm { pushf; cli }
|
||||
#define UNGUARD() _asm { popf }
|
||||
#define FAR _far
|
||||
|
||||
#elif defined (__WATCOMC__)
|
||||
#define CALLBACK(foo) WORD pascal foo
|
||||
#define PAS_PTR(x,arg) typedef WORD pascal (_far *x) arg
|
||||
#define GUARD() _disable()
|
||||
#define UNGUARD() _enable()
|
||||
#define FAR _far
|
||||
|
||||
#else
|
||||
#error Unsupported compiler
|
||||
#endif
|
||||
|
||||
|
||||
/*
|
||||
* Forwards
|
||||
*/
|
||||
struct _ReqBlock;
|
||||
struct _TxBufDescr;
|
||||
struct _TDBufDescr;
|
||||
|
||||
/*
|
||||
* Protocol Manager API
|
||||
*/
|
||||
PAS_PTR (ProtMan, (struct _ReqBlock FAR*, WORD));
|
||||
|
||||
/*
|
||||
* System request
|
||||
*/
|
||||
PAS_PTR (SystemRequest, (DWORD, DWORD, WORD, WORD, WORD));
|
||||
|
||||
/*
|
||||
* MAC API
|
||||
*/
|
||||
PAS_PTR (TransmitChain, (WORD, WORD, struct _TxBufDescr FAR*, WORD));
|
||||
PAS_PTR (TransferData, (WORD*,WORD, struct _TDBufDescr FAR*, WORD));
|
||||
PAS_PTR (Request, (WORD, WORD, WORD, DWORD, WORD, WORD));
|
||||
PAS_PTR (ReceiveRelease,(WORD, WORD));
|
||||
PAS_PTR (IndicationOn, (WORD));
|
||||
PAS_PTR (IndicationOff, (WORD));
|
||||
|
||||
|
||||
typedef enum {
|
||||
HARDWARE_NOT_INSTALLED = 0,
|
||||
HARDWARE_FAILED_DIAG = 1,
|
||||
HARDWARE_FAILED_CONFIG = 2,
|
||||
HARDWARE_HARD_FAULT = 3,
|
||||
HARDWARE_SOFT_FAULT = 4,
|
||||
HARDWARE_OK = 7,
|
||||
HARDWARE_MASK = 0x0007,
|
||||
MAC_BOUND = 0x0008,
|
||||
MAC_OPEN = 0x0010,
|
||||
DIAG_IN_PROGRESS = 0x0020
|
||||
} NdisMacStatus;
|
||||
|
||||
typedef enum {
|
||||
STATUS_RING_STATUS = 1,
|
||||
STATUS_ADAPTER_CHECK = 2,
|
||||
STATUS_START_RESET = 3,
|
||||
STATUS_INTERRUPT = 4,
|
||||
STATUS_END_RESET = 5
|
||||
} NdisStatus;
|
||||
|
||||
typedef enum {
|
||||
FILTER_DIRECTED = 1,
|
||||
FILTER_BROADCAST = 2,
|
||||
FILTER_PROMISCUOUS = 4,
|
||||
FILTER_SOURCE_ROUTE = 8
|
||||
} NdisPacketFilter;
|
||||
|
||||
typedef enum {
|
||||
REQ_INITIATE_DIAGNOSTICS = 1,
|
||||
REQ_READ_ERROR_LOG = 2,
|
||||
REQ_SET_STATION_ADDRESS = 3,
|
||||
REQ_OPEN_ADAPTER = 4,
|
||||
REQ_CLOSE_ADAPTER = 5,
|
||||
REQ_RESET_MAC = 6,
|
||||
REQ_SET_PACKET_FILTER = 7,
|
||||
REQ_ADD_MULTICAST_ADDRESS = 8,
|
||||
REQ_DELETE_MULTICAST_ADDRESS = 9,
|
||||
REQ_UPDATE_STATISTICS = 10,
|
||||
REQ_CLEAR_STATISTICS = 11,
|
||||
REQ_INTERRUPT_REQUEST = 12,
|
||||
REQ_SET_FUNCTIONAL_ADDRESS = 13,
|
||||
REQ_SET_LOOKAHEAD = 14
|
||||
} NdisGeneralRequest;
|
||||
|
||||
typedef enum {
|
||||
SF_BROADCAST = 0x00000001L,
|
||||
SF_MULTICAST = 0x00000002L,
|
||||
SF_FUNCTIONAL = 0x00000004L,
|
||||
SF_PROMISCUOUS = 0x00000008L,
|
||||
SF_SOFT_ADDRESS = 0x00000010L,
|
||||
SF_STATS_CURRENT = 0x00000020L,
|
||||
SF_INITIATE_DIAGS = 0x00000040L,
|
||||
SF_LOOPBACK = 0x00000080L,
|
||||
SF_RECEIVE_CHAIN = 0x00000100L,
|
||||
SF_SOURCE_ROUTING = 0x00000200L,
|
||||
SF_RESET_MAC = 0x00000400L,
|
||||
SF_OPEN_CLOSE = 0x00000800L,
|
||||
SF_INTERRUPT_REQUEST = 0x00001000L,
|
||||
SF_SOURCE_ROUTING_BRIDGE = 0x00002000L,
|
||||
SF_VIRTUAL_ADDRESSES = 0x00004000L
|
||||
} NdisMacServiceFlags;
|
||||
|
||||
typedef enum {
|
||||
REQ_INITIATE_BIND = 1,
|
||||
REQ_BIND = 2,
|
||||
REQ_INITIATE_PREBIND = 3,
|
||||
REQ_INITIATE_UNBIND = 4,
|
||||
REQ_UNBIND = 5
|
||||
} NdisSysRequest;
|
||||
|
||||
typedef enum {
|
||||
PM_GET_PROTOCOL_MANAGER_INFO = 1,
|
||||
PM_REGISTER_MODULE = 2,
|
||||
PM_BIND_AND_START = 3,
|
||||
PM_GET_PROTOCOL_MANAGER_LINKAGE = 4,
|
||||
PM_GET_PROTOCOL_INI_PATH = 5,
|
||||
PM_REGISTER_PROTOCOL_MANAGER_INFO = 6,
|
||||
PM_INIT_AND_REGISTER = 7,
|
||||
PM_UNBIND_AND_STOP = 8,
|
||||
PM_BIND_STATUS = 9,
|
||||
PM_REGISTER_STATUS = 10
|
||||
} NdisProtManager;
|
||||
|
||||
|
||||
typedef enum {
|
||||
ERR_SUCCESS = 0x00,
|
||||
ERR_WAIT_FOR_RELEASE = 0x01,
|
||||
ERR_REQUEST_QUEUED = 0x02,
|
||||
ERR_FRAME_NOT_RECOGNIZED = 0x03,
|
||||
ERR_FRAME_REJECTED = 0x04,
|
||||
ERR_FORWARD_FRAME = 0x05,
|
||||
ERR_OUT_OF_RESOURCE = 0x06,
|
||||
ERR_INVALID_PARAMETER = 0x07,
|
||||
ERR_INVALID_FUNCTION = 0x08,
|
||||
ERR_NOT_SUPPORTED = 0x09,
|
||||
ERR_HARDWARE_ERROR = 0x0A,
|
||||
ERR_TRANSMIT_ERROR = 0x0B,
|
||||
ERR_NO_SUCH_DESTINATION = 0x0C,
|
||||
ERR_BUFFER_TOO_SMALL = 0x0D,
|
||||
ERR_ALREADY_STARTED = 0x20,
|
||||
ERR_INCOMPLETE_BINDING = 0x21,
|
||||
ERR_DRIVER_NOT_INITIALIZED = 0x22,
|
||||
ERR_HARDWARE_NOT_FOUND = 0x23,
|
||||
ERR_HARDWARE_FAILURE = 0x24,
|
||||
ERR_CONFIGURATION_FAILURE = 0x25,
|
||||
ERR_INTERRUPT_CONFLICT = 0x26,
|
||||
ERR_INCOMPATIBLE_MAC = 0x27,
|
||||
ERR_INITIALIZATION_FAILED = 0x28,
|
||||
ERR_NO_BINDING = 0x29,
|
||||
ERR_NETWORK_MAY_NOT_BE_CONNECTED = 0x2A,
|
||||
ERR_INCOMPATIBLE_OS_VERSION = 0x2B,
|
||||
ERR_ALREADY_REGISTERED = 0x2C,
|
||||
ERR_PATH_NOT_FOUND = 0x2D,
|
||||
ERR_INSUFFICIENT_MEMORY = 0x2E,
|
||||
ERR_INFO_NOT_FOUND = 0x2F,
|
||||
ERR_GENERAL_FAILURE = 0xFF
|
||||
} NdisError;
|
||||
|
||||
#define NDIS_PARAM_INTEGER 0
|
||||
#define NDIS_PARAM_STRING 1
|
||||
|
||||
#define NDIS_TX_BUF_LENGTH 8
|
||||
#define NDIS_TD_BUF_LENGTH 1
|
||||
#define NDIS_RX_BUF_LENGTH 8
|
||||
|
||||
#define NDIS_PTR_PHYSICAL 0
|
||||
#define NDIS_PTR_VIRTUAL 2
|
||||
|
||||
#define NDIS_PATH "PROTMAN$"
|
||||
|
||||
|
||||
typedef struct _CommonChars {
|
||||
WORD tableSize;
|
||||
BYTE majorNdisVersion; /* 2 - Latest version */
|
||||
BYTE minorNdisVersion; /* 0 */
|
||||
WORD reserved1;
|
||||
BYTE majorModuleVersion;
|
||||
BYTE minorModuleVersion;
|
||||
DWORD moduleFlags;
|
||||
/* 0 - Binding at upper boundary supported
|
||||
* 1 - Binding at lower boundary supported
|
||||
* 2 - Dynamically bound.
|
||||
* 3-31 - Reserved, must be zero.
|
||||
*/
|
||||
BYTE moduleName[16];
|
||||
BYTE protocolLevelUpper;
|
||||
/* 1 - MAC
|
||||
* 2 - Data Link
|
||||
* 3 - Network
|
||||
* 4 - Transport
|
||||
* 5 - Session
|
||||
* -1 - Not specified
|
||||
*/
|
||||
BYTE interfaceUpper;
|
||||
BYTE protocolLevelLower;
|
||||
/* 0 - Physical
|
||||
* 1 - MAC
|
||||
* 2 - Data Link
|
||||
* 3 - Network
|
||||
* 4 - Transport
|
||||
* 5 - Session
|
||||
* -1 - Not specified
|
||||
*/
|
||||
BYTE interfaceLower;
|
||||
WORD moduleId;
|
||||
WORD moduleDS;
|
||||
SystemRequest systemRequest;
|
||||
BYTE *serviceChars;
|
||||
BYTE *serviceStatus;
|
||||
BYTE *upperDispatchTable;
|
||||
BYTE *lowerDispatchTable;
|
||||
BYTE *reserved2; /* Must be NULL */
|
||||
BYTE *reserved3; /* Must be NULL */
|
||||
} CommonChars;
|
||||
|
||||
|
||||
typedef struct _MulticastList {
|
||||
WORD maxMulticastAddresses;
|
||||
WORD numberMulticastAddresses;
|
||||
BYTE multicastAddress[16][16];
|
||||
} MulticastList;
|
||||
|
||||
|
||||
typedef struct _MacChars {
|
||||
WORD tableSize;
|
||||
BYTE macName[16];
|
||||
WORD addressLength;
|
||||
BYTE permanentAddress[16];
|
||||
BYTE currentAddress[16];
|
||||
DWORD currentFunctionalAddress;
|
||||
MulticastList *multicastList;
|
||||
DWORD linkSpeed;
|
||||
DWORD serviceFlags;
|
||||
WORD maxFrameSize;
|
||||
DWORD txBufferSize;
|
||||
WORD txBufferAllocSize;
|
||||
DWORD rxBufferSize;
|
||||
WORD rxBufferAllocSize;
|
||||
BYTE ieeeVendor[3];
|
||||
BYTE vendorAdapter;
|
||||
BYTE *vendorAdapterDescription;
|
||||
WORD interruptLevel;
|
||||
WORD txQueueDepth;
|
||||
WORD maxDataBlocks;
|
||||
} MacChars;
|
||||
|
||||
|
||||
typedef struct _ProtocolChars {
|
||||
WORD length;
|
||||
BYTE name[16];
|
||||
WORD type;
|
||||
} ProtocolChars;
|
||||
|
||||
|
||||
typedef struct _MacUpperDispatch {
|
||||
CommonChars *backPointer;
|
||||
Request request;
|
||||
TransmitChain transmitChain;
|
||||
TransferData transferData;
|
||||
ReceiveRelease receiveRelease;
|
||||
IndicationOn indicationOn;
|
||||
IndicationOff indicationOff;
|
||||
} MacUpperDispatch;
|
||||
|
||||
|
||||
typedef struct _MacStatusTable {
|
||||
WORD tableSize;
|
||||
DWORD lastDiag;
|
||||
DWORD macStatus;
|
||||
WORD packetFilter;
|
||||
BYTE *mediaSpecificStats;
|
||||
DWORD lastClear;
|
||||
DWORD totalFramesRx;
|
||||
DWORD totalFramesCrc;
|
||||
DWORD totalBytesRx;
|
||||
DWORD totalDiscardBufSpaceRx;
|
||||
DWORD totalMulticastRx;
|
||||
DWORD totalBroadcastRx;
|
||||
DWORD obsolete1[5];
|
||||
DWORD totalDiscardHwErrorRx;
|
||||
DWORD totalFramesTx;
|
||||
DWORD totalBytesTx;
|
||||
DWORD totalMulticastTx;
|
||||
DWORD totalBroadcastTx;
|
||||
DWORD obsolete2[2];
|
||||
DWORD totalDiscardTimeoutTx;
|
||||
DWORD totalDiscardHwErrorTx;
|
||||
} MacStatusTable;
|
||||
|
||||
|
||||
typedef struct _ProtDispatch {
|
||||
CommonChars *backPointer;
|
||||
DWORD flags;
|
||||
/* 0 - handles non-LLC frames
|
||||
* 1 - handles specific-LSAP LLC frames
|
||||
* 2 - handles specific-LSAP LLC frames
|
||||
* 3-31 - reserved must be 0
|
||||
*/
|
||||
void (*requestConfirm) (void);
|
||||
void (*transmitConfirm) (void);
|
||||
void (*receiveLookahead) (void);
|
||||
void (*indicationComplete) (void);
|
||||
void (*receiveChain) (void);
|
||||
void (*status) (void);
|
||||
} ProtDispatch;
|
||||
|
||||
|
||||
typedef struct _ReqBlock {
|
||||
WORD opcode;
|
||||
WORD status;
|
||||
BYTE FAR *pointer1;
|
||||
BYTE FAR *pointer2;
|
||||
WORD word1;
|
||||
} ReqBlock;
|
||||
|
||||
|
||||
typedef struct _TxBufDescrRec {
|
||||
BYTE txPtrType;
|
||||
BYTE dummy;
|
||||
WORD txDataLen;
|
||||
BYTE *txDataPtr;
|
||||
} TxBufDescrRec;
|
||||
|
||||
|
||||
typedef struct _TxBufDescr {
|
||||
WORD txImmedLen;
|
||||
BYTE *txImmedPtr;
|
||||
WORD txDataCount;
|
||||
TxBufDescrRec txBufDescrRec[NDIS_TX_BUF_LENGTH];
|
||||
} TxBufDescr;
|
||||
|
||||
|
||||
typedef struct _TDBufDescrRec {
|
||||
BYTE tDPtrType;
|
||||
BYTE dummy;
|
||||
WORD tDDataLen;
|
||||
BYTE *tDDataPtr;
|
||||
} TDBufDescrRec;
|
||||
|
||||
|
||||
typedef struct _TDBufDescr {
|
||||
WORD tDDataCount;
|
||||
TDBufDescrRec tDBufDescrRec[NDIS_TD_BUF_LENGTH];
|
||||
} TDBufDescr;
|
||||
|
||||
|
||||
typedef struct _RxBufDescrRec {
|
||||
WORD rxDataLen;
|
||||
BYTE *rxDataPtr;
|
||||
} RxBufDescrRec;
|
||||
|
||||
|
||||
typedef struct _RxBufDescr {
|
||||
WORD rxDataCount;
|
||||
RxBufDescrRec rxBufDescrRec[NDIS_RX_BUF_LENGTH];
|
||||
} RxBufDescr;
|
||||
|
||||
|
||||
typedef struct _PktBuf {
|
||||
struct _PktBuf *nextLink;
|
||||
struct _PktBuf *prevLink;
|
||||
int handle;
|
||||
int length;
|
||||
int packetLength;
|
||||
DWORD sequence;
|
||||
BYTE *buffer;
|
||||
} PktBuf;
|
||||
|
||||
|
||||
typedef struct _CardHandle {
|
||||
BYTE moduleName[16];
|
||||
CommonChars *common;
|
||||
} CardHandle;
|
||||
|
||||
|
||||
typedef struct _BindingsList {
|
||||
WORD numBindings;
|
||||
BYTE moduleName[2][16];
|
||||
} BindingsList;
|
||||
|
||||
|
||||
typedef struct _FailingModules {
|
||||
BYTE upperModuleName[16];
|
||||
BYTE lowerModuleName[16];
|
||||
} FailingModules;
|
||||
|
||||
|
||||
typedef union _HardwareAddress {
|
||||
BYTE bytes[6];
|
||||
WORD words[3];
|
||||
struct {
|
||||
BYTE bytes[6];
|
||||
} addr;
|
||||
} HardwareAddress;
|
||||
|
||||
|
||||
typedef struct _FddiHeader {
|
||||
BYTE frameControl;
|
||||
HardwareAddress etherDestHost;
|
||||
HardwareAddress etherSrcHost;
|
||||
} FddiHeader;
|
||||
|
||||
|
||||
typedef struct _EthernetIIHeader {
|
||||
HardwareAddress etherDestHost;
|
||||
HardwareAddress etherSrcHost;
|
||||
WORD etherType;
|
||||
} EthernetIIHeader;
|
||||
|
||||
|
||||
typedef struct _Ieee802Dot5Header {
|
||||
HardwareAddress etherDestHost;
|
||||
HardwareAddress etherSrcHost;
|
||||
BYTE routeInfo[30];
|
||||
} Ieee802Dot5Header;
|
||||
|
||||
|
||||
typedef struct _Ieee802Dot2SnapHeader {
|
||||
BYTE dsap; /* 0xAA */
|
||||
BYTE ssap; /* 0xAA */
|
||||
BYTE control; /* 3 */
|
||||
BYTE protocolId[5];
|
||||
} Ieee802Dot2SnapHeader;
|
||||
|
||||
|
||||
/*
|
||||
* Prototypes
|
||||
*/
|
||||
extern char *NdisLastError (void);
|
||||
extern int NdisOpen (void);
|
||||
extern int NdisInit (int promis);
|
||||
extern int NdisRegisterAndBind (int promis);
|
||||
extern void NdisShutdown (void);
|
||||
extern void NdisCheckMacFeatures (struct _CardHandle *card);
|
||||
extern int NdisSendPacket (struct _PktBuf *pktBuf, int macId);
|
||||
|
||||
/*
|
||||
* Assembly "glue" functions
|
||||
*/
|
||||
extern int systemRequestGlue();
|
||||
extern int requestConfirmGlue();
|
||||
extern int transmitConfirmGlue();
|
||||
extern int receiveLookaheadGlue();
|
||||
extern int indicationCompleteGlue();
|
||||
extern int receiveChainGlue();
|
||||
extern int statusGlue();
|
||||
|
||||
/*
|
||||
* IOCTL function
|
||||
*/
|
||||
#ifdef __SMALL__
|
||||
extern int _far NdisGetLinkage (int handle, char *data, int size);
|
||||
#else
|
||||
extern int NdisGetLinkage (int handle, char *data, int size);
|
||||
#endif
|
||||
|
||||
/*
|
||||
* NDIS callback handlers
|
||||
*/
|
||||
CALLBACK (NdisSystemRequest (DWORD,DWORD, WORD, WORD, WORD));
|
||||
CALLBACK (NdisRequestConfirm ( WORD, WORD, WORD, WORD, WORD,WORD));
|
||||
CALLBACK (NdisTransmitConfirm ( WORD, WORD, WORD, WORD, WORD));
|
||||
CALLBACK (NdisReceiveLookahead ( WORD, WORD, WORD, BYTE*, BYTE*, WORD));
|
||||
CALLBACK (NdisReceiveChain ( WORD, WORD, WORD, struct _RxBufDescr*, BYTE*, WORD));
|
||||
CALLBACK (NdisStatusProc ( WORD, WORD, BYTE*, WORD,WORD));
|
||||
CALLBACK (NdisIndicationComplete( WORD, WORD));
|
||||
|
||||
BYTE *NdisAllocStack (void);
|
||||
void NdisFreeStack (BYTE*);
|
||||
|
||||
#ifdef __HIGHC__
|
||||
#define RENAME_ASM_SYM(x) pragma Alias(x,"@" #x "") /* prepend `@' */
|
||||
#define RENAME_C_SYM(x) pragma Alias(x,"_" #x "") /* prepend `_' */
|
||||
|
||||
RENAME_ASM_SYM (systemRequestGlue);
|
||||
RENAME_ASM_SYM (requestConfirmGlue);
|
||||
RENAME_ASM_SYM (transmitConfirmGlue);
|
||||
RENAME_ASM_SYM (receiveLookaheadGlue);
|
||||
RENAME_ASM_SYM (indicationCompleteGlue);
|
||||
RENAME_ASM_SYM (receiveChainGlue);
|
||||
RENAME_ASM_SYM (statusGlue);
|
||||
RENAME_ASM_SYM (NdisGetLinkage);
|
||||
RENAME_C_SYM (NdisSystemRequest);
|
||||
RENAME_C_SYM (NdisRequestConfirm);
|
||||
RENAME_C_SYM (NdisTransmitConfirm);
|
||||
RENAME_C_SYM (NdisReceiveLookahead);
|
||||
RENAME_C_SYM (NdisIndicationComplete);
|
||||
RENAME_C_SYM (NdisReceiveChain);
|
||||
RENAME_C_SYM (NdisStatusProc);
|
||||
RENAME_C_SYM (NdisAllocStack);
|
||||
RENAME_C_SYM (NdisFreeStack);
|
||||
#endif
|
||||
|
||||
#endif
|
|
@ -0,0 +1,188 @@
|
|||
PAGE 60,132
|
||||
NAME NDIS_0
|
||||
|
||||
ifdef DOSX
|
||||
.386
|
||||
_TEXT SEGMENT PUBLIC DWORD USE16 'CODE'
|
||||
_TEXT ENDS
|
||||
_DATA SEGMENT PUBLIC DWORD USE16 'CODE'
|
||||
_DATA ENDS
|
||||
_TEXT32 SEGMENT PUBLIC BYTE USE32 'CODE'
|
||||
_TEXT32 ENDS
|
||||
CB_DSEG EQU <CS> ; DOSX is tiny-model
|
||||
D_SEG EQU <_TEXT SEGMENT>
|
||||
D_END EQU <_TEXT ENDS>
|
||||
ASSUME CS:_TEXT,DS:_TEXT
|
||||
|
||||
PUSHREGS equ <pushad>
|
||||
POPREGS equ <popad>
|
||||
|
||||
PUBPROC macro name
|
||||
align 4
|
||||
public @&name
|
||||
@&name label near
|
||||
endm
|
||||
else
|
||||
.286
|
||||
_TEXT SEGMENT PUBLIC DWORD 'CODE'
|
||||
_TEXT ENDS
|
||||
_DATA SEGMENT PUBLIC DWORD 'DATA'
|
||||
_DATA ENDS
|
||||
CB_DSEG EQU <SEG _DATA> ; 16bit is small/large model
|
||||
D_SEG EQU <_DATA SEGMENT>
|
||||
D_END EQU <_DATA ENDS>
|
||||
ASSUME CS:_TEXT,DS:_DATA
|
||||
|
||||
PUSHREGS equ <pusha>
|
||||
POPREGS equ <popa>
|
||||
|
||||
PUBPROC macro name
|
||||
public _&name
|
||||
_&name label far
|
||||
endm
|
||||
endif
|
||||
|
||||
;-------------------------------------------
|
||||
|
||||
D_SEG
|
||||
|
||||
D_END
|
||||
|
||||
|
||||
_TEXT SEGMENT
|
||||
|
||||
EXTRN _NdisSystemRequest : near
|
||||
EXTRN _NdisRequestConfirm : near
|
||||
EXTRN _NdisTransmitConfirm : near
|
||||
EXTRN _NdisReceiveLookahead : near
|
||||
EXTRN _NdisIndicationComplete : near
|
||||
EXTRN _NdisReceiveChain : near
|
||||
EXTRN _NdisStatusProc : near
|
||||
EXTRN _NdisAllocStack : near
|
||||
EXTRN _NdisFreeStack : near
|
||||
|
||||
;
|
||||
; *ALL* interrupt threads come through this macro.
|
||||
;
|
||||
CALLBACK macro callbackProc, argsSize
|
||||
|
||||
pushf
|
||||
PUSHREGS ;; Save the registers
|
||||
|
||||
push es
|
||||
push ds
|
||||
mov ax,CB_DSEG ;; Load DS
|
||||
mov ds,ax
|
||||
call _NdisAllocStack ;; Get and install a stack.
|
||||
|
||||
mov bx,ss ;; Save off the old stack in other regs
|
||||
mov cx,sp
|
||||
mov ss,dx ;; Install the new one
|
||||
mov sp,ax
|
||||
push bx ;; Save the old one on to the new stack
|
||||
push cx
|
||||
sub sp,&argsSize ;; Allocate space for arguments on the stack
|
||||
|
||||
mov ax,ss ;; Set up the destination for the move
|
||||
mov es,ax
|
||||
mov di,sp
|
||||
mov ds,bx ;; Set up the source for the move.
|
||||
mov si,cx
|
||||
add si,4+6+32
|
||||
|
||||
mov cx,&argsSize ;; Move the arguments to the stack.
|
||||
shr cx,1
|
||||
cld
|
||||
rep movsw
|
||||
|
||||
mov ax,CB_DSEG ;; Set my data segment again.
|
||||
mov ds,ax
|
||||
|
||||
call &callbackProc ;; Call the real callback.
|
||||
pop di ;; Pop off the old stack
|
||||
pop si
|
||||
mov bx,ss ;; Save off the current allocated stack.
|
||||
mov cx,sp
|
||||
mov ss,si ;; Restore the old stack
|
||||
mov sp,di
|
||||
push ax ;; Save the return code
|
||||
push bx ;; Free the stack. Push the pointer to it
|
||||
push cx
|
||||
call _NdisFreeStack
|
||||
add sp,4
|
||||
pop ax ;; Get the return code back
|
||||
add di,32 ;; Get a pointer to ax on the stack
|
||||
mov word ptr ss:[di],ax
|
||||
pop ds
|
||||
pop es
|
||||
|
||||
POPREGS
|
||||
popf
|
||||
endm
|
||||
|
||||
;
|
||||
; Define all of the callbacks for the NDIS procs.
|
||||
;
|
||||
|
||||
PUBPROC systemRequestGlue
|
||||
CALLBACK _NdisSystemRequest,14
|
||||
RETF
|
||||
|
||||
PUBPROC requestConfirmGlue
|
||||
CALLBACK _NdisRequestConfirm,12
|
||||
RETF
|
||||
|
||||
PUBPROC transmitConfirmGlue
|
||||
CALLBACK _NdisTransmitConfirm,10
|
||||
RETF
|
||||
|
||||
PUBPROC receiveLookaheadGlue
|
||||
CALLBACK _NdisReceiveLookahead,16
|
||||
RETF
|
||||
|
||||
PUBPROC indicationCompleteGlue
|
||||
CALLBACK _NdisIndicationComplete,4
|
||||
RETF
|
||||
|
||||
PUBPROC receiveChainGlue
|
||||
CALLBACK _NdisReceiveChain,16
|
||||
RETF
|
||||
|
||||
PUBPROC statusGlue
|
||||
CALLBACK _NdisStatusProc,12
|
||||
RETF
|
||||
|
||||
;
|
||||
; int FAR NdisGetLinkage (int handle, char *data, int size);
|
||||
;
|
||||
|
||||
ifdef DOSX
|
||||
PUBPROC NdisGetLinkage
|
||||
push ebx
|
||||
mov ebx, [esp+8] ; device handle
|
||||
mov eax, 4402h ; IOCTRL read function
|
||||
mov edx, [esp+12] ; DS:EDX -> result data
|
||||
mov ecx, [esp+16] ; ECX = length
|
||||
int 21h
|
||||
pop ebx
|
||||
jc @fail
|
||||
xor eax, eax
|
||||
@fail: ret
|
||||
|
||||
else
|
||||
PUBPROC NdisGetLinkage
|
||||
enter 0, 0
|
||||
mov bx, [bp+6]
|
||||
mov ax, 4402h
|
||||
mov dx, [bp+8]
|
||||
mov cx, [bp+12]
|
||||
int 21h
|
||||
jc @fail
|
||||
xor ax, ax
|
||||
@fail: leave
|
||||
retf
|
||||
endif
|
||||
|
||||
ENDS
|
||||
|
||||
END
|
|
@ -0,0 +1,197 @@
|
|||
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
|
|
@ -0,0 +1,155 @@
|
|||
;
|
||||
; 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)
|
||||
%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
|
||||
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,153 @@
|
|||
#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/Interl/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 */
|
||||
|
|
@ -0,0 +1,156 @@
|
|||
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 trucated filenames.
|
||||
So for djgpp to work with these, disable the use of long file names by
|
||||
setting "LFN=n" in the environment.
|
||||
|
||||
Files specific to DOS are pcap-dos.[ch] and the assembly and C files in
|
||||
the MSDOS sub-directory. Remember to built lipcap libraries from the top
|
||||
install directory. And not from the MSDOS sub-directory.
|
||||
|
||||
|
||||
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
|
||||
opporunity 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:
|
||||
|
||||
http://www.bgnett.no/~giva/
|
||||
|
||||
2. Exception handler and disassember library (libexc.a) is needed if
|
||||
"USE_EXCEPT = 1" in common.dj. Available at:
|
||||
|
||||
http://www.bgnett.no/~giva/misc/exc_dx07.zip
|
||||
|
||||
3. Flex & Bison is used to generate parser for the filter handler
|
||||
pcap_compile:
|
||||
|
||||
ftp://ftp.simtel.net/pub/simtelnet/gnu/djgpp/v2gnu/flx254b.zip
|
||||
ftp://ftp.simtel.net/pub/simtelnet/gnu/djgpp/v2gnu/bsn128b.zip
|
||||
|
||||
4. NASM assembler v 0.98 or later is required when building djgpp and
|
||||
Watcom targets:
|
||||
|
||||
ftp://ftp.simtel.net/pub/simtelnet/gnu/djgpp/v2tk/nasm098p.zip
|
||||
|
||||
5. sed (Stream Editor) is required for doing `make depend'.
|
||||
It's available at
|
||||
ftp://ftp.simtel.net/pub/simtelnet/gnu/djgpp/v2gnu/sed*.zip
|
||||
|
||||
A touch tool to update the time-stamp of a file. E.g.
|
||||
ftp://ftp.simtel.net/pub/simtelnet/gnu/djgpp/v2gnu/grep*.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 libraries are put in current directory. There's no
|
||||
test-program for `libpcap'. Linking the library with `tcpdump' is
|
||||
the ultimate test anyway.
|
||||
|
||||
|
||||
|
||||
Extensions to libpcap
|
||||
---------------------
|
||||
|
||||
I've included some extra functions to DOS-libpcap:
|
||||
|
||||
`pcap_config_hook (const char *name, const char *value)'
|
||||
|
||||
Allows an application to set values of internal libpcap variables.
|
||||
`name' is typically a left-side keyword with an associated `value'
|
||||
that is called from application's configure process (see tcpdump's
|
||||
config.c file). libpcap keeps a set of tables that are searched for
|
||||
a name/value match. Currently only used to set debug-levels and
|
||||
parameters for the 32-bit network drivers.
|
||||
|
||||
`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.
|
||||
|
||||
`pcap_verbose (int mode)' :
|
||||
Sets the internal verbosity mode. Currently only effective while
|
||||
capturing packets to file (the `-w' option in tcpdump). `pcap_dump()'
|
||||
will print to `stderr' number of packets dumped.
|
||||
|
||||
|
||||
|
||||
Happy sniffing !
|
||||
|
||||
|
||||
Gisle Vanem <giva@bgnett.no>
|
||||
<gvanem@broadpark.no>
|
||||
|
||||
October 1999, 2004
|
||||
|
|
@ -22,7 +22,7 @@
|
|||
*/
|
||||
#ifndef lint
|
||||
static const char rcsid[] _U_ =
|
||||
"@(#) $Header: /tcpdump/master/libpcap/optimize.c,v 1.83 2004-11-14 03:10:33 guy Exp $ (LBL)";
|
||||
"@(#) $Header: /tcpdump/master/libpcap/optimize.c,v 1.84 2004-12-18 08:52:09 guy Exp $ (LBL)";
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
|
@ -32,6 +32,7 @@ static const char rcsid[] _U_ =
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <memory.h>
|
||||
#include <string.h>
|
||||
|
||||
#include <errno.h>
|
||||
|
||||
|
@ -47,6 +48,11 @@ static const char rcsid[] _U_ =
|
|||
extern int dflag;
|
||||
#endif
|
||||
|
||||
#if defined(MSDOS) && !defined(__DJGPP__)
|
||||
extern int _w32_ffs (int mask);
|
||||
#define ffs _w32_ffs
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Represents a deleted instruction.
|
||||
*/
|
||||
|
|
|
@ -37,7 +37,7 @@
|
|||
*
|
||||
* @(#)bpf.h 7.1 (Berkeley) 5/7/91
|
||||
*
|
||||
* @(#) $Header: /tcpdump/master/libpcap/pcap-bpf.h,v 1.27 2004-12-09 19:03:36 guy Exp $ (LBL)
|
||||
* @(#) $Header: /tcpdump/master/libpcap/pcap-bpf.h,v 1.28 2004-12-18 08:52:10 guy Exp $ (LBL)
|
||||
*/
|
||||
|
||||
/*
|
||||
|
@ -60,8 +60,13 @@ extern "C" {
|
|||
/* BSD style release date */
|
||||
#define BPF_RELEASE 199606
|
||||
|
||||
#ifdef MSDOS /* must be 32-bit */
|
||||
typedef long bpf_int32;
|
||||
typedef unsigned long bpf_u_int32;
|
||||
#else
|
||||
typedef int bpf_int32;
|
||||
typedef u_int bpf_u_int32;
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Alignment macros. BPF_WORDALIGN rounds up to the next
|
||||
|
|
File diff suppressed because it is too large
Load Diff
|
@ -0,0 +1,227 @@
|
|||
/*
|
||||
* Internal details for libpcap on DOS.
|
||||
* 32-bit targets: djgpp, Pharlap or DOS4GW.
|
||||
*
|
||||
* @(#) $Header: /tcpdump/master/libpcap/pcap-dos.h,v 1.1 2004-12-18 08:52:10 guy Exp $ (LBL)
|
||||
*/
|
||||
|
||||
#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 */
|
14
pcap-int.h
14
pcap-int.h
|
@ -30,7 +30,7 @@
|
|||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#) $Header: /tcpdump/master/libpcap/pcap-int.h,v 1.67 2004-12-17 20:32:35 guy Exp $ (LBL)
|
||||
* @(#) $Header: /tcpdump/master/libpcap/pcap-int.h,v 1.68 2004-12-18 08:52:10 guy Exp $ (LBL)
|
||||
*/
|
||||
|
||||
#ifndef pcap_int_h
|
||||
|
@ -46,6 +46,11 @@ extern "C" {
|
|||
#include <packet32.h>
|
||||
#endif /* WIN32 */
|
||||
|
||||
#ifdef MSDOS
|
||||
#include <fcntl.h>
|
||||
#include <io.h>
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Savefile
|
||||
*/
|
||||
|
@ -116,6 +121,11 @@ struct pcap {
|
|||
int fddipad;
|
||||
#endif
|
||||
|
||||
#ifdef MSDOS
|
||||
int inter_packet_wait; /* offline: wait between packets */
|
||||
void (*wait_proc)(void); /* call proc while waiting */
|
||||
#endif
|
||||
|
||||
struct pcap_sf sf;
|
||||
struct pcap_md md;
|
||||
|
||||
|
@ -259,7 +269,7 @@ extern int vsnprintf (char *, size_t, const char *, va_list ap);
|
|||
/*
|
||||
* Routines that most pcap implementations can use for non-blocking mode.
|
||||
*/
|
||||
#ifndef WIN32
|
||||
#if !defined(WIN32) && !defined(MSDOS)
|
||||
int pcap_getnonblock_fd(pcap_t *, char *);
|
||||
int pcap_setnonblock_fd(pcap_t *p, int, char *);
|
||||
#endif
|
||||
|
|
50
pcap.c
50
pcap.c
|
@ -33,7 +33,7 @@
|
|||
|
||||
#ifndef lint
|
||||
static const char rcsid[] _U_ =
|
||||
"@(#) $Header: /tcpdump/master/libpcap/pcap.c,v 1.79 2004-12-17 23:25:36 guy Exp $ (LBL)";
|
||||
"@(#) $Header: /tcpdump/master/libpcap/pcap.c,v 1.80 2004-12-18 08:52:11 guy Exp $ (LBL)";
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
|
@ -49,7 +49,7 @@ static const char rcsid[] _U_ =
|
|||
#include <stdio.h>
|
||||
#include <stdlib.h>
|
||||
#include <string.h>
|
||||
#ifndef _MSC_VER
|
||||
#if !defined(_MSC_VER) && !defined(__BORLANDC__)
|
||||
#include <unistd.h>
|
||||
#endif
|
||||
#include <fcntl.h>
|
||||
|
@ -59,6 +59,10 @@ static const char rcsid[] _U_ =
|
|||
#include "os-proto.h"
|
||||
#endif
|
||||
|
||||
#ifdef MSDOS
|
||||
#include "pcap-dos.h"
|
||||
#endif
|
||||
|
||||
#include "pcap-int.h"
|
||||
|
||||
#ifdef HAVE_DAG_API
|
||||
|
@ -528,7 +532,7 @@ pcap_fileno(pcap_t *p)
|
|||
#endif
|
||||
}
|
||||
|
||||
#ifndef WIN32
|
||||
#if !defined(WIN32) && !defined(MSDOS)
|
||||
int
|
||||
pcap_get_selectable_fd(pcap_t *p)
|
||||
{
|
||||
|
@ -561,7 +565,7 @@ pcap_getnonblock(pcap_t *p, char *errbuf)
|
|||
* We don't look at "p->nonblock", in case somebody tweaked the FD
|
||||
* directly.
|
||||
*/
|
||||
#ifndef WIN32
|
||||
#if !defined(WIN32) && !defined(MSDOS)
|
||||
int
|
||||
pcap_getnonblock_fd(pcap_t *p, char *errbuf)
|
||||
{
|
||||
|
@ -586,7 +590,7 @@ pcap_setnonblock(pcap_t *p, int nonblock, char *errbuf)
|
|||
return p->setnonblock_op(p, nonblock, errbuf);
|
||||
}
|
||||
|
||||
#ifndef WIN32
|
||||
#if !defined(WIN32) && !defined(MSDOS)
|
||||
/*
|
||||
* Set non-blocking mode, under the assumption that it's just the
|
||||
* standard POSIX non-blocking flag. (This can be called by the
|
||||
|
@ -629,6 +633,7 @@ pcap_win32strerror(void)
|
|||
DWORD error;
|
||||
static char errbuf[PCAP_ERRBUF_SIZE+1];
|
||||
int errlen;
|
||||
char *p;
|
||||
|
||||
error = GetLastError();
|
||||
FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, error, 0, errbuf,
|
||||
|
@ -643,6 +648,8 @@ pcap_win32strerror(void)
|
|||
errbuf[errlen - 1] = '\0';
|
||||
errbuf[errlen - 2] = '\0';
|
||||
}
|
||||
p = strchr(errbuf, '\0');
|
||||
snprintf (p, sizeof(errbuf)-(p-errbuf), " (%lu)", error);
|
||||
return (errbuf);
|
||||
}
|
||||
#endif
|
||||
|
@ -692,7 +699,7 @@ pcap_close_common(pcap_t *p)
|
|||
{
|
||||
if (p->buffer != NULL)
|
||||
free(p->buffer);
|
||||
#ifndef WIN32
|
||||
#if !defined(WIN32) && !defined(MSDOS)
|
||||
if (p->fd >= 0)
|
||||
close(p->fd);
|
||||
#endif
|
||||
|
@ -778,7 +785,7 @@ static const char pcap_version_string[] = "libpcap version 0.9[.x]";
|
|||
* version numbers when building WinPcap. (It'd be nice to do so for
|
||||
* the packet.dll version number as well.)
|
||||
*/
|
||||
static const char wpcap_version_string[] = "3.0";
|
||||
static const char wpcap_version_string[] = "3.1";
|
||||
static const char pcap_version_string_fmt[] =
|
||||
"WinPcap version %s, based on %s";
|
||||
static const char pcap_version_string_packet_dll_fmt[] =
|
||||
|
@ -833,7 +840,34 @@ pcap_lib_version(void)
|
|||
}
|
||||
return (full_pcap_version_string);
|
||||
}
|
||||
#else
|
||||
|
||||
#elif defined(MSDOS)
|
||||
|
||||
static char *full_pcap_version_string;
|
||||
|
||||
const char *
|
||||
pcap_lib_version (void)
|
||||
{
|
||||
char *packet_version_string;
|
||||
size_t full_pcap_version_string_len;
|
||||
static char dospfx[] = "DOS-";
|
||||
|
||||
if (full_pcap_version_string == NULL) {
|
||||
/*
|
||||
* Generate the version string.
|
||||
*/
|
||||
full_pcap_version_string_len =
|
||||
sizeof dospfx + strlen(pcap_version_string);
|
||||
full_pcap_version_string =
|
||||
malloc(full_pcap_version_string_len);
|
||||
strcpy(full_pcap_version_string, dospfx);
|
||||
strcat(full_pcap_version_string, pcap_version_string);
|
||||
}
|
||||
return (full_pcap_version_string);
|
||||
}
|
||||
|
||||
#else /* UN*X */
|
||||
|
||||
const char *
|
||||
pcap_lib_version(void)
|
||||
{
|
||||
|
|
70
pcap.h
70
pcap.h
|
@ -31,18 +31,21 @@
|
|||
* OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
|
||||
* SUCH DAMAGE.
|
||||
*
|
||||
* @(#) $Header: /tcpdump/master/libpcap/pcap.h,v 1.51 2004-11-07 21:40:48 guy Exp $ (LBL)
|
||||
* @(#) $Header: /tcpdump/master/libpcap/pcap.h,v 1.52 2004-12-18 08:52:11 guy Exp $ (LBL)
|
||||
*/
|
||||
|
||||
#ifndef lib_pcap_h
|
||||
#define lib_pcap_h
|
||||
|
||||
#ifdef WIN32
|
||||
#include <pcap-stdinc.h>
|
||||
#else /* WIN32 */
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#endif /* WIN32 */
|
||||
#if defined(WIN32)
|
||||
#include <pcap-stdinc.h>
|
||||
#elif defined(MSDOS)
|
||||
#include <sys/types.h>
|
||||
#include <sys/socket.h> /* u_int, u_char etc. */
|
||||
#else /* UN*X */
|
||||
#include <sys/types.h>
|
||||
#include <sys/time.h>
|
||||
#endif /* WIN32/MSDOS/UN*X */
|
||||
|
||||
#ifndef PCAP_DONT_INCLUDE_PCAP_BPF_H
|
||||
#include <pcap-bpf.h>
|
||||
|
@ -140,6 +143,39 @@ struct pcap_stat {
|
|||
#endif /* WIN32 */
|
||||
};
|
||||
|
||||
#ifdef MSDOS
|
||||
/*
|
||||
* As returned by the pcap_stats_ex()
|
||||
*/
|
||||
struct pcap_stat_ex {
|
||||
u_long rx_packets; /* total packets received */
|
||||
u_long tx_packets; /* total packets transmitted */
|
||||
u_long rx_bytes; /* total bytes received */
|
||||
u_long tx_bytes; /* total bytes transmitted */
|
||||
u_long rx_errors; /* bad packets received */
|
||||
u_long tx_errors; /* packet transmit problems */
|
||||
u_long rx_dropped; /* no space in Rx buffers */
|
||||
u_long tx_dropped; /* no space available for Tx */
|
||||
u_long multicast; /* multicast packets received */
|
||||
u_long collisions;
|
||||
|
||||
/* detailed rx_errors: */
|
||||
u_long rx_length_errors;
|
||||
u_long rx_over_errors; /* receiver ring buff overflow */
|
||||
u_long rx_crc_errors; /* recv'd pkt with crc error */
|
||||
u_long rx_frame_errors; /* recv'd frame alignment error */
|
||||
u_long rx_fifo_errors; /* recv'r fifo overrun */
|
||||
u_long rx_missed_errors; /* recv'r missed packet */
|
||||
|
||||
/* detailed tx_errors */
|
||||
u_long tx_aborted_errors;
|
||||
u_long tx_carrier_errors;
|
||||
u_long tx_fifo_errors;
|
||||
u_long tx_heartbeat_errors;
|
||||
u_long tx_window_errors;
|
||||
};
|
||||
#endif
|
||||
|
||||
/*
|
||||
* Item in a list of interfaces.
|
||||
*/
|
||||
|
@ -227,7 +263,8 @@ int bpf_validate(struct bpf_insn *f, int len);
|
|||
char *bpf_image(struct bpf_insn *, int);
|
||||
void bpf_dump(struct bpf_program *, int);
|
||||
|
||||
#ifdef WIN32
|
||||
#if defined(WIN32)
|
||||
|
||||
/*
|
||||
* Win32 definitions
|
||||
*/
|
||||
|
@ -239,20 +276,31 @@ int pcap_setmintocopy(pcap_t *p, int size);
|
|||
#ifdef WPCAP
|
||||
/* Include file with the wpcap-specific extensions */
|
||||
#include <Win32-Extensions.h>
|
||||
#endif
|
||||
#endif /* WPCAP */
|
||||
|
||||
#define MODE_CAPT 0
|
||||
#define MODE_STAT 1
|
||||
#define MODE_MON 2
|
||||
|
||||
#else
|
||||
#elif defined(MSDOS)
|
||||
|
||||
/*
|
||||
* MS-DOS definitions
|
||||
*/
|
||||
|
||||
int pcap_stats_ex (pcap_t *, struct pcap_stat_ex *);
|
||||
void pcap_set_wait (pcap_t *p, void (*yield)(void), int wait);
|
||||
u_long pcap_mac_packets (void);
|
||||
|
||||
#else /* UN*X */
|
||||
|
||||
/*
|
||||
* UN*X definitions
|
||||
*/
|
||||
|
||||
int pcap_get_selectable_fd(pcap_t *);
|
||||
|
||||
#endif /* WIN32 */
|
||||
#endif /* WIN32/MSDOS/UN*X */
|
||||
|
||||
#ifdef __cplusplus
|
||||
}
|
||||
|
|
29
savefile.c
29
savefile.c
|
@ -30,7 +30,7 @@
|
|||
|
||||
#ifndef lint
|
||||
static const char rcsid[] _U_ =
|
||||
"@(#) $Header: /tcpdump/master/libpcap/savefile.c,v 1.118 2004-12-17 20:26:16 guy Exp $ (LBL)";
|
||||
"@(#) $Header: /tcpdump/master/libpcap/savefile.c,v 1.119 2004-12-18 08:52:11 guy Exp $ (LBL)";
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_CONFIG_H
|
||||
|
@ -88,6 +88,19 @@ static const char rcsid[] _U_ =
|
|||
#define SFERR_BADF 3
|
||||
#define SFERR_EOF 4 /* not really an error, just a status */
|
||||
|
||||
/*
|
||||
* Setting O_BINARY on DOS/Windows is a bit tricky
|
||||
*/
|
||||
#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
|
||||
|
||||
/*
|
||||
* We don't write DLT_* values to the capture file header, because
|
||||
* they're not the same on all platforms.
|
||||
|
@ -657,7 +670,7 @@ pcap_open_offline(const char *fname, char *errbuf)
|
|||
if (fname[0] == '-' && fname[1] == '\0')
|
||||
fp = stdin;
|
||||
else {
|
||||
#ifndef WIN32
|
||||
#if !defined(WIN32) && !defined(MSDOS)
|
||||
fp = fopen(fname, "r");
|
||||
#else
|
||||
fp = fopen(fname, "rb");
|
||||
|
@ -816,7 +829,7 @@ pcap_fopen_offline(FILE *fp, char *errbuf)
|
|||
break;
|
||||
}
|
||||
|
||||
#ifndef WIN32
|
||||
#if !defined(WIN32) && !defined(MSDOS)
|
||||
/*
|
||||
* You can do "select()" and "poll()" on plain files on most
|
||||
* platforms, and should be able to do so on pipes.
|
||||
|
@ -836,13 +849,13 @@ pcap_fopen_offline(FILE *fp, char *errbuf)
|
|||
p->stats_op = sf_stats;
|
||||
p->close_op = sf_close;
|
||||
|
||||
#ifdef WIN32
|
||||
#if defined(WIN32) || defined(MSDOS)
|
||||
/*
|
||||
* If we're reading from the standard input, put it in binary
|
||||
* mode, as savefiles are binary files.
|
||||
*/
|
||||
if (fp == stdin)
|
||||
_setmode(_fileno(f), _O_BINARY);
|
||||
SET_BINMODE(fp);
|
||||
#endif
|
||||
|
||||
return (p);
|
||||
|
@ -1067,7 +1080,7 @@ static pcap_dumper_t *
|
|||
pcap_setup_dump(pcap_t *p, int linktype, FILE *f, const char *fname)
|
||||
{
|
||||
|
||||
#ifdef WIN32
|
||||
#if defined(WIN32) || defined(MSDOS)
|
||||
/*
|
||||
* If we're writing to the standard output, put it in binary
|
||||
* mode, as savefiles are binary files.
|
||||
|
@ -1076,7 +1089,7 @@ pcap_setup_dump(pcap_t *p, int linktype, FILE *f, const char *fname)
|
|||
* XXX - why? And why not on the standard output?
|
||||
*/
|
||||
if (f == stdout)
|
||||
_setmode(_fileno(f), _O_BINARY);
|
||||
SET_BINMODE(f);
|
||||
else
|
||||
setbuf(f, NULL);
|
||||
#endif
|
||||
|
@ -1111,7 +1124,7 @@ pcap_dump_open(pcap_t *p, const char *fname)
|
|||
f = stdout;
|
||||
fname = "standard output";
|
||||
} else {
|
||||
#ifndef WIN32
|
||||
#if !defined(WIN32) && !defined(MSDOS)
|
||||
f = fopen(fname, "w");
|
||||
#else
|
||||
f = fopen(fname, "wb");
|
||||
|
|
Reference in New Issue