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