4 * Copyright (C) 2000-2006 by Darren Reed.
6 * See the IPFILTER.LICENCE file for details on licencing.
8 * Id: ipft_ef.c,v 1.14.2.2 2006/06/16 17:21:02 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.2.2 2006/06/16 17:21:02 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 pkt
.ti_sport
= htons(atoi(sprt
) & 65535);
104 pkt
.ti_dport
= htons(atoi(dprt
) & 65535);
105 extra
= sizeof(struct tcphdr
);
109 pkt
.ti_sport
= htons(atoi(sprt
) & 65535);
111 pkt
.ti_dport
= htons(atoi(dprt
) & 65535);
112 extra
= sizeof(struct udphdr
);
116 extra
= sizeof(struct igmp
);
120 extra
= sizeof(struct icmp
);
126 (void) inet_aton(src
, &ip
->ip_src
);
127 (void) inet_aton(dst
, &ip
->ip_dst
);
128 ip
->ip_len
= atoi(len
);
129 IP_HL_A(ip
, sizeof(ip_t
));
131 slen
= IP_HL(ip
) + extra
;
133 bcopy((char *)&pkt
, buf
, i
);