- Test m_pkthdr.fw_flags against DUMMYNET_MBUF_TAGGED before trying to locate
[dragonfly/netmp.git] / contrib / ipfilter / ipsend / slinux.c
blob7438d1c25cf9f40cba15e1792c9cc1c690384eb2
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 <string.h>
9 #include <netdb.h>
10 #include <ctype.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/dir.h>
20 #include <linux/netdevice.h>
21 #include <net/if.h>
22 #include <netinet/in.h>
23 #include <netinet/in_systm.h>
24 #include <netinet/ip.h>
25 #include <netinet/tcp.h>
26 #include "ipsend.h"
28 #if !defined(lint)
29 static const char sccsid[] = "@(#)slinux.c 1.2 8/25/95";
30 static const char rcsid[] = "@(#)$Id: slinux.c,v 2.1.4.1 2001/06/26 10:43:22 darrenr Exp $";
31 #endif
33 #define CHUNKSIZE 8192
34 #define BUFSPACE (4*CHUNKSIZE)
37 * Be careful to only include those defined in the flags option for the
38 * interface are included in the header size.
41 static int timeout;
42 static char *eth_dev = NULL;
45 int initdevice(dev, sport, spare)
46 char *dev;
47 int sport, spare;
49 int fd;
51 eth_dev = strdup(dev);
52 if ((fd = socket(AF_INET, SOCK_PACKET, htons(ETHERTYPE_IP))) == -1)
54 perror("socket(SOCK_PACKET)");
55 exit(-1);
58 return fd;
63 * output an IP packet onto a fd opened for /dev/nit
65 int sendip(fd, pkt, len)
66 int fd, len;
67 char *pkt;
69 struct sockaddr s;
70 struct ifreq ifr;
72 strncpy(ifr.ifr_name, eth_dev, sizeof(ifr.ifr_name));
73 if (ioctl(fd, SIOCGIFHWADDR, &ifr) == -1)
75 perror("SIOCGIFHWADDR");
76 return -1;
78 bcopy(ifr.ifr_hwaddr.sa_data, pkt + 6, 6);
79 s.sa_family = ETHERTYPE_IP;
80 strncpy(s.sa_data, eth_dev, sizeof(s.sa_data));
82 if (sendto(fd, pkt, len, 0, &s, sizeof(s)) == -1)
84 perror("send");
85 return -1;
88 return len;