4 * (C)opyright 1992-1998 Darren Reed. (from tcplog)
6 * See the IPFILTER.LICENCE file for details on licencing.
16 #include <sys/types.h>
18 #include <sys/timeb.h>
19 #include <sys/socket.h>
21 #include <sys/ioctl.h>
22 #include <sys/stropts.h>
25 # include <sys/pfmod.h>
26 # include <sys/bufmod.h>
29 # include <sys/dlpihdr.h>
31 # include <sys/dlpi.h>
34 # include <sys/dlpi_ext.h>
38 #include <netinet/in.h>
39 #include <netinet/in_systm.h>
40 #include <netinet/ip.h>
41 #include <netinet/if_ether.h>
42 #include <netinet/ip_var.h>
43 #include <netinet/udp.h>
44 #include <netinet/udp_var.h>
45 #include <netinet/tcp.h>
50 static const char sccsid[] = "@(#)sdlpi.c 1.3 10/30/95 (C)1995 Darren Reed";
51 static const char rcsid[] = "@(#)$Id$";
54 #define CHUNKSIZE 8192
55 #define BUFSPACE (4*CHUNKSIZE)
59 * Be careful to only include those defined in the flags option for the
60 * interface are included in the header size.
62 int initdevice(device, tout)
66 char devname[16], *s, buf[256];
69 (void) strcpy(devname, "/dev/");
70 (void) strncat(devname, device, sizeof(devname) - strlen(devname));
73 while (*s && !ISDIGIT(*s))
77 fprintf(stderr, "bad device name %s\n", devname);
85 if ((fd = open(devname, O_RDWR)) < 0)
87 fprintf(stderr, "O_RDWR(1) ");
92 if (dlattachreq(fd, i) == -1)
94 fprintf(stderr, "dlattachreq: DLPI error\n");
97 else if (dlokack(fd, buf) == -1)
99 fprintf(stderr, "dlokack(attach): DLPI error\n");
103 if (dlpromisconreq(fd, DL_PROMISC_SAP) < 0)
105 fprintf(stderr, "dlpromisconreq: DL_PROMISC_PHYS error\n");
108 else if (dlokack(fd, buf) < 0)
110 fprintf(stderr, "dlokack(promisc): DLPI error\n");
113 /* 22 is INSAP as per the HP-UX DLPI Programmer's Guide */
115 dlbindreq(fd, 22, 1, DL_HP_RAWDLS, 0, 0);
117 dlbindreq(fd, ETHERTYPE_IP, 0, DL_CLDLS, 0, 0);
123 #ifdef DLIOCRAW /* we require RAW DLPI mode, which is a Sun extension */
124 if (strioctl(fd, DLIOCRAW, -1, 0, NULL) == -1)
126 fprintf(stderr, "DLIOCRAW error\n");
135 * output an IP packet onto a fd opened for /dev/nit
137 int sendip(fd, pkt, len)
141 struct strbuf dbuf, *dp = &dbuf, *cp = NULL;
145 dl_hp_rawdata_req_t raw;
148 raw.dl_primitive = DL_HP_RAWDATA_REQ;
149 cp->len = sizeof(raw);
150 cp->buf = (char *)&raw;
151 cp->maxlen = cp->len;
155 * construct NIT STREAMS messages, first control then data.
159 dp->maxlen = dp->len;
161 if (putmsg(fd, cp, dp, pri) == -1)
166 if (ioctl(fd, I_FLUSH, FLUSHW) == -1)