Expand PMF_FN_* macros.
[netbsd-mini2440.git] / dist / ipf / ipsend / sdlpi.c
bloba34c6bfeb490d2bc8ac655fd7c8002af8e42123f
1 /* $NetBSD$ */
3 /*
4 * (C)opyright 1992-1998 Darren Reed. (from tcplog)
6 * See the IPFILTER.LICENCE file for details on licencing.
8 */
10 #include <stdio.h>
11 #include <netdb.h>
12 #include <ctype.h>
13 #include <fcntl.h>
14 #include <signal.h>
15 #include <errno.h>
16 #include <sys/types.h>
17 #include <sys/time.h>
18 #include <sys/timeb.h>
19 #include <sys/socket.h>
20 #include <sys/file.h>
21 #include <sys/ioctl.h>
22 #include <sys/stropts.h>
24 #ifdef sun
25 # include <sys/pfmod.h>
26 # include <sys/bufmod.h>
27 #endif
28 #ifdef __osf__
29 # include <sys/dlpihdr.h>
30 # include "radix_ipf_local.h"
31 #else
32 # include <sys/dlpi.h>
33 #endif
34 #ifdef __hpux
35 # include <sys/dlpi_ext.h>
36 #endif
38 #include <net/if.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>
48 #include "ipsend.h"
50 #if !defined(lint)
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";
53 #endif
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)
64 char *device;
65 int tout;
67 char devname[16], *s, buf[256];
68 int i, fd;
70 (void) strcpy(devname, "/dev/");
71 (void) strncat(devname, device, sizeof(devname) - strlen(devname));
73 s = devname + 5;
74 while (*s && !ISDIGIT(*s))
75 s++;
76 if (!*s)
78 fprintf(stderr, "bad device name %s\n", devname);
79 exit(-1);
81 i = atoi(s);
82 *s = '\0';
84 * For writing
86 if ((fd = open(devname, O_RDWR)) < 0)
88 fprintf(stderr, "O_RDWR(1) ");
89 perror(devname);
90 exit(-1);
93 if (dlattachreq(fd, i) == -1)
95 fprintf(stderr, "dlattachreq: DLPI error\n");
96 exit(-1);
98 else if (dlokack(fd, buf) == -1)
100 fprintf(stderr, "dlokack(attach): DLPI error\n");
101 exit(-1);
103 #ifdef DL_HP_RAWDLS
104 if (dlpromisconreq(fd, DL_PROMISC_SAP) < 0)
106 fprintf(stderr, "dlpromisconreq: DL_PROMISC_PHYS error\n");
107 exit(-1);
109 else if (dlokack(fd, buf) < 0)
111 fprintf(stderr, "dlokack(promisc): DLPI error\n");
112 exit(-1);
114 /* 22 is INSAP as per the HP-UX DLPI Programmer's Guide */
116 dlbindreq(fd, 22, 1, DL_HP_RAWDLS, 0, 0);
117 #else
118 dlbindreq(fd, ETHERTYPE_IP, 0, DL_CLDLS, 0, 0);
119 #endif
120 dlbindack(fd, buf);
122 * write full headers
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");
128 exit(-1);
130 #endif
131 return fd;
136 * output an IP packet onto a fd opened for /dev/nit
138 int sendip(fd, pkt, len)
139 int fd, len;
140 char *pkt;
142 struct strbuf dbuf, *dp = &dbuf, *cp = NULL;
143 int pri = 0;
144 #ifdef DL_HP_RAWDLS
145 struct strbuf cbuf;
146 dl_hp_rawdata_req_t raw;
148 cp = &cbuf;
149 raw.dl_primitive = DL_HP_RAWDATA_REQ;
150 cp->len = sizeof(raw);
151 cp->buf = (char *)&raw;
152 cp->maxlen = cp->len;
153 pri = MSG_HIPRI;
154 #endif
156 * construct NIT STREAMS messages, first control then data.
158 dp->buf = pkt;
159 dp->len = len;
160 dp->maxlen = dp->len;
162 if (putmsg(fd, cp, dp, pri) == -1)
164 perror("putmsg");
165 return -1;
167 if (ioctl(fd, I_FLUSH, FLUSHW) == -1)
169 perror("I_FLUSHW");
170 return -1;
172 return len;