2 * (C)opyright 1997 Darren Reed. (from tcplog)
4 * Redistribution and use in source and binary forms are permitted
5 * provided that this notice is preserved and due credit is given
6 * to the original author and the contributors.
13 #include <sys/types.h>
14 #include <sys/param.h>
15 #include <sys/socket.h>
17 #include <sys/ioctl.h>
19 #include <netinet/in.h>
20 #include <netinet/if_ether.h>
21 #include <netdnet/dli_var.h>
24 static struct dli_devid dli_devid;
27 int initdevice(device, sport, tout)
34 fd = socket(AF_DLI, SOCK_DGRAM, 0);
36 perror("socket(AF_DLI,SOCK_DGRAM)");
38 strncpy(dli_devid.dli_devname, device, DLI_DEVSIZE);
39 dli_devid.dli_devname[DLI_DEVSIZE] ='\0';
40 for (s = dli_devid.dli_devname; *s && isalpha((char)*s); s++)
42 if (*s && isdigit((char)*s)) {
43 dli_devid.dli_devnumber = atoi(s);
51 * output an IP packet onto a fd opened for /dev/bpf
53 int sendip(fd, pkt, len)
57 struct sockaddr_dl dl;
58 struct sockaddr_edl *edl = &dl.choose_addr.dli_eaddr;
60 dl.dli_family = AF_DLI;
61 dl.dli_substructype = DLI_ETHERNET;
62 bcopy((char *)&dli_devid, (char *)&dl.dli_device, sizeof(dli_devid));
63 bcopy(pkt, edl->dli_target, DLI_EADDRSIZE);
64 bcopy(pkt, edl->dli_dest, DLI_EADDRSIZE);
65 bcopy(pkt + DLI_EADDRSIZE * 2, (char *)&edl->dli_protype, 2);
66 edl->dli_ioctlflg = 0;
68 if (sendto(fd, pkt, len, 0, (struct sockaddr *)&dl, sizeof(dl)) == -1)
83 if ((s = (char *)malloc(strlen(str) + 1)))
84 return strcpy(s, str);