- Test m_pkthdr.fw_flags against DUMMYNET_MBUF_TAGGED before trying to locate
[dragonfly/netmp.git] / contrib / ipfilter / ipsend / sdlpi.c
blobdcd842211e0325cd52128b12a872c397362afd97
1 /*
2 * (C)opyright 1992-1998 Darren Reed. (from tcplog)
4 * See the IPFILTER.LICENCE file for details on licencing.
5 */
7 #include <stdio.h>
8 #include <netdb.h>
9 #include <ctype.h>
10 #include <fcntl.h>
11 #include <signal.h>
12 #include <errno.h>
13 #include <sys/types.h>
14 #include <sys/time.h>
15 #include <sys/timeb.h>
16 #include <sys/socket.h>
17 #include <sys/file.h>
18 #include <sys/ioctl.h>
19 #include <sys/stropts.h>
21 #ifdef sun
22 #include <sys/pfmod.h>
23 #include <sys/bufmod.h>
24 #endif
25 #include <sys/dlpi.h>
27 #include <net/if.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>
37 #include "ipsend.h"
39 #if !defined(lint)
40 static const char sccsid[] = "@(#)sdlpi.c 1.3 10/30/95 (C)1995 Darren Reed";
41 static const char rcsid[] = "@(#)$Id: sdlpi.c,v 2.1.4.2 2001/06/26 10:43:22 darrenr Exp $";
42 #endif
44 #define CHUNKSIZE 8192
45 #define BUFSPACE (4*CHUNKSIZE)
49 * Be careful to only include those defined in the flags option for the
50 * interface are included in the header size.
52 int initdevice(device, sport, tout)
53 char *device;
54 int sport, tout;
56 char devname[16], *s, buf[256];
57 int i, fd;
59 (void) strcpy(devname, "/dev/");
60 (void) strncat(devname, device, sizeof(devname) - strlen(devname));
62 s = devname + 5;
63 while (*s && !isdigit(*s))
64 s++;
65 if (!*s)
67 fprintf(stderr, "bad device name %s\n", devname);
68 exit(-1);
70 i = atoi(s);
71 *s = '\0';
73 * For writing
75 if ((fd = open(devname, O_RDWR)) < 0)
77 fprintf(stderr, "O_RDWR(1) ");
78 perror(devname);
79 exit(-1);
82 if (dlattachreq(fd, i) == -1 || dlokack(fd, buf) == -1)
84 fprintf(stderr, "DLPI error\n");
85 exit(-1);
87 dlbindreq(fd, ETHERTYPE_IP, 0, DL_CLDLS, 0, 0);
88 dlbindack(fd, buf);
90 * write full headers
92 #ifdef sun /* we require RAW DLPI mode, which is a Sun extension */
93 if (strioctl(fd, DLIOCRAW, -1, 0, NULL) == -1)
95 fprintf(stderr, "DLIOCRAW error\n");
96 exit(-1);
98 #else
99 you lose
100 #endif
101 return fd;
106 * output an IP packet onto a fd opened for /dev/nit
108 int sendip(fd, pkt, len)
109 int fd, len;
110 char *pkt;
112 struct strbuf dbuf, *dp = &dbuf;
115 * construct NIT STREAMS messages, first control then data.
117 dp->buf = pkt;
118 dp->len = len;
119 dp->maxlen = dp->len;
121 if (putmsg(fd, NULL, dp, 0) == -1)
123 perror("putmsg");
124 return -1;
126 if (ioctl(fd, I_FLUSH, FLUSHW) == -1)
128 perror("I_FLUSHW");
129 return -1;
131 return len;