2 * Copyright (C) 1993-2001 by Darren Reed.
4 * See the IPFILTER.LICENCE file for details on licencing.
10 00:05:47.816843 128.231.76.76.3291 > 224.2.252.231.36573: udp 36 (encap)
14 00:33:48.410771 192.73.213.11.1463 > 224.2.248.153.59360: udp 31 (encap)
18 128.250.133.13.23 > 128.250.20.20.2419: tcp 27
22 123456789.1234567 128.250.133.13.23 > 128.250.20.20.2419: tcp 27
26 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
29 #if defined(__sgi) && (IRIX > 602)
30 # include <sys/ptimers.h>
34 #if !defined(__SVR4) && !defined(__GNUC__)
37 #include <sys/types.h>
38 #include <sys/param.h>
43 #include <sys/socket.h>
44 #include <sys/ioctl.h>
45 #include <netinet/in.h>
46 #include <arpa/inet.h>
47 #include <netinet/in_systm.h>
49 #include <netinet/ip_var.h>
51 #include <netinet/ip.h>
52 #include <netinet/tcp.h>
53 #include <netinet/udp.h>
54 #include <netinet/ip_icmp.h>
57 #include "ip_compat.h"
58 #include <netinet/tcpip.h>
63 static const char sccsid
[] = "@(#)ipft_td.c 1.8 2/4/96 (C)1995 Darren Reed";
64 static const char rcsid
[] = "@(#)$Id: ipft_td.c,v 2.2.2.6 2003/05/31 02:13:04 darrenr Exp $";
67 static int tcpd_open
__P((char *));
68 static int tcpd_close
__P((void));
69 static int tcpd_readip
__P((char *, int, char **, int *));
70 static int count_dots
__P((char *));
72 struct ipread tcpd
= { tcpd_open
, tcpd_close
, tcpd_readip
};
74 static FILE *tfp
= NULL
;
78 static int tcpd_open(fname
)
84 if (!strcmp(fname
, "-")) {
88 tfd
= open(fname
, O_RDONLY
);
89 tfp
= fdopen(tfd
, "r");
95 static int tcpd_close()
102 static int count_dots(str
)
114 static int tcpd_readip(buf
, cnt
, ifn
, dir
)
119 ip_t
*ip
= (ip_t
*)&pkt
;
121 char src
[32], dst
[32], misc
[256], time
[32], link1
[32], link2
[32];
123 int n
, slen
, extra
= 0;
125 if (!fgets(lbuf
, sizeof(lbuf
) - 1, tfp
))
128 if ((s
= strchr(lbuf
, '\n')))
130 lbuf
[sizeof(lbuf
)-1] = '\0';
132 bzero(&pkt
, sizeof(pkt
));
134 if ((n
= sscanf(lbuf
, "%31s > %31s: %255s", src
, dst
, misc
)) != 3)
135 if ((n
= sscanf(lbuf
, "%31s %31s > %31s: %255s",
136 time
, src
, dst
, misc
)) != 4)
137 if ((n
= sscanf(lbuf
, "%31s %31s: %31s > %31s: %255s",
138 link1
, link2
, src
, dst
, misc
)) != 5) {
140 "%31s %31s %31s: %31s > %31s: %255s",
141 time
, link1
, link2
, src
, dst
, misc
);
146 if (count_dots(dst
) == 4) {
147 s
= strrchr(src
, '.');
149 (void) inet_aton(src
, &ip
->ip_src
);
150 pkt
.ti_sport
= htons(atoi(s
));
152 s
= strrchr(dst
, '.');
155 (void) inet_aton(src
, &ip
->ip_dst
);
156 pkt
.ti_dport
= htons(atoi(s
));
160 (void) inet_aton(src
, &ip
->ip_src
);
161 (void) inet_aton(src
, &ip
->ip_dst
);
163 ip
->ip_len
= ip
->ip_hl
= (unsigned)sizeof(ip_t
);
165 s
= strtok(misc
, " :");
166 if ((p
= getprotobyname(s
))) {
167 ip
->ip_p
= p
->p_proto
;
169 switch (p
->p_proto
) {
172 s
= strtok(NULL
, " :");
173 ip
->ip_len
+= atoi(s
);
174 if (p
->p_proto
== IPPROTO_TCP
)
175 extra
= sizeof(struct tcphdr
);
176 else if (p
->p_proto
== IPPROTO_UDP
)
177 extra
= sizeof(struct udphdr
);
181 extra
= sizeof(struct igmp
);
185 extra
= sizeof(struct icmp
);
191 slen
= ip
->ip_hl
+ extra
+ ip
->ip_len
;