]> The Tcpdump Group git mirrors - tcpdump/commitdiff
From Gisle Vanem <[email protected]>:
authorguy <guy>
Sat, 8 Feb 2003 19:31:59 +0000 (19:31 +0000)
committerguy <guy>
Sat, 8 Feb 2003 19:31:59 +0000 (19:31 +0000)
open the file containing a filter expression in binary mode, so
that we get all the characters that "fstat()" claims are there,
rather than having CRs stripped out (causing us to report an
error because the "read()" call gives us less data than
"fstat()" claims was in the file);

close the file descriptor once we're finished reading the file;

strip out everything on a line starting with "#", so that "#"
can be used for to-end-of-line comments in the file.

Update his address in the CREDITS file.

CREDITS
util.c

diff --git a/CREDITS b/CREDITS
index 8915959600f9ea2fae4f51e6d42bbc399aeaddf8..a6df2dde01a9fab1bc9633d43ab374983b2ef8d7 100644 (file)
--- a/CREDITS
+++ b/CREDITS
@@ -40,7 +40,7 @@ Additional people who have contributed patches:
        George Bakos                    <[email protected]>
        Gert Doering                    <[email protected]>
        Gilbert Ramirez Jr.             <[email protected]>
-       Gisle Vanem                     <gvanem@eunet.no>
+       Gisle Vanem                     <giva@bgnett.no>
        Harry Raaymakers                <[email protected]>
        Heinz-Ado Arnolds               <[email protected]>
        Hendrik Scholz                  <[email protected]>
diff --git a/util.c b/util.c
index a1c9f094c66673cb302836eba6cc7f62efc20c3c..81f456d9e93b6b730063b271bd70f0f07e5b9962 100644 (file)
--- a/util.c
+++ b/util.c
@@ -21,7 +21,7 @@
 
 #ifndef lint
 static const char rcsid[] =
-    "@(#) $Header: /tcpdump/master/tcpdump/util.c,v 1.82 2002-12-22 01:26:49 hannes Exp $ (LBL)";
+    "@(#) $Header: /tcpdump/master/tcpdump/util.c,v 1.83 2003-02-08 19:32:00 guy Exp $ (LBL)";
 #endif
 
 #ifdef HAVE_CONFIG_H
@@ -412,14 +412,24 @@ copy_argv(register char **argv)
        return buf;
 }
 
+/*
+ * On Windows, we need to open the file in binary mode, so that
+ * we get all the bytes specified by the size we get from "fstat()".
+ * On UNIX, that's not necessary.  O_BINARY is defined on Windows;
+ * we define it as 0 if it's not defined, so it does nothing.
+ */
+#ifndef O_BINARY
+#define O_BINARY       0
+#endif
+
 char *
 read_infile(char *fname)
 {
-       register int fd, cc;
+       register int i, fd, cc;
        register char *cp;
        struct stat buf;
 
-       fd = open(fname, O_RDONLY);
+       fd = open(fname, O_RDONLY|O_BINARY);
        if (fd < 0)
                error("can't open %s: %s", fname, pcap_strerror(errno));
 
@@ -434,18 +444,16 @@ read_infile(char *fname)
        if (cc < 0)
                error("read %s: %s", fname, pcap_strerror(errno));
        if (cc != buf.st_size)
-#ifndef WIN32
                error("short read %s (%d != %d)", fname, cc, (int)buf.st_size);
-#else
-/* Windows seems not to like the final \xa character */
-       {
-               char *pdest;
-               pdest=strchr( cp, '\xa');
-               *pdest=0;
-       }
-#endif /* WIN32 */
-       cp[(int)buf.st_size] = '\0';
 
+       close(fd);
+       /* replace "# comment" with spaces */
+       for (i = 0; i < cc; i++) {
+               if (cp[i] == '#')
+                       while (i < cc && cp[i] != '\n')
+                               cp[i++] = ' ';
+       }
+       cp[cc] = '\0';
        return (cp);
 }