dect
/
libpcap
Archived
1
0
Fork 0

From Gisle Vanem: MS-DOS support.

master
guy 18 years ago
parent f912cc399c
commit f8a76d1d76
  1. 15
      FILES
  2. 5
      INSTALL.txt
  3. 6
      gencode.c
  4. 14
      inet.c
  5. 43
      msdos/bin2c.c
  6. 79
      msdos/common.dj
  7. 184
      msdos/makefile
  8. 147
      msdos/makefile.dj
  9. 131
      msdos/makefile.wc
  10. 860
      msdos/ndis2.c
  11. 559
      msdos/ndis2.h
  12. 188
      msdos/ndis_0.asm
  13. 197
      msdos/pkt_rx0.asm
  14. 155
      msdos/pkt_rx1.s
  15. 1437
      msdos/pktdrvr.c
  16. 153
      msdos/pktdrvr.h
  17. 156
      msdos/readme.dos
  18. 8
      optimize.c
  19. 7
      pcap-bpf.h
  20. 1473
      pcap-dos.c
  21. 227
      pcap-dos.h
  22. 14
      pcap-int.h
  23. 50
      pcap.c
  24. 70
      pcap.h
  25. 29
      savefile.c

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"

@ -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