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 $
11 lnth proto source destination src port dst port
15 60 tcp 128.250.20.20 128.250.133.13 2419 telnet
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
27 #include <netinet/ip_var.h>
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
;
45 static int etherf_open(fname
)
51 if (!strcmp(fname
, "-")) {
55 efd
= open(fname
, O_RDONLY
);
56 efp
= fdopen(efd
, "r");
62 static int etherf_close()
68 static int etherf_readip(buf
, cnt
, ifn
, dir
)
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
))
81 if ((s
= strchr(lbuf
, '\n')))
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
,
89 if (sscanf(lbuf
, "%7s %7s %7s %15s %15s %15s %15s", time
,
90 len
, prot
, src
, dst
, sprt
, dprt
) != 7)
93 ip
->ip_p
= getproto(prot
);
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
);
107 extra
= sizeof(struct igmp
);
111 extra
= sizeof(struct icmp
);
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
;
124 bcopy((char *)&pkt
, buf
, i
);