Add a new error for attempts to open a pipe or FIFO for random access.
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Fri, 7 Jun 2002 07:47:58 +0000 (07:47 +0000)
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Fri, 7 Jun 2002 07:47:58 +0000 (07:47 +0000)
Have "wtap_open_offline()", if asked to open a FIFO, return that error
if it was asked to open the file for random access.

git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@5643 f5534014-38df-0310-8fa8-9805f1628bb7

file.c
wiretap/file.c
wiretap/wtap.c
wiretap/wtap.h

diff --git a/file.c b/file.c
index 1a9a658b576c7f166d68430b3cfa35dbb7a329b1..92084bf3f2814c74315e3cd95ce5ee58bcf85510 100644 (file)
--- a/file.c
+++ b/file.c
@@ -1,7 +1,7 @@
 /* file.c
  * File I/O routines
  *
- * $Id: file.c,v 1.276 2002/06/04 07:03:44 guy Exp $
+ * $Id: file.c,v 1.277 2002/06/07 07:47:56 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
@@ -1909,6 +1909,11 @@ file_open_error_message(int err, gboolean for_writing)
     errmsg = "The file \"%s\" is a \"special file\" or socket or other non-regular file.";
     break;
 
+  case WTAP_ERR_RANDOM_OPEN_PIPE:
+    /* Seen only when opening a capture file for reading. */
+    errmsg = "The file \"%s\" is a pipe or FIFO; Ethereal cannot read pipe or FIFO files.";
+    break;
+
   case WTAP_ERR_FILE_UNKNOWN_FORMAT:
   case WTAP_ERR_UNSUPPORTED:
     /* Seen only when opening a capture file for reading. */
index 973cc948213b691d3fc9009df4fcaef0bdad21c4..516eae2c12140f560e39957178e23df5b8ac809d 100644 (file)
@@ -1,6 +1,6 @@
 /* file.c
  *
- * $Id: file.c,v 1.91 2002/06/07 07:27:34 guy Exp $
+ * $Id: file.c,v 1.92 2002/06/07 07:47:57 guy Exp $
  *
  * Wiretap Library
  * Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
@@ -179,11 +179,33 @@ wtap* wtap_open_offline(const char *filename, int *err, gboolean do_random)
                *err = errno;
                return NULL;
        }
-       if (! S_ISREG(statb.st_mode) && ! S_ISFIFO(statb.st_mode)) {
-               if (S_ISDIR(statb.st_mode))
-                       *err = EISDIR;
-               else
-                       *err = WTAP_ERR_NOT_REGULAR_FILE;
+       if (S_ISFIFO(statb.st_mode)) {
+               /*
+                * Opens of FIFOs are allowed only when not opening
+                * for random access.
+                *
+                * XXX - currently, we do seeking when trying to find
+                * out the file type, so we don't actually support
+                * opening FIFOs.  However, we may eventually
+                * do buffering that allows us to do at least some
+                * file type determination even on pipes, so we
+                * allow FIFO opens and let things fail later when
+                * we try to seek.
+                */
+               if (do_random) {
+                       *err = WTAP_ERR_RANDOM_OPEN_PIPE;
+                       return NULL;
+               }
+       } else if (S_ISDIR(statb.st_mode)) {
+               /*
+                * Return different errors for "this is a directory"
+                * and "this is some random special file type", so
+                * the user can get a potentially more helpful error.
+                */
+               *err = EISDIR;
+               return NULL;
+       } else if (! S_ISREG(statb.st_mode)) {
+               *err = WTAP_ERR_NOT_REGULAR_FILE;
                return NULL;
        }
 
