From mboxrd@z Thu Jan 1 00:00:00 1970 Received: (qmail 16179 invoked from network); 8 Dec 1999 14:59:55 -0000 Received: from mail.redhat.com (199.183.24.239) by lists.redhat.com with SMTP; 8 Dec 1999 14:59:55 -0000 Received: from radicalmedia.com (eel.radicalmedia.com [204.254.246.9]) by mail.redhat.com (8.8.7/8.8.7) with ESMTP id JAA11504 for ; Wed, 8 Dec 1999 09:59:54 -0500 Received: (from phiber@localhost) by radicalmedia.com (8.8.6/8.8.6) id KAA11903 for axp-list@redhat.com; Wed, 8 Dec 1999 10:06:47 -0500 (EST) Message-ID: <19991208100647.S19418@radicalmedia.com> Date: Wed, 8 Dec 1999 10:06:47 -0500 From: Mark Abene To: axp-list@redhat.com Subject: fix for libpcap and tcpdump References: Mime-Version: 1.0 Content-Type: multipart/mixed; boundary=8vCeF2GUdMpe9ZbK X-Mailer: Mutt 0.93.2i In-Reply-To: ; from Larry Sendlosky on Wed, Dec 08, 1999 at 08:20:45AM -0500 --8vCeF2GUdMpe9ZbK Content-Type: text/plain; charset=us-ascii Dan Frasnelli et al: Please accept the attached patches for libpcap and tcpdump. My changes fix some general 64-bit uncleanness, as well as a major portability issue stemming from the use of packet timestamps based on struct timeval. On Alpha, a time_t is a 64-bit long, unlike everybody else. This made packet dumps made on the Alpha incompatible with, well, everybody. We couldn't read dumps made on other systems either. I basically override the use of timeval with a "mytimeval" which is a struct containing two ints, instead of two longs, and do some typecasting where appropriate. So now we're totally compatible with everyone else! The only downside is that any app, like tcpdump for example, which prints timestamps *also* has to override the native timeval, hence my little patches to tcpdump. Nothing major, a small sacrifice in favor of portability in a heterogeneous networking environment (like the kind us security weenies are used to). If you're looking to adapt a util that uses timestamps from libpcap, just look at my tcpdump changes, they're pretty straightforward. Cheers -Mark --8vCeF2GUdMpe9ZbK Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="libpcap-0.4a6.diff" --- gencode.c.orig Tue Dec 7 13:22:26 1999 +++ gencode.c Tue Dec 7 13:23:09 1999 @@ -158,7 +158,7 @@ int k, size; /* XXX Round up to nearest long. */ - n = (n + sizeof(long) - 1) & ~(sizeof(long) - 1); + n = (n + sizeof(int) - 1) & ~(sizeof(int) - 1); cp = &chunks[cur_chunk]; if (n > cp->n_left) { @@ -966,7 +966,7 @@ #endif case Q_IGRP: b0 = gen_linktype(ETHERTYPE_IP); - b1 = gen_cmp(off_nl + 9, BPF_B, (long)IPPROTO_IGRP); + b1 = gen_cmp(off_nl + 9, BPF_B, (int)IPPROTO_IGRP); gen_and(b0, b1); break; --- pcap-int.h.orig Tue Dec 7 13:20:20 1999 +++ pcap-int.h Tue Dec 7 13:21:23 1999 @@ -53,11 +53,11 @@ struct pcap_stat stat; /*XXX*/ int use_bpf; - u_long TotPkts; /* can't oflow for 79 hrs on ether */ - u_long TotAccepted; /* count accepted by filter */ - u_long TotDrops; /* count of dropped packets */ - long TotMissed; /* missed by i/f during this run */ - long OrigMissed; /* missed by i/f before this run */ + u_int TotPkts; /* can't oflow for 79 hrs on ether */ + u_int TotAccepted; /* count accepted by filter */ + u_int TotDrops; /* count of dropped packets */ + int TotMissed; /* missed by i/f during this run */ + int OrigMissed; /* missed by i/f before this run */ #ifdef linux int pad; int skip; --- pcap-linux.c.orig Wed Dec 8 09:03:24 1999 +++ pcap-linux.c Wed Dec 8 09:46:42 1999 @@ -73,6 +73,7 @@ register u_char *bp; struct sockaddr from; int fromlen; + struct timeval tmpts; bp = p->buffer + p->offset; bufsize = p->bufsize; @@ -124,11 +125,13 @@ ++p->md.stat.ps_recv; /* Get timestamp */ - if (ioctl(p->fd, SIOCGSTAMP, &h.ts) < 0) { + if (ioctl(p->fd, SIOCGSTAMP, &tmpts) < 0) { sprintf(p->errbuf, "SIOCGSTAMP: %s", pcap_strerror(errno)); return (-1); } + h.ts.tv_sec = (int)tmpts.tv_sec; + h.ts.tv_usec = (int)tmpts.tv_usec; h.len = cc; h.caplen = caplen; (*callback)(user, &h, bp); --- pcap-pf.c.orig Tue Dec 7 13:24:36 1999 +++ pcap-pf.c Tue Dec 7 13:25:11 1999 @@ -131,7 +131,7 @@ return (-1); } #ifdef LBL_ALIGN - if ((long)bp & 3) { + if ((int)bp & 3) { sp = &stamp; memcpy((char *)sp, (char *)bp, sizeof(*sp)); } else --- pcap.h.orig Wed Dec 8 09:03:17 1999 +++ pcap.h Wed Dec 8 09:12:42 1999 @@ -81,8 +81,13 @@ * This gets around the problem of different headers for different * packet interfaces. */ +struct mytimeval { + int tv_sec; + int tv_usec; +}; + struct pcap_pkthdr { - struct timeval ts; /* time stamp */ + struct mytimeval ts; /* time stamp */ bpf_u_int32 caplen; /* length of portion present */ bpf_u_int32 len; /* length this packet (off wire) */ }; --8vCeF2GUdMpe9ZbK Content-Type: text/plain; charset=us-ascii Content-Disposition: attachment; filename="tcpdump-3.4a6.diff" --- interface.h.orig Wed Dec 8 09:30:15 1999 +++ interface.h Wed Dec 8 09:37:05 1999 @@ -131,7 +131,8 @@ struct timeval; #endif -extern void ts_print(const struct timeval *); +#include +extern void ts_print(const struct mytimeval *); extern int fn_print(const u_char *, const u_char *); extern int fn_printn(const u_char *, u_int, const u_char *); --- util.c.orig Wed Dec 8 09:30:22 1999 +++ util.c Wed Dec 8 09:31:20 1999 @@ -122,7 +122,7 @@ * Print the timestamp */ void -ts_print(register const struct timeval *tvp) +ts_print(register const struct mytimeval *tvp) { register int s; --8vCeF2GUdMpe9ZbK--