/* 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>
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. */
/* 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>
*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;
}
/* 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>
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,
/* 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>
* 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