summaryrefslogtreecommitdiffstats
path: root/contrib/ipfilter/ipsend/slinux.c
blob: 1021acf6d3c0be752b7b32892f6c4df65f580823 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
/*	$FreeBSD$	*/

/*
 * (C)opyright 1992-1998 Darren Reed. (from tcplog)
 *
 * See the IPFILTER.LICENCE file for details on licencing.
 *
 */

#include <stdio.h>
#include <string.h>
#include <netdb.h>
#include <ctype.h>
#include <signal.h>
#include <errno.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/timeb.h>
#include <sys/socket.h>
#include <sys/file.h>
#include <sys/ioctl.h>
#include <sys/dir.h>
#include <linux/netdevice.h>
#include <net/if.h>
#include <netinet/in.h>
#include <netinet/in_systm.h>
#include <netinet/ip.h>
#include <netinet/tcp.h>
#include "ipsend.h"

#if !defined(lint)
static const char sccsid[] = "@(#)slinux.c	1.2 8/25/95";
static const char rcsid[] = "@(#)Id: slinux.c,v 2.3 2001/06/09 17:09:26 darrenr Exp";
#endif

#define	CHUNKSIZE	8192
#define BUFSPACE	(4*CHUNKSIZE)

/*
 * Be careful to only include those defined in the flags option for the
 * interface are included in the header size.
 */

static	int	timeout;
static	char	*eth_dev = NULL;


int	initdevice(dev, spare)
char	*dev;
int	spare;
{
	int fd;

	eth_dev = strdup(dev);
	if ((fd = socket(AF_INET, SOCK_PACKET, htons(ETHERTYPE_IP))) == -1)
	    {
		perror("socket(SOCK_PACKET)");
		exit(-1);
	    }

	return fd;
}


/*
 * output an IP packet onto a fd opened for /dev/nit
 */
int	sendip(fd, pkt, len)
int	fd, len;
char	*pkt;
{
	struct	sockaddr	s;
	struct	ifreq	ifr;

	strncpy(ifr.ifr_name, eth_dev, sizeof(ifr.ifr_name));
	if (ioctl(fd, SIOCGIFHWADDR, &ifr) == -1)
	    {
		perror("SIOCGIFHWADDR");
		return -1;
	    }
	bcopy(ifr.ifr_hwaddr.sa_data, pkt + 6, 6);
	s.sa_family = ETHERTYPE_IP;
	strncpy(s.sa_data, eth_dev, sizeof(s.sa_data));

	if (sendto(fd, pkt, len, 0, &s, sizeof(s)) == -1)
	    {
		perror("send");
		return -1;
	    }

	return len;
}
OpenPOWER on IntegriCloud