2 * (C)opyright 1998 Darren Reed. (from tcplog)
4 * See the IPFILTER.LICENCE file for details on licencing.
11 #include <sys/types.h>
12 #include <sys/param.h>
13 #include <sys/socket.h>
15 #include <sys/ioctl.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)
32 fd = socket(AF_DLI, SOCK_DGRAM, 0);
34 perror("socket(AF_DLI,SOCK_DGRAM)");
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);
49 * output an IP packet onto a fd opened for /dev/bpf
51 int sendip(fd, pkt, len)
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)
81 if ((s = (char *)malloc(strlen(str) + 1)))
82 return strcpy(s, str);