index ec71287323aecb7c960af46be419cd049a7be954..c0cc35c00390a5339cd2b195646ebb1784343dbc 100644 (file)
@@ -1,6 +1,6 @@
 /* wtap.c
  *
- * $Id: wtap.c,v 1.65 2002/04/08 09:44:42 guy Exp $
+ * $Id: wtap.c,v 1.66 2002/06/07 07:47:57 guy Exp $
  *
  * Wiretap Library
  * Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
@@ -180,6 +180,7 @@ wtap_short_string_to_encap(const char *short_name)
 
 static const char *wtap_errlist[] = {
        "The file isn't a plain file",
+       "The file is being opened for random access but is a pipe",
        "The file isn't a capture file in a known format",
        "File contains record data we don't support",
        NULL,
index 4e51a47dfba8b502c2177f7c1536d5bf3f4edb62..857fd885574ff43ba193802eb42e995c564b759d 100644 (file)
@@ -1,6 +1,6 @@
 /* wtap.h
  *
- * $Id: wtap.h,v 1.112 2002/05/28 02:39:15 guy Exp $
+ * $Id: wtap.h,v 1.113 2002/06/07 07:47:58 guy Exp $
  *
  * Wiretap Library
  * Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
@@ -387,36 +387,38 @@ int wtap_pcap_encap_to_wtap_encap(int encap);
  * Wiretap error codes.
  */
 #define        WTAP_ERR_NOT_REGULAR_FILE               -1
-       /* The file being opened for reading isn't a plain file */
-#define        WTAP_ERR_FILE_UNKNOWN_FORMAT            -2
+       /* The file being opened for reading isn't a plain file (or pipe) */
+#define        WTAP_ERR_RANDOM_OPEN_PIPE               -2
+       /* The file is being opened for random access and it's a pipe */
+#define        WTAP_ERR_FILE_UNKNOWN_FORMAT            -3
        /* The file being opened is not a capture file in a known format */
-#define        WTAP_ERR_UNSUPPORTED                    -3
+#define        WTAP_ERR_UNSUPPORTED                    -4
        /* Supported file type, but there's something in the file we
           can't support */
-#define        WTAP_ERR_CANT_OPEN                      -4
+#define        WTAP_ERR_CANT_OPEN                      -5
        /* The file couldn't be opened, reason unknown */
-#define        WTAP_ERR_UNSUPPORTED_FILE_TYPE          -5
+#define        WTAP_ERR_UNSUPPORTED_FILE_TYPE          -6
        /* Wiretap can't save files in the specified format */
-#define        WTAP_ERR_UNSUPPORTED_ENCAP              -6
+#define        WTAP_ERR_UNSUPPORTED_ENCAP              -7
        /* Wiretap can't read or save files in the specified format with the
           specified encapsulation */
-#define        WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED   -7
+#define        WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED   -8
        /* The specified format doesn't support per-packet encapsulations */
-#define        WTAP_ERR_CANT_CLOSE                     -8
+#define        WTAP_ERR_CANT_CLOSE                     -9
        /* The file couldn't be closed, reason unknown */
-#define        WTAP_ERR_CANT_READ                      -9
+#define        WTAP_ERR_CANT_READ                      -10
        /* An attempt to read failed, reason unknown */
-#define        WTAP_ERR_SHORT_READ                     -10
+#define        WTAP_ERR_SHORT_READ                     -11
        /* An attempt to read read less data than it should have */
-#define        WTAP_ERR_BAD_RECORD                     -11
+#define        WTAP_ERR_BAD_RECORD                     -12
        /* We read an invalid record */
-#define        WTAP_ERR_SHORT_WRITE                    -12
+#define        WTAP_ERR_SHORT_WRITE                    -13
        /* An attempt to write wrote less data than it should have */
-#define        WTAP_ERR_UNC_TRUNCATED                  -13
+#define        WTAP_ERR_UNC_TRUNCATED                  -14
        /* Sniffer compressed data was oddly truncated */
-#define        WTAP_ERR_UNC_OVERFLOW                   -14
+#define        WTAP_ERR_UNC_OVERFLOW                   -15
        /* Uncompressing Sniffer data would overflow buffer */
-#define        WTAP_ERR_UNC_BAD_OFFSET                 -15
+#define        WTAP_ERR_UNC_BAD_OFFSET                 -16
        /* LZ77 compressed data has bad offset to string */
 
 /* Errors from zlib; zlib error Z_xxx turns into Wiretap error