4 * Copyright (C) 1993-2001 by Darren Reed.
6 * See the IPFILTER.LICENCE file for details on licencing.
8 * $Id: ipft_ef.c,v 1.14 2004/01/08 13:34:31 darrenr Exp $
13 lnth proto source destination src port dst port
17 60 tcp 128.250.20.20 128.250.133.13 2419 telnet
21 0.32 91 04 131.170.1.10 128.250.133.13
22 0.33 566 udp 128.250.37.155 128.250.133.3 901 901
29 #include <netinet/ip_var.h>
31 #include <netinet/tcpip.h>
35 static const char sccsid[] = "@(#)ipft_ef.c 1.6 2/4/96 (C)1995 Darren Reed";
36 static const char rcsid[] = "@(#)$Id: ipft_ef.c,v 1.14 2004/01/08 13:34:31 darrenr Exp $";
39 static int etherf_open __P((char *));
40 static int etherf_close __P((void));
41 static int etherf_readip __P((char *, int, char **, int *));
43 struct ipread etherf = { etherf_open, etherf_close, etherf_readip, 0 };
45 static FILE *efp = NULL;
49 static int etherf_open(fname)
55 if (!strcmp(fname, "-")) {
59 efd = open(fname, O_RDONLY);
60 efp = fdopen(efd, "r");
66 static int etherf_close()
72 static int etherf_readip(buf, cnt, ifn, dir)
77 ip_t *ip = (ip_t *)&pkt;
78 char src[16], dst[16], sprt[16], dprt[16];
79 char lbuf[128], len[8], prot[8], time[8], *s;
80 int slen, extra = 0, i;
82 if (!fgets(lbuf, sizeof(lbuf) - 1, efp))
85 if ((s = strchr(lbuf, '\n')))
87 lbuf[sizeof(lbuf)-1] = '\0';
89 bzero(&pkt, sizeof(pkt));
91 if (sscanf(lbuf, "%7s %7s %15s %15s %15s %15s", len, prot, src, dst,
93 if (sscanf(lbuf, "%7s %7s %7s %15s %15s %15s %15s", time,
94 len, prot, src, dst, sprt, dprt) != 7)
97 ip->ip_p = getproto(prot);
102 s = strtok(NULL, " :");
103 ip->ip_len += atoi(s);
104 if (ip->ip_p == IPPROTO_TCP)
105 extra = sizeof(struct tcphdr);
106 else if (ip->ip_p == IPPROTO_UDP)
107 extra = sizeof(struct udphdr);
111 extra = sizeof(struct igmp);
115 extra = sizeof(struct icmp);
121 (void) inet_aton(src, &ip->ip_src);
122 (void) inet_aton(dst, &ip->ip_dst);
123 ip->ip_len = atoi(len);
124 IP_HL_A(ip, sizeof(ip_t));
126 slen = IP_HL(ip) + extra;
128 bcopy((char *)&pkt, buf, i);