slinux.c revision 22514
1220231Snp/* 2220231Snp * (C)opyright October 1992 Darren Reed. (from tcplog) 3220231Snp * 4220231Snp * This software may be freely distributed as long as it is not altered 5220231Snp * in any way and that this messagge always accompanies it. 6228561Snp * 7237263Snp * The author of this software makes no garuntee about the 8220231Snp * performance of this package or its suitability to fulfill any purpose. 9237263Snp * 10237263Snp */ 11237263Snp 12237263Snp#include <stdio.h> 13220231Snp#include <string.h> 14#include <netdb.h> 15#include <ctype.h> 16#include <signal.h> 17#include <errno.h> 18#include <sys/types.h> 19#include <sys/time.h> 20#include <sys/timeb.h> 21#include <sys/socket.h> 22#include <sys/file.h> 23#include <sys/ioctl.h> 24#include <sys/dir.h> 25#include <linux/netdevice.h> 26#include <net/if.h> 27#include <netinet/in.h> 28#include <netinet/in_systm.h> 29#include <netinet/ip.h> 30#include <netinet/tcp.h> 31#include "ip_compat.h" 32#include "tcpip.h" 33 34#if !defined(lint) && defined(LIBC_SCCS) 35static char sccsid[] = "@(#)slinux.c 1.2 8/25/95"; 36#endif 37 38#define CHUNKSIZE 8192 39#define BUFSPACE (4*CHUNKSIZE) 40 41/* 42 * Be careful to only include those defined in the flags option for the 43 * interface are included in the header size. 44 */ 45 46static int timeout; 47static char *eth_dev = NULL; 48 49 50int initdevice(dev, sport, tout) 51char *dev; 52int sport, tout; 53{ 54 int fd; 55 56 eth_dev = strdup(dev); 57 if ((fd = socket(AF_INET, SOCK_PACKET, htons(ETHERTYPE_IP))) == -1) 58 { 59 perror("socket(SOCK_PACKET)"); 60 exit(-1); 61 } 62 63 return fd; 64} 65 66 67/* 68 * output an IP packet onto a fd opened for /dev/nit 69 */ 70int sendip(fd, pkt, len) 71int fd, len; 72char *pkt; 73{ 74 struct sockaddr s; 75 struct ifreq ifr; 76 77 strncpy(ifr.ifr_name, eth_dev, sizeof(ifr.ifr_name)); 78 if (ioctl(fd, SIOCGIFHWADDR, &ifr) == -1) 79 { 80 perror("SIOCGIFHWADDR"); 81 return -1; 82 } 83 bcopy(ifr.ifr_hwaddr.sa_data, pkt + 6, 6); 84 s.sa_family = ETHERTYPE_IP; 85 strncpy(s.sa_data, eth_dev, sizeof(s.sa_data)); 86 87 if (sendto(fd, pkt, len, 0, &s, sizeof(s)) == -1) 88 { 89 perror("send"); 90 return -1; 91 } 92 93 return len; 94} 95