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>
30 # include "radix_ipf_local.h"
32 # include <sys/dlpi.h>
35 # include <sys/dlpi_ext.h>
39 #include <netinet/in.h>
40 #include <netinet/in_systm.h>
41 #include <netinet/ip.h>
42 #include <netinet/if_ether.h>
43 #include <netinet/ip_var.h>
44 #include <netinet/udp.h>
45 #include <netinet/udp_var.h>
46 #include <netinet/tcp.h>
51 static const char sccsid
[] = "@(#)sdlpi.c 1.3 10/30/95 (C)1995 Darren Reed";
52 static const char rcsid
[] = "@(#)Id: sdlpi.c,v 2.8.2.2 2007/02/17 12:41:51 darrenr Exp";
55 #define CHUNKSIZE 8192
56 #define BUFSPACE (4*CHUNKSIZE)
60 * Be careful to only include those defined in the flags option for the
61 * interface are included in the header size.
63 int initdevice(device
, tout
)
67 char devname
[16], *s
, buf
[256];
70 (void) strcpy(devname
, "/dev/");
71 (void) strncat(devname
, device
, sizeof(devname
) - strlen(devname
));
74 while (*s
&& !ISDIGIT(*s
))
78 fprintf(stderr
, "bad device name %s\n", devname
);
86 if ((fd
= open(devname
, O_RDWR
)) < 0)
88 fprintf(stderr
, "O_RDWR(1) ");
93 if (dlattachreq(fd
, i
) == -1)
95 fprintf(stderr
, "dlattachreq: DLPI error\n");
98 else if (dlokack(fd
, buf
) == -1)
100 fprintf(stderr
, "dlokack(attach): DLPI error\n");
104 if (dlpromisconreq(fd
, DL_PROMISC_SAP
) < 0)
106 fprintf(stderr
, "dlpromisconreq: DL_PROMISC_PHYS error\n");
109 else if (dlokack(fd
, buf
) < 0)
111 fprintf(stderr
, "dlokack(promisc): DLPI error\n");
114 /* 22 is INSAP as per the HP-UX DLPI Programmer's Guide */
116 dlbindreq(fd
, 22, 1, DL_HP_RAWDLS
, 0, 0);
118 dlbindreq(fd
, ETHERTYPE_IP
, 0, DL_CLDLS
, 0, 0);
124 #ifdef DLIOCRAW /* we require RAW DLPI mode, which is a Sun extension */
125 if (strioctl(fd
, DLIOCRAW
, -1, 0, NULL
) == -1)
127 fprintf(stderr
, "DLIOCRAW error\n");
136 * output an IP packet onto a fd opened for /dev/nit
138 int sendip(fd
, pkt
, len
)
142 struct strbuf dbuf
, *dp
= &dbuf
, *cp
= NULL
;
146 dl_hp_rawdata_req_t raw
;
149 raw
.dl_primitive
= DL_HP_RAWDATA_REQ
;
150 cp
->len
= sizeof(raw
);
151 cp
->buf
= (char *)&raw
;
152 cp
->maxlen
= cp
->len
;
156 * construct NIT STREAMS messages, first control then data.
160 dp
->maxlen
= dp
->len
;
162 if (putmsg(fd
, cp
, dp
, pri
) == -1)
167 if (ioctl(fd
, I_FLUSH
, FLUSHW
) == -1)