To find out the file's packet encapsulation type (which could be
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Sat, 4 Dec 1999 11:32:25 +0000 (11:32 +0000)
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Sat, 4 Dec 1999 11:32:25 +0000 (11:32 +0000)
WTAP_ENCAP_PER_PACKET, if there's more than one type of packet in the
file, or could be WTAP_ENCAP_UNKNOWN, if the file is of a type that
doesn't put an encapsulation type in the file header, and it has no
packets), we just need to call "wtap_file_encap()" when we're done
reading the file.

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

file.c
file.h

diff --git a/file.c b/file.c
index fc3b8c1b689e3a845e06803a7a594fcc87d78c20..d30b3600ad52fe106e160047b4e044de1c505a12 100644 (file)
--- a/file.c
+++ b/file.c
@@ -1,7 +1,7 @@
 /* file.c
  * File I/O routines
  *
- * $Id: file.c,v 1.133 1999/12/04 08:59:12 guy Exp $
+ * $Id: file.c,v 1.134 1999/12/04 11:32:24 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@zing.org>
@@ -163,7 +163,6 @@ open_cap_file(char *fname, gboolean is_tempfile, capture_file *cf)
   cf->user_saved = !is_tempfile;
 
   cf->cd_t      = wtap_file_type(cf->wth);
-  cf->first_packet = TRUE;
   cf->count     = 0;
   cf->drops     = 0;
   cf->esec      = 0;
@@ -308,6 +307,11 @@ read_cap_file(capture_file *cf)
   freeze_clist(cf);
   proto_tree_is_visible = FALSE;
   success = wtap_loop(cf->wth, 0, wtap_dispatch_cb, (u_char *) cf, &err);
+  /* Set the file encapsulation type now; we don't know what it is until
+     we've looked at all the packets, as we don't know until then whether
+     there's more than one type (and thus whether it's
+     WTAP_ENCAP_PER_PACKET). */
+  cf->lnk_t = wtap_file_encap(cf->wth);
   wtap_close(cf->wth);
   cf->wth = NULL;
   cf->filed = open(cf->filename, O_RDONLY);
@@ -454,6 +458,12 @@ finish_tail_cap_file(capture_file *cf)
     gtk_clist_moveto(GTK_CLIST(packet_list), 
                       cf->plist_end->row, -1, 1.0, 1.0);
 
+  /* Set the file encapsulation type now; we don't know what it is until
+     we've looked at all the packets, as we don't know until then whether
+     there's more than one type (and thus whether it's
+     WTAP_ENCAP_PER_PACKET). */
+  cf->lnk_t = wtap_file_encap(cf->wth);
+
   /* There's nothing more to read from the capture file - close it. */
   wtap_close(cf->wth);
   cf->wth = NULL;
@@ -897,19 +907,6 @@ wtap_dispatch_cb(u_char *user, const struct wtap_pkthdr *phdr, int offset,
       gtk_main_iteration();
   }
 
-  if (cf->first_packet) {
-    /* Tentatively make the encapsulation type the type of the first
-       packet. */
-    cf->lnk_t = phdr->pkt_encap;
-  } else {
-    /* If this packet's encapsulation type isn't the same as the type
-       type we've chosen so far, make the type for this file
-       WTAP_ENCAP_PER_PACKET, because there is no single encapsulation
-       type for the entire file. */
-    if (cf->lnk_t != phdr->pkt_encap)
-      cf->lnk_t = WTAP_ENCAP_PER_PACKET;
-  }
-
   /* Allocate the next list entry, and add it to the list. */
   fdata = (frame_data *) g_malloc(sizeof(frame_data));
 
diff --git a/file.h b/file.h
index 6680467cc191b223499a474c5ed0ef990ffafa66..6953eb85164706d4d2261b3692588f9e12ba6d51 100644 (file)
--- a/file.h
+++ b/file.h
@@ -1,7 +1,7 @@
 /* file.h
  * Definitions for file structures and routines
  *
- * $Id: file.h,v 1.59 1999/12/04 08:59:13 guy Exp $
+ * $Id: file.h,v 1.60 1999/12/04 11:32:25 guy Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@zing.org>
@@ -81,7 +81,6 @@ typedef struct _capture_file {
   gboolean     user_saved;/* If capture file is temporary, has it been saved by user yet? */
   long         f_len;     /* Length of capture file */
   guint16      cd_t;      /* File type of capture file */
-  gboolean     first_packet; /* TRUE if we're looking at the first packet */
   int          lnk_t;     /* Link-layer type with which to save capture */
   guint32      vers;      /* Version.  For tcpdump minor is appended to major */
   guint32      count;     /* Packet count */