2 * (C)opyright 1992-1998 Darren Reed. (from tcplog)
4 * See the IPFILTER.LICENCE file for details on licencing.
14 #include <sys/types.h>
16 #include <sys/timeb.h>
17 #include <sys/socket.h>
19 #include <sys/ioctl.h>
20 #include <sys/stropts.h>
23 # include <sys/pfmod.h>
24 # include <sys/bufmod.h>
27 # include <sys/dlpihdr.h>
29 # include <sys/dlpi.h>
32 # include <sys/dlpi_ext.h>
36 #include <netinet/in.h>
37 #include <netinet/in_systm.h>
38 #include <netinet/ip.h>
39 #include <netinet/if_ether.h>
40 #include <netinet/ip_var.h>
41 #include <netinet/udp.h>
42 #include <netinet/udp_var.h>
43 #include <netinet/tcp.h>
48 static const char sccsid[] = "@(#)sdlpi.c 1.3 10/30/95 (C)1995 Darren Reed";
49 static const char rcsid[] = "@(#)$Id$";
52 #define CHUNKSIZE 8192
53 #define BUFSPACE (4*CHUNKSIZE)
57 * Be careful to only include those defined in the flags option for the
58 * interface are included in the header size.
60 int initdevice(device, tout)
64 char devname[16], *s, buf[256];
67 (void) strcpy(devname, "/dev/");
68 (void) strncat(devname, device, sizeof(devname) - strlen(devname));
71 while (*s && !ISDIGIT(*s))
75 fprintf(stderr, "bad device name %s\n", devname);
83 if ((fd = open(devname, O_RDWR)) < 0)
85 fprintf(stderr, "O_RDWR(1) ");
90 if (dlattachreq(fd, i) == -1)
92 fprintf(stderr, "dlattachreq: DLPI error\n");
95 else if (dlokack(fd, buf) == -1)
97 fprintf(stderr, "dlokack(attach): DLPI error\n");
101 if (dlpromisconreq(fd, DL_PROMISC_SAP) < 0)
103 fprintf(stderr, "dlpromisconreq: DL_PROMISC_PHYS error\n");
106 else if (dlokack(fd, buf) < 0)
108 fprintf(stderr, "dlokack(promisc): DLPI error\n");
111 /* 22 is INSAP as per the HP-UX DLPI Programmer's Guide */
113 dlbindreq(fd, 22, 1, DL_HP_RAWDLS, 0, 0);
115 dlbindreq(fd, ETHERTYPE_IP, 0, DL_CLDLS, 0, 0);
121 #ifdef DLIOCRAW /* we require RAW DLPI mode, which is a Sun extension */
122 if (strioctl(fd, DLIOCRAW, -1, 0, NULL) == -1)
124 fprintf(stderr, "DLIOCRAW error\n");
133 * output an IP packet onto a fd opened for /dev/nit
135 int sendip(fd, pkt, len)
139 struct strbuf dbuf, *dp = &dbuf, *cp = NULL;
143 dl_hp_rawdata_req_t raw;
146 raw.dl_primitive = DL_HP_RAWDATA_REQ;
147 cp->len = sizeof(raw);
148 cp->buf = (char *)&raw;
149 cp->maxlen = cp->len;
153 * construct NIT STREAMS messages, first control then data.
157 dp->maxlen = dp->len;
159 if (putmsg(fd, cp, dp, pri) == -1)
164 if (ioctl(fd, I_FLUSH, FLUSHW) == -1)