]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/ipfilter/ipsend/ultrix.c
This commit was generated by cvs2svn to compensate for changes in r50760,
[FreeBSD/FreeBSD.git] / contrib / ipfilter / ipsend / ultrix.c
1 /*
2  * (C)opyright 1997 Darren Reed. (from tcplog)
3  *
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.
7  */
8 #include <stdio.h>
9 #include <strings.h>
10 #include <unistd.h>
11 #include <stdlib.h>
12 #include <ctype.h>
13 #include <sys/types.h>
14 #include <sys/param.h>
15 #include <sys/socket.h>
16 #include <sys/file.h>
17 #include <sys/ioctl.h>
18 #include <net/if.h>
19 #include <netinet/in.h>
20 #include <netinet/if_ether.h>
21 #include <netdnet/dli_var.h>
22
23
24 static  struct  dli_devid       dli_devid;
25
26
27 int     initdevice(device, sport, tout)
28 char    *device;
29 int     sport, tout;
30 {
31         u_char  *s;
32         int     fd;
33
34         fd = socket(AF_DLI, SOCK_DGRAM, 0);
35         if (fd == -1)
36                 perror("socket(AF_DLI,SOCK_DGRAM)");
37         else {
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++)
41                         ;
42                 if (*s && isdigit((char)*s)) {
43                         dli_devid.dli_devnumber = atoi(s);
44                 }
45         }
46         return fd;
47 }
48
49
50 /*
51  * output an IP packet onto a fd opened for /dev/bpf
52  */
53 int     sendip(fd, pkt, len)
54 int     fd, len;
55 char    *pkt;
56 {
57         struct sockaddr_dl dl;
58         struct sockaddr_edl *edl = &dl.choose_addr.dli_eaddr;
59
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;
67
68         if (sendto(fd, pkt, len, 0, (struct sockaddr *)&dl, sizeof(dl)) == -1)
69             {
70                 perror("send");
71                 return -1;
72             }
73
74         return len;
75 }
76
77
78 char *strdup(str)
79 char *str;
80 {
81         char    *s;
82
83         if ((s = (char *)malloc(strlen(str) + 1)))
84                 return strcpy(s, str);
85         return NULL;
86 }