1 /* $NetBSD: slinux.c,v 1.2 2012/07/22 14:27:36 darrenr Exp $ */
2
3 /*
4 * (C)opyright 1992-1998 Darren Reed. (from tcplog)
5 *
6 * See the IPFILTER.LICENCE file for details on licencing.
7 *
8 */
9
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"
30
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 1.1.1.2 2012/07/22 13:44:37 darrenr Exp $";
34 #endif
35
36 #define CHUNKSIZE 8192
37 #define BUFSPACE (4*CHUNKSIZE)
38
39 /*
40 * Be careful to only include those defined in the flags option for the
41 * interface are included in the header size.
42 */
43
44 static int timeout;
45 static char *eth_dev = NULL;
46
47
initdevice(dev,spare)48 int initdevice(dev, spare)
49 char *dev;
50 int spare;
51 {
52 int fd;
53
54 eth_dev = strdup(dev);
55 if ((fd = socket(AF_INET, SOCK_PACKET, htons(ETHERTYPE_IP))) == -1)
56 {
57 perror("socket(SOCK_PACKET)");
58 exit(-1);
59 }
60
61 return fd;
62 }
63
64
65 /*
66 * output an IP packet onto a fd opened for /dev/nit
67 */
sendip(fd,pkt,len)68 int sendip(fd, pkt, len)
69 int fd, len;
70 char *pkt;
71 {
72 struct sockaddr s;
73 struct ifreq ifr;
74
75 strncpy(ifr.ifr_name, eth_dev, sizeof(ifr.ifr_name));
76 if (ioctl(fd, SIOCGIFHWADDR, &ifr) == -1)
77 {
78 perror("SIOCGIFHWADDR");
79 return -1;
80 }
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));
84
85 if (sendto(fd, pkt, len, 0, &s, sizeof(s)) == -1)
86 {
87 perror("send");
88 return -1;
89 }
90
91 return len;
92 }
93