Fix the pcap-encapsulation-to-wiretap-encapsulation mapping table.
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Sun, 22 Aug 1999 03:50:31 +0000 (03:50 +0000)
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Sun, 22 Aug 1999 03:50:31 +0000 (03:50 +0000)
Have the code that opens "libpcap" files for writing check to make sure
that the Wiretap encapsulation can be written to a "libpcap" file, and
return -1 and supply a new WTAP_ERR_UNSUPPORTED_ENCAP error code if it
can't.

Handle that new error code in "wtap_strerror()".

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

wiretap/libpcap.c
wiretap/wtap.c
wiretap/wtap.h

index aee592fda78d30e5c3ec5bc8916190d8b23c9fde..ff9bde6e4f17c92179d4882472db4dc8670b0f5d 100644 (file)
@@ -1,6 +1,6 @@
 /* libpcap.c
  *
- * $Id: libpcap.c,v 1.12 1999/08/22 02:29:37 guy Exp $
+ * $Id: libpcap.c,v 1.13 1999/08/22 03:50:31 guy Exp $
  *
  * Wiretap Library
  * Copyright (c) 1998 by Gilbert Ramirez <gram@verdict.uthscsa.edu>
@@ -292,7 +292,7 @@ int libpcap_dump_open(wtap_dumper *wdh, int *err)
        static const guint32 pcap_magic = PCAP_MAGIC;
        struct pcap_hdr file_hdr;
        static const int wtap_encap[] = {
-               0,              /* WTAP_ENCAP_UNKNOWN -> DLT_NULL */
+               -1,             /* WTAP_ENCAP_UNKNOWN -> unsupported */
                1,              /* WTAP_ENCAP_ETHERNET -> DLT_EN10MB */
                6,              /* WTAP_ENCAP_TR -> DLT_IEEE802 */
                8,              /* WTAP_ENCAP_SLIP -> DLT_SLIP */
@@ -302,8 +302,11 @@ int libpcap_dump_open(wtap_dumper *wdh, int *err)
                7,              /* WTAP_ENCAP_ARCNET -> DLT_ARCNET */
                11,             /* WTAP_ENCAP_ATM_RFC1483 -> DLT_ATM_RFC1483 */
                19,             /* WTAP_ENCAP_LINUX_ATM_CLIP */
+               -1,             /* WTAP_ENCAP_LAPB -> unsupported*/
+               -1,             /* WTAP_ENCAP_ATM_SNIFFER -> unsupported */
                0               /* WTAP_ENCAP_NULL -> DLT_NULL */
        };
+       #define NUM_WTAP_ENCAPS (sizeof wtap_encap / sizeof wtap_encap[0])
        int nwritten;
 
        /* Per-packet encapsulations aren't supported. */
@@ -312,6 +315,12 @@ int libpcap_dump_open(wtap_dumper *wdh, int *err)
                return 0;
        }
 
+       if (wdh->encap < 0 || wdh->encap >= NUM_WTAP_ENCAPS
+           || wtap_encap[wdh->encap] == -1) {
+               *err = WTAP_ERR_UNSUPPORTED_ENCAP;
+               return 0;
+       }
+
        /* This is a libpcap file */
        wdh->subtype_write = libpcap_dump;
        wdh->subtype_close = libpcap_dump_close;
index 58c95b4eb48a27a5f34cc0879cfa3dc1a7ae9b3c..cdc48c63ed39c92b02c94d04df6d11f3e514d5a5 100644 (file)
@@ -1,6 +1,6 @@
 /* wtap.c
  *
- * $Id: wtap.c,v 1.16 1999/08/22 02:52:48 guy Exp $
+ * $Id: wtap.c,v 1.17 1999/08/22 03:50:31 guy Exp $
  *
  * Wiretap Library
  * Copyright (c) 1998 by Gilbert Ramirez <gram@verdict.uthscsa.edu>
@@ -94,6 +94,7 @@ static const char *wtap_errlist[] = {
        "File contains record data we don't support",
        NULL,
        "Files can't be saved in that format",
+       "Files from that network type can't be saved in that format",
        "That format doesn't support per-packet encapsulations",
        NULL,
        NULL,
index 3ccfe55644072cef4a0ec21072f4ca64c8499ad8..0ed96c0bae497fe6bdd128c77a58888ce9210698 100644 (file)
@@ -1,6 +1,6 @@
 /* wtap.h
  *
- * $Id: wtap.h,v 1.32 1999/08/22 02:52:48 guy Exp $
+ * $Id: wtap.h,v 1.33 1999/08/22 03:50:30 guy Exp $
  *
  * Wiretap Library
  * Copyright (c) 1998 by Gilbert Ramirez <gram@verdict.uthscsa.edu>
@@ -320,17 +320,20 @@ int wtap_pcap_encap_to_wtap_encap(int encap);
        /* The file couldn't be opened, reason unknown */
 #define        WTAP_ERR_UNSUPPORTED_FILE_TYPE          -5
        /* Wiretap can't save files in the specified format */
-#define        WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED   -6
+#define        WTAP_ERR_UNSUPPORTED_ENCAP              -6
+       /* Wiretap can't save files in the specified format with the
+          specified encapsulation */
+#define        WTAP_ERR_ENCAP_PER_PACKET_UNSUPPORTED   -7
        /* The specified format doesn't support per-packet encapsulations */
-#define        WTAP_ERR_CANT_CLOSE                     -7
+#define        WTAP_ERR_CANT_CLOSE                     -8
        /* The file couldn't be closed, reason unknown */
-#define        WTAP_ERR_CANT_READ                      -8
+#define        WTAP_ERR_CANT_READ                      -9
        /* An attempt to read failed, reason unknown */
-#define        WTAP_ERR_SHORT_READ                     -9
+#define        WTAP_ERR_SHORT_READ                     -10
        /* An attempt to read read less data than it should have */
-#define        WTAP_ERR_BAD_RECORD                     -10
+#define        WTAP_ERR_BAD_RECORD                     -11
        /* We read an invalid record */
-#define        WTAP_ERR_SHORT_WRITE                    -11
+#define        WTAP_ERR_SHORT_WRITE                    -12
        /* An attempt to write wrote less data than it should have */
 
 /* Pointer versions of ntohs and ntohl.  Given a pointer to a member of a