2 * (C)opyright 1992-1998 Darren Reed. (from tcplog)
4 * See the IPFILTER.LICENCE file for details on licencing.
12 #include <sys/types.h>
14 #include <sys/timeb.h>
15 #include <sys/socket.h>
17 #include <sys/ioctl.h>
19 #include <sys/fcntlcom.h>
21 #include <net/nit_if.h>
22 #include <net/nit_pf.h>
23 #include <net/nit_buf.h>
24 #include <net/packetfilt.h>
25 #include <sys/stropts.h>
28 #include <netinet/in.h>
29 #include <netinet/in_systm.h>
30 #include <netinet/ip.h>
31 #include <netinet/if_ether.h>
32 #include <netinet/ip_var.h>
33 #include <netinet/udp.h>
34 #include <netinet/udp_var.h>
35 #include <netinet/tcp.h>
40 static const char sccsid
[] = "@(#)snit.c 1.5 1/11/96 (C)1995 Darren Reed";
41 static const char rcsid
[] = "@(#)$Id: snit.c,v 2.1.4.1 2001/06/26 10:43:22 darrenr Exp $";
44 #define CHUNKSIZE 8192
45 #define BUFSPACE (4*CHUNKSIZE)
48 * Be careful to only include those defined in the flags option for the
49 * interface are included in the header size.
51 #define BUFHDR_SIZE (sizeof(struct nit_bufhdr))
52 #define NIT_HDRSIZE (BUFHDR_SIZE)
57 int initdevice(device
, sport
, tout
)
66 if ((fd
= open("/dev/nit", O_RDWR
)) < 0)
73 * arrange to get messages from the NIT STREAM and use NIT_BUF option
75 ioctl(fd
, I_SRDOPT
, (char*)RMSGD
);
76 ioctl(fd
, I_PUSH
, "nbuf");
85 si
.ic_cmd
= NIOCSTIME
;
86 si
.ic_len
= sizeof(to
);
87 si
.ic_dp
= (char*)&to
;
88 if (ioctl(fd
, I_STR
, (char*)&si
) == -1)
90 perror("ioctl: NIT timeout");
95 * request the interface
97 strncpy(ifr
.ifr_name
, device
, sizeof(ifr
.ifr_name
));
98 ifr
.ifr_name
[sizeof(ifr
.ifr_name
) - 1] = ' ';
100 si
.ic_len
= sizeof(ifr
);
101 si
.ic_dp
= (char*)&ifr
;
102 if (ioctl(fd
, I_STR
, (char*)&si
) == -1)
104 perror(ifr
.ifr_name
);
112 * output an IP packet onto a fd opened for /dev/nit
114 int sendip(fd
, pkt
, len
)
118 struct sockaddr sk
, *sa
= &sk
;
119 struct strbuf cbuf
, *cp
= &cbuf
, dbuf
, *dp
= &dbuf
;
122 * For ethernet, need at least 802.3 header and IP header.
124 if (len
< (sizeof(sa
->sa_data
) + sizeof(struct ip
)))
127 * to avoid any output processing for IP, say we're not.
129 sa
->sa_family
= AF_UNSPEC
;
130 bcopy(pkt
, sa
->sa_data
, sizeof(sa
->sa_data
));
131 pkt
+= sizeof(sa
->sa_data
);
132 len
-= sizeof(sa
->sa_data
);
135 * construct NIT STREAMS messages, first control then data.
137 cp
->len
= sizeof(*sa
);
138 cp
->maxlen
= sizeof(*sa
);
139 cp
->buf
= (char *)sa
;
143 dp
->maxlen
= dp
->len
;
145 if (putmsg(fd
, cp
, dp
, 0) == -1)
151 if (ioctl(fd
, I_FLUSH
, FLUSHW
) == -1)