Move /var/svc/log to /var/log/svc
[unleashed/lotheac.git] / usr / src / cmd / ipf / lib / common / ipft_ef.c
blob973ef437d86dd2bd030fe752b38b8cb20132d80a
1 /*
2 * Copyright (C) 1993-2001 by Darren Reed.
4 * See the IPFILTER.LICENCE file for details on licencing.
6 * $Id: ipft_ef.c,v 1.14 2004/01/08 13:34:31 darrenr Exp $
7 */
9 /*
10 icmp type
11 lnth proto source destination src port dst port
13 etherfind -n
15 60 tcp 128.250.20.20 128.250.133.13 2419 telnet
17 etherfind -n -t
19 0.32 91 04 131.170.1.10 128.250.133.13
20 0.33 566 udp 128.250.37.155 128.250.133.3 901 901
23 #include "ipf.h"
24 #include "ipt.h"
26 #ifndef linux
27 #include <netinet/ip_var.h>
28 #endif
29 #include <netinet/tcpip.h>
32 static const char sccsid[] = "@(#)ipft_ef.c 1.6 2/4/96 (C)1995 Darren Reed";
33 static const char rcsid[] = "@(#)$Id: ipft_ef.c,v 1.14 2004/01/08 13:34:31 darrenr Exp $";
35 static int etherf_open __P((char *));
36 static int etherf_close __P((void));
37 static int etherf_readip __P((char *, int, char **, int *));
39 struct ipread etherf = { etherf_open, etherf_close, etherf_readip, 0 };
41 static FILE *efp = NULL;
42 static int efd = -1;
45 static int etherf_open(fname)
46 char *fname;
48 if (efd != -1)
49 return efd;
51 if (!strcmp(fname, "-")) {
52 efd = 0;
53 efp = stdin;
54 } else {
55 efd = open(fname, O_RDONLY);
56 efp = fdopen(efd, "r");
58 return efd;
62 static int etherf_close()
64 return close(efd);
68 static int etherf_readip(buf, cnt, ifn, dir)
69 char *buf, **ifn;
70 int cnt, *dir;
72 struct tcpiphdr pkt;
73 ip_t *ip = (ip_t *)&pkt;
74 char src[16], dst[16], sprt[16], dprt[16];
75 char lbuf[128], len[8], prot[8], time[8], *s;
76 int slen, extra = 0, i;
78 if (!fgets(lbuf, sizeof(lbuf) - 1, efp))
79 return 0;
81 if ((s = strchr(lbuf, '\n')))
82 *s = '\0';
83 lbuf[sizeof(lbuf)-1] = '\0';
85 bzero(&pkt, sizeof(pkt));
87 if (sscanf(lbuf, "%7s %7s %15s %15s %15s %15s", len, prot, src, dst,
88 sprt, dprt) != 6)
89 if (sscanf(lbuf, "%7s %7s %7s %15s %15s %15s %15s", time,
90 len, prot, src, dst, sprt, dprt) != 7)
91 return -1;
93 ip->ip_p = getproto(prot);
95 switch (ip->ip_p) {
96 case IPPROTO_TCP :
97 case IPPROTO_UDP :
98 s = strtok(NULL, " :");
99 ip->ip_len += atoi(s);
100 if (ip->ip_p == IPPROTO_TCP)
101 extra = sizeof(struct tcphdr);
102 else if (ip->ip_p == IPPROTO_UDP)
103 extra = sizeof(struct udphdr);
104 break;
105 #ifdef IGMP
106 case IPPROTO_IGMP :
107 extra = sizeof(struct igmp);
108 break;
109 #endif
110 case IPPROTO_ICMP :
111 extra = sizeof(struct icmp);
112 break;
113 default :
114 break;
117 (void) inet_aton(src, &ip->ip_src);
118 (void) inet_aton(dst, &ip->ip_dst);
119 ip->ip_len = atoi(len);
120 IP_HL_A(ip, sizeof(ip_t));
122 slen = IP_HL(ip) + extra;
123 i = MIN(cnt, slen);
124 bcopy((char *)&pkt, buf, i);
125 return i;