1/* $NetBSD: slinux.c,v 1.5 2012/02/15 17:55:05 riz 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) 32static const char sccsid[] = "@(#)slinux.c 1.2 8/25/95"; 33static const char rcsid[] = "@(#)Id: slinux.c,v 2.3 2001/06/09 17:09:26 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 44static int timeout; 45static char *eth_dev = NULL; 46 47 48int initdevice(dev, spare) 49char *dev; 50int 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 */ 68int sendip(fd, pkt, len) 69int fd, len; 70char *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