Expand PMF_FN_* macros.
[netbsd-mini2440.git] / dist / ipf / ipsend / slinux.c
blob3bc7f09c4db7f047e2a4de4b5b94305e735c51ef
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 <string.h>
12 #include <netdb.h>
13 #include <ctype.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/dir.h>
23 #include <linux/netdevice.h>
24 #include <net/if.h>
25 #include <netinet/in.h>
26 #include <netinet/in_systm.h>
27 #include <netinet/ip.h>
28 #include <netinet/tcp.h>
29 #include "ipsend.h"
31 #if !defined(lint)
32 static const char sccsid[] = "@(#)slinux.c 1.2 8/25/95";
33 static const char rcsid[] = "@(#)Id: slinux.c,v 2.3 2001/06/09 17:09:26 darrenr Exp";
34 #endif
36 #define CHUNKSIZE 8192
37 #define BUFSPACE (4*CHUNKSIZE)
40 * Be careful to only include those defined in the flags option for the
41 * interface are included in the header size.
44 static int timeout;
45 static char *eth_dev = NULL;
48 int initdevice(dev, spare)
49 char *dev;
50 int spare;
52 int fd;
54 eth_dev = strdup(dev);
55 if ((fd = socket(AF_INET, SOCK_PACKET, htons(ETHERTYPE_IP))) == -1)
57 perror("socket(SOCK_PACKET)");
58 exit(-1);
61 return fd;
66 * output an IP packet onto a fd opened for /dev/nit
68 int sendip(fd, pkt, len)
69 int fd, len;
70 char *pkt;
72 struct sockaddr s;
73 struct ifreq ifr;
75 strncpy(ifr.ifr_name, eth_dev, sizeof(ifr.ifr_name));
76 if (ioctl(fd, SIOCGIFHWADDR, &ifr) == -1)
78 perror("SIOCGIFHWADDR");
79 return -1;
81 bcopy(ifr.ifr_hwaddr.sa_data, pkt + 6, 6);
82 s.sa_family = ETHERTYPE_IP;
83 strncpy(s.sa_data, eth_dev, sizeof(s.sa_data));
85 if (sendto(fd, pkt, len, 0, &s, sizeof(s)) == -1)
87 perror("send");
88 return -1;
91 return len;