2 * Copyright (C) 1993-2001 by Darren Reed.
4 * See the IPFILTER.LICENCE file for details on licencing.
6 * $Id: ipft_td.c,v 1.15 2004/01/08 13:34:31 darrenr Exp $
12 00:05:47.816843 128.231.76.76.3291 > 224.2.252.231.36573: udp 36 (encap)
16 00:33:48.410771 192.73.213.11.1463 > 224.2.248.153.59360: udp 31 (encap)
20 128.250.133.13.23 > 128.250.20.20.2419: tcp 27
24 123456789.1234567 128.250.133.13.23 > 128.250.20.20.2419: tcp 27
28 8:0:20:f:65:f7 0:0:c:1:8a:c5 81: 128.250.133.13.23 > 128.250.20.20.2419: tcp 27
36 #include <netinet/ip_var.h>
38 #include <netinet/tcpip.h>
41 static const char sccsid
[] = "@(#)ipft_td.c 1.8 2/4/96 (C)1995 Darren Reed";
42 static const char rcsid
[] = "@(#)$Id: ipft_td.c,v 1.15 2004/01/08 13:34:31 darrenr Exp $";
44 static int tcpd_open
__P((char *));
45 static int tcpd_close
__P((void));
46 static int tcpd_readip
__P((char *, int, char **, int *));
47 static int count_dots
__P((char *));
49 struct ipread tcpd
= { tcpd_open
, tcpd_close
, tcpd_readip
, 0 };
51 static FILE *tfp
= NULL
;
55 static int tcpd_open(fname
)
61 if (!strcmp(fname
, "-")) {
65 tfd
= open(fname
, O_RDONLY
);
66 tfp
= fdopen(tfd
, "r");
72 static int tcpd_close()
79 static int count_dots(str
)
91 static int tcpd_readip(buf
, cnt
, ifn
, dir
)
96 ip_t
*ip
= (ip_t
*)&pkt
;
97 char src
[32], dst
[32], misc
[256], time
[32], link1
[32], link2
[32];
99 int n
, slen
, extra
= 0;
101 if (!fgets(lbuf
, sizeof(lbuf
) - 1, tfp
))
104 if ((s
= strchr(lbuf
, '\n')))
106 lbuf
[sizeof(lbuf
)-1] = '\0';
108 bzero(&pkt
, sizeof(pkt
));
110 if ((n
= sscanf(lbuf
, "%31s > %31s: %255s", src
, dst
, misc
)) != 3)
111 if ((n
= sscanf(lbuf
, "%31s %31s > %31s: %255s",
112 time
, src
, dst
, misc
)) != 4)
113 if ((n
= sscanf(lbuf
, "%31s %31s: %31s > %31s: %255s",
114 link1
, link2
, src
, dst
, misc
)) != 5) {
116 "%31s %31s %31s: %31s > %31s: %255s",
117 time
, link1
, link2
, src
, dst
, misc
);
122 if (count_dots(dst
) == 4) {
123 s
= strrchr(src
, '.');
125 (void) inet_aton(src
, &ip
->ip_src
);
126 pkt
.ti_sport
= htons(atoi(s
));
128 s
= strrchr(dst
, '.');
131 (void) inet_aton(src
, &ip
->ip_dst
);
132 pkt
.ti_dport
= htons(atoi(s
));
136 (void) inet_aton(src
, &ip
->ip_src
);
137 (void) inet_aton(src
, &ip
->ip_dst
);
139 ip
->ip_len
= sizeof(ip_t
);
140 IP_HL_A(ip
, sizeof(ip_t
));
142 s
= strtok(misc
, " :");
143 ip
->ip_p
= getproto(s
);
149 s
= strtok(NULL
, " :");
150 ip
->ip_len
+= atoi(s
);
151 if (ip
->ip_p
== IPPROTO_TCP
)
152 extra
= sizeof(struct tcphdr
);
153 else if (ip
->ip_p
== IPPROTO_UDP
)
154 extra
= sizeof(struct udphdr
);
158 extra
= sizeof(struct igmp
);
162 extra
= sizeof(struct icmp
);
168 slen
= IP_HL(ip
) + extra
+ ip
->ip_len
;