summaryrefslogtreecommitdiff
path: root/util.c
diff options
context:
space:
mode:
authorguy <guy>2003-02-08 19:31:59 +0000
committerguy <guy>2003-02-08 19:31:59 +0000
commit49e3507eb3b461f89f7bf8afc90c0e567e7a698a (patch)
treedf388e838594ef5512ef58f75f8f212b0e901ff0 /util.c
parent2b27594dec682fab06f3560af4891e66c39d88ed (diff)
downloadtcpdump-49e3507eb3b461f89f7bf8afc90c0e567e7a698a.tar.gz
From Gisle Vanem <giva@bgnett.no>:
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.
Diffstat (limited to 'util.c')
-rw-r--r--util.c34
1 files changed, 21 insertions, 13 deletions
diff --git a/util.c b/util.c
index a1c9f094..81f456d9 100644
--- 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);
}