Set the pseudo-header regardless of whether we have a trailer or not.
authorguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Tue, 3 May 2011 08:49:41 +0000 (08:49 +0000)
committerguy <guy@f5534014-38df-0310-8fa8-9805f1628bb7>
Tue, 3 May 2011 08:49:41 +0000 (08:49 +0000)
git-svn-id: http://anonsvn.wireshark.org/wireshark/trunk@36974 f5534014-38df-0310-8fa8-9805f1628bb7

wiretap/netmon.c

index 89631f5549795bd1e8b333b6c925fd1268e3debb..2599613d9c3de13c6ed83604e30dbce96f089a9b 100644 (file)
@@ -182,8 +182,7 @@ static gboolean netmon_read_atm_pseudoheader(FILE_T fh,
     union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info);
 static gboolean netmon_read_rec_data(FILE_T fh, guchar *pd, int length,
     int *err, gchar **err_info);
-static int netmon_read_rec_trailer(FILE_T fh,
-    union wtap_pseudo_header *pseudo_header, int trlr_size, int *err,
+static int netmon_read_rec_trailer(FILE_T fh, int trlr_size, int *err,
     gchar **err_info);
 static void netmon_sequential_close(wtap *wth);
 static gboolean netmon_dump(wtap_dumper *wdh, const struct wtap_pkthdr *phdr,
@@ -396,6 +395,39 @@ netmon_trailer_size(netmon_t *netmon)
        return 0;       /* no trailer */
 }
 
+static void
+netmon_set_pseudo_header_info(int pkt_encap,
+    union wtap_pseudo_header *pseudo_header, guchar *pd, int length)
+{
+       switch (pkt_encap) {
+
+       case WTAP_ENCAP_ATM_PDUS:
+               /*
+                * Attempt to guess from the packet data, the VPI, and
+                * the VCIinformation about the type of traffic.
+                */
+               atm_guess_traffic_type(pd, length, pseudo_header);
+               break;
+
+       case WTAP_ENCAP_ETHERNET:
+               /*
+                * We assume there's no FCS in this frame.
+                */
+               pseudo_header->eth.fcs_len = 0;
+               break;
+
+       case WTAP_ENCAP_IEEE802_11_NETMON_RADIO:
+               /*
+                * It appears to be the case that management
+                * frames have an FCS and data frames don't;
+                * I'm not sure about control frames.  An
+                * "FCS length" of -2 means "NetMon weirdness".
+                */
+               pseudo_header->ieee_802_11.fcs_len = -2;
+               break;
+       }
+}
+
 /* Read the next packet */
 static gboolean netmon_read(wtap *wth, int *err, gchar **err_info,
     gint64 *data_offset)
@@ -567,15 +599,6 @@ again:
        wth->phdr.caplen = packet_size;
        wth->phdr.len = orig_size;
 
-       /*
-        * Attempt to guess from the packet data, the VPI, and the VCI
-        * information about the type of traffic.
-        */
-       if (wth->file_encap == WTAP_ENCAP_ATM_PDUS) {
-               atm_guess_traffic_type(data_ptr, packet_size,
-                   &wth->pseudo_header);
-       }
-
        /*
         * For version 2.1 and later, there's additional information
         * after the frame data.
@@ -586,12 +609,17 @@ again:
                 * I haz a trailer.
                 */
                wth->phdr.pkt_encap = netmon_read_rec_trailer(wth->fh,
-                   &wth->pseudo_header, trlr_size, err, err_info);
+                   trlr_size, err, err_info);
                if (wth->phdr.pkt_encap == -1)
                        return FALSE;   /* error */
                wth->data_offset += trlr_size;
                if (wth->phdr.pkt_encap == 0)
                        goto again;
+               netmon_set_pseudo_header_info(wth->phdr.pkt_encap,
+                   &wth->pseudo_header, data_ptr, packet_size);
+       } else {
+               netmon_set_pseudo_header_info(wth->file_encap,
+                   &wth->pseudo_header, data_ptr, packet_size);
        }
 
        return TRUE;
@@ -636,7 +664,7 @@ netmon_seek_read(wtap *wth, gint64 seek_off,
                 * I haz a trailer.
                 */
                pkt_encap = netmon_read_rec_trailer(wth->random_fh,
-                   pseudo_header, trlr_size, err, err_info);
+                   trlr_size, err, err_info);
                if (pkt_encap == -1)
                        return FALSE;   /* error */
                if (pkt_encap == 0) {
@@ -647,15 +675,13 @@ netmon_seek_read(wtap *wth, gint64 seek_off,
                        *err_info = g_strdup("netmon: saw metadata in netmon_seek_read");
                        return FALSE;
                }
+               netmon_set_pseudo_header_info(pkt_encap, pseudo_header,
+                   pd, length);
+       } else {
+               netmon_set_pseudo_header_info(wth->file_encap, pseudo_header,
+                   pd, length);
        }
 
-       /*
-        * Attempt to guess from the packet data, the VPI, and the VCI
-        * information about the type of traffic.
-        */
-       if (wth->file_encap == WTAP_ENCAP_ATM_PDUS)
-               atm_guess_traffic_type(pd, length, pseudo_header);
-
        return TRUE;
 }
 
@@ -720,8 +746,7 @@ netmon_read_rec_data(FILE_T fh, guchar *pd, int length, int *err,
  * we'd never return that on success).
  */
 static int
-netmon_read_rec_trailer(FILE_T fh, union wtap_pseudo_header *pseudo_header,
-    int trlr_size, int *err, gchar **err_info)
+netmon_read_rec_trailer(FILE_T fh, int trlr_size, int *err, gchar **err_info)
 {
        int     bytes_read;
        union {
@@ -794,26 +819,6 @@ netmon_read_rec_trailer(FILE_T fh, union wtap_pseudo_header *pseudo_header,
                }
        }
 
-       switch (pkt_encap) {
-
-       case WTAP_ENCAP_ETHERNET:
-               /*
-                * We assume there's no FCS in this frame.
-                */
-               pseudo_header->eth.fcs_len = 0;
-               break;
-
-       case WTAP_ENCAP_IEEE802_11_NETMON_RADIO:
-               /*
-                * It appears to be the case that management
-                * frames have an FCS and data frames don't;
-                * I'm not sure about control frames.  An
-                * "FCS length" of -2 means "NetMon weirdness".
-                */
-               pseudo_header->ieee_802_11.fcs_len = -2;
-               break;
-       }
-
        return pkt_encap;       /* success */
 }