- Test m_pkthdr.fw_flags against DUMMYNET_MBUF_TAGGED before trying to locate
[dragonfly/netmp.git] / contrib / ipfilter / ipsend / sirix.c
blob8f491f7866bfbd677498f0fec167681d97e4490a
1 /*
2 * (C)opyright 1992-1998 Darren Reed.
3 * (C)opyright 1997 Marc Boucher.
5 * See the IPFILTER.LICENCE file for details on licencing.
6 */
7 #if defined(__sgi) && (IRIX > 602)
8 # include <sys/ptimers.h>
9 #endif
10 #include <stdio.h>
11 #include <sys/types.h>
12 #include <string.h>
13 #include <unistd.h>
14 #include <stdlib.h>
15 #include <errno.h>
16 #include <sys/socket.h>
17 #include <sys/ioctl.h>
19 #include <net/if.h>
20 #include <net/raw.h>
21 #include <netinet/in.h>
22 #include <netinet/in_systm.h>
23 #include <netinet/ip.h>
24 #include <netinet/if_ether.h>
25 #include <netinet/ip_var.h>
26 #include <netinet/udp.h>
27 #include <netinet/udp_var.h>
28 #include <netinet/tcp.h>
29 #include "ipsend.h"
31 #if !defined(lint) && defined(LIBC_SCCS)
32 static char sirix[] = "@(#)sirix.c 1.0 10/9/97 (C)1997 Marc Boucher";
33 #endif
36 int initdevice(char *device, int sport, int tout)
38 int fd;
39 struct sockaddr_raw sr;
41 if ((fd = socket(PF_RAW, SOCK_RAW, RAWPROTO_DRAIN)) < 0)
43 perror("socket(PF_RAW, SOCK_RAW, RAWPROTO_DRAIN)");
44 return -1;
47 memset(&sr, 0, sizeof(sr));
48 sr.sr_family = AF_RAW;
49 sr.sr_port = ETHERTYPE_IP;
50 strncpy(sr.sr_ifname, device, sizeof(sr.sr_ifname));
51 if (bind(fd, &sr, sizeof(sr)) < 0)
53 perror("bind AF_RAW");
54 close(fd);
55 return -1;
57 return fd;
62 * output an IP packet
64 int sendip(int fd, char *pkt, int len)
66 struct sockaddr_raw sr;
67 int srlen = sizeof(sr);
68 struct ifreq ifr;
69 struct ether_header *eh = (struct ether_header *)pkt;
71 if (getsockname(fd, &sr, &srlen) == -1)
73 perror("getsockname");
74 return -1;
77 memset(&ifr, 0, sizeof(ifr));
78 strncpy(ifr.ifr_name, sr.sr_ifname, sizeof ifr.ifr_name);
80 if (ioctl(fd, SIOCGIFADDR, &ifr) == -1)
82 perror("ioctl SIOCGIFADDR");
83 return -1;
86 memcpy(eh->ether_shost, ifr.ifr_addr.sa_data, sizeof(eh->ether_shost));
88 if (write(fd, pkt, len) == -1)
90 perror("send");
91 return -1;
94 return len;