- Test m_pkthdr.fw_flags against DUMMYNET_MBUF_TAGGED before trying to locate
[dragonfly/netmp.git] / contrib / ipfilter / ipsend / ultrix.c
blobf41a8a9a7481a950641984114709dfb72811d8cc
1 /*
2 * (C)opyright 1998 Darren Reed. (from tcplog)
4 * See the IPFILTER.LICENCE file for details on licencing.
5 */
6 #include <stdio.h>
7 #include <strings.h>
8 #include <unistd.h>
9 #include <stdlib.h>
10 #include <ctype.h>
11 #include <sys/types.h>
12 #include <sys/param.h>
13 #include <sys/socket.h>
14 #include <sys/file.h>
15 #include <sys/ioctl.h>
16 #include <net/if.h>
17 #include <netinet/in.h>
18 #include <netinet/if_ether.h>
19 #include <netdnet/dli_var.h>
22 static struct dli_devid dli_devid;
25 int initdevice(device, sport, tout)
26 char *device;
27 int sport, tout;
29 u_char *s;
30 int fd;
32 fd = socket(AF_DLI, SOCK_DGRAM, 0);
33 if (fd == -1)
34 perror("socket(AF_DLI,SOCK_DGRAM)");
35 else {
36 strncpy(dli_devid.dli_devname, device, DLI_DEVSIZE);
37 dli_devid.dli_devname[DLI_DEVSIZE] ='\0';
38 for (s = dli_devid.dli_devname; *s && isalpha((char)*s); s++)
40 if (*s && isdigit((char)*s)) {
41 dli_devid.dli_devnumber = atoi(s);
44 return fd;
49 * output an IP packet onto a fd opened for /dev/bpf
51 int sendip(fd, pkt, len)
52 int fd, len;
53 char *pkt;
55 struct sockaddr_dl dl;
56 struct sockaddr_edl *edl = &dl.choose_addr.dli_eaddr;
58 dl.dli_family = AF_DLI;
59 dl.dli_substructype = DLI_ETHERNET;
60 bcopy((char *)&dli_devid, (char *)&dl.dli_device, sizeof(dli_devid));
61 bcopy(pkt, edl->dli_target, DLI_EADDRSIZE);
62 bcopy(pkt, edl->dli_dest, DLI_EADDRSIZE);
63 bcopy(pkt + DLI_EADDRSIZE * 2, (char *)&edl->dli_protype, 2);
64 edl->dli_ioctlflg = 0;
66 if (sendto(fd, pkt, len, 0, (struct sockaddr *)&dl, sizeof(dl)) == -1)
68 perror("send");
69 return -1;
72 return len;
76 char *strdup(str)
77 char *str;
79 char *s;
81 if ((s = (char *)malloc(strlen(str) + 1)))
82 return strcpy(s, str);
83 return NULL;