Handle the new LINKTYPE_CAN_SOCKETCAN_HOSTENDIAN.
[metze/wireshark/wip.git] / wiretap / iptrace.c
index f427cff95ba47e827739786e6a4d0c1a4b725100..235b317251c9a7a26dc69fd4a19dedfc0e240d0b 100644 (file)
@@ -1,6 +1,4 @@
 /* iptrace.c
- *
- * $Id$
  *
  * Wiretap Library
  * Copyright (c) 1998 by Gilbert Ramirez <gram@alumni.rice.edu>
  *
  * You should have received a copy of the GNU General Public License
  * along with this program; if not, write to the Free Software
- * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA  02111-1307, USA.
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
  *
  */
-#ifdef HAVE_CONFIG_H
 #include "config.h"
-#endif
 #include <stdlib.h>
 #include <errno.h>
 #include <string.h>
 #include "wtap-int.h"
 #include "file_wrappers.h"
-#include "buffer.h"
 #include "atm.h"
 #include "iptrace.h"
 
+#define IPTRACE_IFT_HF 0x3d    /* Support for PERCS IP-HFI*/
+#define IPTRACE_IFT_IB  0xc7    /* IP over Infiniband. Number by IANA */
+
 static gboolean iptrace_read_1_0(wtap *wth, int *err, gchar **err_info,
-    long *data_offset);
-static gboolean iptrace_seek_read_1_0(wtap *wth, long seek_off,
-    union wtap_pseudo_header *pseudo_header, guchar *pd, int packet_size,
-    int *err, gchar **err_info);
+    gint64 *data_offset);
+static gboolean iptrace_seek_read_1_0(wtap *wth, gint64 seek_off,
+    struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info);
 
 static gboolean iptrace_read_2_0(wtap *wth, int *err, gchar **err_info,
-    long *data_offset);
-static gboolean iptrace_seek_read_2_0(wtap *wth, long seek_off,
-    union wtap_pseudo_header *pseudo_header, guchar *pd, int packet_size,
-    int *err, gchar **err_info);
-
-static int iptrace_read_rec_header(FILE_T fh, guint8 *header, int header_len,
-    int *err);
-static gboolean iptrace_read_rec_data(FILE_T fh, guint8 *data_ptr,
-    int packet_size, int *err);
-static void fill_in_pseudo_header(int encap, const guint8 *pd, guint32 len,
+    gint64 *data_offset);
+static gboolean iptrace_seek_read_2_0(wtap *wth, gint64 seek_off,
+    struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info);
+
+static gboolean iptrace_read_rec_data(FILE_T fh, Buffer *buf,
+    struct wtap_pkthdr *phdr, int *err, gchar **err_info);
+static void fill_in_pseudo_header(int encap,
     union wtap_pseudo_header *pseudo_header, guint8 *header);
 static int wtap_encap_ift(unsigned int  ift);
 
-int iptrace_open(wtap *wth, int *err, gchar **err_info _U_)
+#define NAME_SIZE 11
+
+wtap_open_return_val iptrace_open(wtap *wth, int *err, gchar **err_info)
 {
-       int bytes_read;
-       char name[12];
-
-       errno = WTAP_ERR_CANT_READ;
-       bytes_read = file_read(name, 1, 11, wth->fh);
-       if (bytes_read != 11) {
-               *err = file_error(wth->fh);
-               if (*err != 0)
-                       return -1;
-               return 0;
+       char name[NAME_SIZE+1];
+
+       if (!wtap_read_bytes(wth->fh, name, NAME_SIZE, err, err_info)) {
+               if (*err != WTAP_ERR_SHORT_READ)
+                       return WTAP_OPEN_ERROR;
+               return WTAP_OPEN_NOT_MINE;
        }
-       wth->data_offset += 11;
-       name[11] = 0;
+       name[NAME_SIZE] = '\0';
 
        if (strcmp(name, "iptrace 1.0") == 0) {
-               wth->file_type = WTAP_FILE_IPTRACE_1_0;
+               wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_IPTRACE_1_0;
                wth->subtype_read = iptrace_read_1_0;
                wth->subtype_seek_read = iptrace_seek_read_1_0;
+               wth->file_tsprec = WTAP_TSPREC_SEC;
        }
        else if (strcmp(name, "iptrace 2.0") == 0) {
-               wth->file_type = WTAP_FILE_IPTRACE_2_0;
+               wth->file_type_subtype = WTAP_FILE_TYPE_SUBTYPE_IPTRACE_2_0;
                wth->subtype_read = iptrace_read_2_0;
                wth->subtype_seek_read = iptrace_seek_read_2_0;
+               wth->file_tsprec = WTAP_TSPREC_NSEC;
        }
        else {
-               return 0;
+               return WTAP_OPEN_NOT_MINE;
        }
 
-       return 1;
+       return WTAP_OPEN_MINE;
 }
 
 /***********************************************************
@@ -120,26 +113,18 @@ typedef struct {
 #define IPTRACE_1_0_PHDR_SIZE  30      /* initial header plus packet data */
 #define IPTRACE_1_0_PDATA_SIZE 22      /* packet data */
 
-/* Read the next packet */
-static gboolean iptrace_read_1_0(wtap *wth, int *err, gchar **err_info _U_,
-    long *data_offset)
+static gboolean
+iptrace_read_rec_1_0(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf,
+    int *err, gchar **err_info)
 {
-       int                     ret;
-       guint32                 packet_size;
        guint8                  header[IPTRACE_1_0_PHDR_SIZE];
-       guint8                  *data_ptr;
        iptrace_1_0_phdr        pkt_hdr;
-       guchar                  fddi_padding[3];
+       guint32                 packet_size;
 
-       /* Read the descriptor data */
-       *data_offset = wth->data_offset;
-       ret = iptrace_read_rec_header(wth->fh, header, IPTRACE_1_0_PHDR_SIZE,
-           err);
-       if (ret <= 0) {
+       if (!wtap_read_bytes_or_eof(fh, header, sizeof header, err, err_info)) {
                /* Read error or EOF */
                return FALSE;
        }
-       wth->data_offset += IPTRACE_1_0_PHDR_SIZE;
 
        /*
         * Byte 28 of the frame header appears to be a BSD-style IFT_xxx
@@ -147,52 +132,93 @@ static gboolean iptrace_read_1_0(wtap *wth, int *err, gchar **err_info _U_,
         * <net/if_types.h> header file.
         */
        pkt_hdr.if_type = header[28];
-       wth->phdr.pkt_encap = wtap_encap_ift(pkt_hdr.if_type);
+       phdr->pkt_encap = wtap_encap_ift(pkt_hdr.if_type);
+       if (phdr->pkt_encap == WTAP_ENCAP_UNKNOWN) {
+               *err = WTAP_ERR_UNSUPPORTED;
+               *err_info = g_strdup_printf("iptrace: interface type IFT=0x%02x unknown or unsupported",
+                   pkt_hdr.if_type);
+               return FALSE;
+       }
 
-       /* Read the packet data */
-       packet_size = pntohl(&header[0]) - IPTRACE_1_0_PDATA_SIZE;
+       /* Read the packet metadata */
+       packet_size = pntoh32(&header[0]);
+       if (packet_size < IPTRACE_1_0_PDATA_SIZE) {
+               /*
+                * Uh-oh, the record isn't big enough to even have a
+                * packet meta-data header.
+                */
+               *err = WTAP_ERR_BAD_FILE;
+               *err_info = g_strdup_printf("iptrace: file has a %u-byte record, too small to have even a packet meta-data header",
+                   packet_size);
+               return FALSE;
+       }
+       packet_size -= IPTRACE_1_0_PDATA_SIZE;
 
        /*
         * AIX appears to put 3 bytes of padding in front of FDDI
         * frames; strip that crap off.
         */
-       if (wth->phdr.pkt_encap == WTAP_ENCAP_FDDI_BITSWAPPED) {
+       if (phdr->pkt_encap == WTAP_ENCAP_FDDI_BITSWAPPED) {
                /*
                 * The packet size is really a record size and includes
                 * the padding.
                 */
+               if (packet_size < 3) {
+                       /*
+                        * Uh-oh, the record isn't big enough to even have
+                        * the padding.
+                        */
+                       *err = WTAP_ERR_BAD_FILE;
+                       *err_info = g_strdup_printf("iptrace: file has a %u-byte record, too small to have even a packet meta-data header",
+                           packet_size + IPTRACE_1_0_PDATA_SIZE);
+                       return FALSE;
+               }
                packet_size -= 3;
-               wth->data_offset += 3;
 
                /*
-                * Read the padding.
+                * Skip the padding.
                 */
-               if (!iptrace_read_rec_data(wth->fh, fddi_padding, 3, err))
-                       return FALSE;   /* Read error */
+               if (!file_skip(fh, 3, err))
+                       return FALSE;
+       }
+       if (packet_size > WTAP_MAX_PACKET_SIZE) {
+               /*
+                * Probably a corrupt capture file; don't blow up trying
+                * to allocate space for an immensely-large packet.
+                */
+               *err = WTAP_ERR_BAD_FILE;
+               *err_info = g_strdup_printf("iptrace: File has %u-byte packet, bigger than maximum of %u",
+                   packet_size, WTAP_MAX_PACKET_SIZE);
+               return FALSE;
        }
 
-       buffer_assure_space( wth->frame_buffer, packet_size );
-       data_ptr = buffer_start_ptr( wth->frame_buffer );
-       if (!iptrace_read_rec_data(wth->fh, data_ptr, packet_size, err))
-               return FALSE;   /* Read error */
-       wth->data_offset += packet_size;
+       phdr->rec_type = REC_TYPE_PACKET;
+       phdr->presence_flags = WTAP_HAS_TS;
+       phdr->len = packet_size;
+       phdr->caplen = packet_size;
+       phdr->ts.secs = pntoh32(&header[4]);
+       phdr->ts.nsecs = 0;
 
-       wth->phdr.len = packet_size;
-       wth->phdr.caplen = packet_size;
-       wth->phdr.ts.tv_sec = pntohl(&header[4]);
-       wth->phdr.ts.tv_usec = 0;
+       /* Fill in the pseudo-header. */
+       fill_in_pseudo_header(phdr->pkt_encap, &phdr->pseudo_header, header);
 
-       if (wth->phdr.pkt_encap == WTAP_ENCAP_UNKNOWN) {
-               *err = WTAP_ERR_UNSUPPORTED_ENCAP;
-               *err_info = g_strdup_printf("iptrace: interface type IFT=0x%02x unknown or unsupported",
-                   pkt_hdr.if_type);
+       /* Get the packet data */
+       return iptrace_read_rec_data(fh, buf, phdr, err, err_info);
+}
+
+/* Read the next packet */
+static gboolean iptrace_read_1_0(wtap *wth, int *err, gchar **err_info,
+    gint64 *data_offset)
+{
+       *data_offset = file_tell(wth->fh);
+
+       /* Read the packet */
+       if (!iptrace_read_rec_1_0(wth->fh, &wth->phdr, wth->frame_buffer,
+           err, err_info)) {
+               /* Read error or EOF */
                return FALSE;
        }
 
-       /* Fill in the pseudo-header. */
-       fill_in_pseudo_header(wth->phdr.pkt_encap, data_ptr, wth->phdr.caplen,
-           &wth->pseudo_header, header);
-
        /* If the per-file encapsulation isn't known, set it to this
           packet's encapsulation.
 
@@ -209,55 +235,18 @@ static gboolean iptrace_read_1_0(wtap *wth, int *err, gchar **err_info _U_,
        return TRUE;
 }
 
-static gboolean iptrace_seek_read_1_0(wtap *wth, long seek_off,
-    union wtap_pseudo_header *pseudo_header, guchar *pd, int packet_size,
-    int *err, gchar **err_info _U_)
+static gboolean iptrace_seek_read_1_0(wtap *wth, gint64 seek_off,
+    struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info)
 {
-       int                     ret;
-       guint8                  header[IPTRACE_1_0_PHDR_SIZE];
-       int                     pkt_encap;
-       guchar                  fddi_padding[3];
-
        if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
                return FALSE;
 
-       /* Read the descriptor data */
-       ret = iptrace_read_rec_header(wth->random_fh, header,
-           IPTRACE_1_0_PHDR_SIZE, err);
-       if (ret <= 0) {
-               /* Read error or EOF */
-               if (ret == 0) {
-                       /* EOF means "short read" in random-access mode */
+       /* Read the packet */
+       if (!iptrace_read_rec_1_0(wth->random_fh, phdr, buf, err, err_info)) {
+               if (*err == 0)
                        *err = WTAP_ERR_SHORT_READ;
-               }
                return FALSE;
        }
-
-       /*
-        * Get the interface type.
-        */
-       pkt_encap = wtap_encap_ift(header[28]);
-
-       /*
-        * AIX appears to put 3 bytes of padding in front of FDDI
-        * frames; strip that crap off.
-        */
-       if (pkt_encap == WTAP_ENCAP_FDDI_BITSWAPPED) {
-               /*
-                * Read the padding.
-                */
-               if (!iptrace_read_rec_data(wth->random_fh, fddi_padding, 3, err))
-                       return FALSE;   /* Read error */
-       }
-
-       /* Get the packet data */
-       if (!iptrace_read_rec_data(wth->random_fh, pd, packet_size, err))
-               return FALSE;
-
-       /* Fill in the pseudo_header. */
-       fill_in_pseudo_header(pkt_encap, pd, packet_size, pseudo_header,
-           header);
-
        return TRUE;
 }
 
@@ -299,26 +288,18 @@ typedef struct {
 #define IPTRACE_2_0_PHDR_SIZE  40      /* initial header plus packet data */
 #define IPTRACE_2_0_PDATA_SIZE 32      /* packet data */
 
-/* Read the next packet */
-static gboolean iptrace_read_2_0(wtap *wth, int *err, gchar **err_info _U_,
-    long *data_offset)
+static gboolean
+iptrace_read_rec_2_0(FILE_T fh, struct wtap_pkthdr *phdr, Buffer *buf,
+    int *err, gchar **err_info)
 {
-       int                     ret;
-       guint32                 packet_size;
        guint8                  header[IPTRACE_2_0_PHDR_SIZE];
-       guint8                  *data_ptr;
        iptrace_2_0_phdr        pkt_hdr;
-       guchar                  fddi_padding[3];
+       guint32                 packet_size;
 
-       /* Read the descriptor data */
-       *data_offset = wth->data_offset;
-       ret = iptrace_read_rec_header(wth->fh, header, IPTRACE_2_0_PHDR_SIZE,
-           err);
-       if (ret <= 0) {
+       if (!wtap_read_bytes_or_eof(fh, header, sizeof header, err, err_info)) {
                /* Read error or EOF */
                return FALSE;
        }
-       wth->data_offset += IPTRACE_2_0_PHDR_SIZE;
 
        /*
         * Byte 28 of the frame header appears to be a BSD-style IFT_xxx
@@ -326,56 +307,111 @@ static gboolean iptrace_read_2_0(wtap *wth, int *err, gchar **err_info _U_,
         * <net/if_types.h> header file.
         */
        pkt_hdr.if_type = header[28];
-       wth->phdr.pkt_encap = wtap_encap_ift(pkt_hdr.if_type);
+       phdr->pkt_encap = wtap_encap_ift(pkt_hdr.if_type);
+#if 0
+       /*
+        * We used to error out if the interface type in iptrace was
+        * unknown/unhandled, but an iptrace may contain packets
+        * from a variety of interfaces, some known, and others
+        * unknown.
+        *
+        * It is better to display the data even for unknown interface
+        * types, isntead of erroring out. In the future, it would be
+        * nice to be able to flag which frames are shown as data
+        * because their interface type is unknown, and also present
+        * the interface type number to the user so that it can be
+        * reported easily back to the Wireshark developer.
+        *
+        * XXX - what types are there that are used in files but
+        * that we don't handle?
+        */
+       if (phdr->pkt_encap == WTAP_ENCAP_UNKNOWN) {
+               *err = WTAP_ERR_UNSUPPORTED;
+               *err_info = g_strdup_printf("iptrace: interface type IFT=0x%02x unknown or unsupported",
+                   pkt_hdr.if_type);
+               return FALSE;
+       }
+#endif
 
-       /* Read the packet data */
-       packet_size = pntohl(&header[0]) - IPTRACE_2_0_PDATA_SIZE;
+       /* Read the packet metadata */
+       packet_size = pntoh32(&header[0]);
+       if (packet_size < IPTRACE_2_0_PDATA_SIZE) {
+               /*
+                * Uh-oh, the record isn't big enough to even have a
+                * packet meta-data header.
+                */
+               *err = WTAP_ERR_BAD_FILE;
+               *err_info = g_strdup_printf("iptrace: file has a %u-byte record, too small to have even a packet meta-data header",
+                   packet_size);
+               return FALSE;
+       }
+       packet_size -= IPTRACE_2_0_PDATA_SIZE;
 
        /*
         * AIX appears to put 3 bytes of padding in front of FDDI
         * frames; strip that crap off.
         */
-       if (wth->phdr.pkt_encap == WTAP_ENCAP_FDDI_BITSWAPPED) {
+       if (phdr->pkt_encap == WTAP_ENCAP_FDDI_BITSWAPPED) {
                /*
                 * The packet size is really a record size and includes
                 * the padding.
                 */
+               if (packet_size < 3) {
+                       /*
+                        * Uh-oh, the record isn't big enough to even have
+                        * the padding.
+                        */
+                       *err = WTAP_ERR_BAD_FILE;
+                       *err_info = g_strdup_printf("iptrace: file has a %u-byte record, too small to have even a packet meta-data header",
+                           packet_size + IPTRACE_2_0_PDATA_SIZE);
+                       return FALSE;
+               }
                packet_size -= 3;
-               wth->data_offset += 3;
 
                /*
-                * Read the padding.
+                * Skip the padding.
                 */
-               if (!iptrace_read_rec_data(wth->fh, fddi_padding, 3, err))
-                       return FALSE;   /* Read error */
+               if (!file_skip(fh, 3, err))
+                       return FALSE;
        }
+       if (packet_size > WTAP_MAX_PACKET_SIZE) {
+               /*
+                * Probably a corrupt capture file; don't blow up trying
+                * to allocate space for an immensely-large packet.
+                */
+               *err = WTAP_ERR_BAD_FILE;
+               *err_info = g_strdup_printf("iptrace: File has %u-byte packet, bigger than maximum of %u",
+                   packet_size, WTAP_MAX_PACKET_SIZE);
+               return FALSE;
+       }
+
+       phdr->rec_type = REC_TYPE_PACKET;
+       phdr->presence_flags = WTAP_HAS_TS;
+       phdr->len = packet_size;
+       phdr->caplen = packet_size;
+       phdr->ts.secs = pntoh32(&header[32]);
+       phdr->ts.nsecs = pntoh32(&header[36]);
 
-       buffer_assure_space( wth->frame_buffer, packet_size );
-       data_ptr = buffer_start_ptr( wth->frame_buffer );
-       if (!iptrace_read_rec_data(wth->fh, data_ptr, packet_size, err))
-               return FALSE;   /* Read error */
-       wth->data_offset += packet_size;
+       /* Fill in the pseudo_header. */
+       fill_in_pseudo_header(phdr->pkt_encap, &phdr->pseudo_header, header);
 
-       /* AIX saves time in nsec, not usec. It's easier to make iptrace
-        * files more Unix-compliant here than try to get the calling
-        * program to know when to use nsec or usec */
+       /* Get the packet data */
+       return iptrace_read_rec_data(fh, buf, phdr, err, err_info);
+}
 
-       wth->phdr.len = packet_size;
-       wth->phdr.caplen = packet_size;
-       wth->phdr.ts.tv_sec = pntohl(&header[32]);
-       wth->phdr.ts.tv_usec = pntohl(&header[36]) / 1000;
+/* Read the next packet */
+static gboolean iptrace_read_2_0(wtap *wth, int *err, gchar **err_info,
+    gint64 *data_offset)
+{
+       *data_offset = file_tell(wth->fh);
 
-       if (wth->phdr.pkt_encap == WTAP_ENCAP_UNKNOWN) {
-               *err = WTAP_ERR_UNSUPPORTED_ENCAP;
-               *err_info = g_strdup_printf("iptrace: interface type IFT=0x%02x unknown or unsupported",
-                   pkt_hdr.if_type);
+       /* Read the packet */
+       if (!iptrace_read_rec_2_0(wth->fh, &wth->phdr, wth->frame_buffer,
+           err, err_info)) {
+               /* Read error or EOF */
                return FALSE;
        }
 
-       /* Fill in the pseudo-header. */
-       fill_in_pseudo_header(wth->phdr.pkt_encap, data_ptr, wth->phdr.caplen,
-           &wth->pseudo_header, header);
-
        /* If the per-file encapsulation isn't known, set it to this
           packet's encapsulation.
 
@@ -392,92 +428,36 @@ static gboolean iptrace_read_2_0(wtap *wth, int *err, gchar **err_info _U_,
        return TRUE;
 }
 
-static gboolean iptrace_seek_read_2_0(wtap *wth, long seek_off,
-    union wtap_pseudo_header *pseudo_header, guchar *pd, int packet_size,
-    int *err, gchar **err_info _U_)
+static gboolean iptrace_seek_read_2_0(wtap *wth, gint64 seek_off,
+    struct wtap_pkthdr *phdr, Buffer *buf, int *err, gchar **err_info)
 {
-       int                     ret;
-       guint8                  header[IPTRACE_2_0_PHDR_SIZE];
-       int                     pkt_encap;
-       guchar                  fddi_padding[3];
-
        if (file_seek(wth->random_fh, seek_off, SEEK_SET, err) == -1)
                return FALSE;
 
-       /* Read the descriptor data */
-       ret = iptrace_read_rec_header(wth->random_fh, header,
-           IPTRACE_2_0_PHDR_SIZE, err);
-       if (ret <= 0) {
-               /* Read error or EOF */
-               if (ret == 0) {
-                       /* EOF means "short read" in random-access mode */
+       /* Read the packet */
+       if (!iptrace_read_rec_2_0(wth->random_fh, phdr, buf, err, err_info)) {
+               if (*err == 0)
                        *err = WTAP_ERR_SHORT_READ;
-               }
                return FALSE;
        }
-
-       /*
-        * Get the interface type.
-        */
-       pkt_encap = wtap_encap_ift(header[28]);
-
-       /*
-        * AIX appears to put 3 bytes of padding in front of FDDI
-        * frames; strip that crap off.
-        */
-       if (pkt_encap == WTAP_ENCAP_FDDI_BITSWAPPED) {
-               /*
-                * Read the padding.
-                */
-               if (!iptrace_read_rec_data(wth->random_fh, fddi_padding, 3, err))
-                       return FALSE;   /* Read error */
-       }
-
-       /* Get the packet data */
-       if (!iptrace_read_rec_data(wth->random_fh, pd, packet_size, err))
-               return FALSE;
-
-       /* Fill in the pseudo-header. */
-       fill_in_pseudo_header(pkt_encap, pd, packet_size, pseudo_header,
-           header);
-
        return TRUE;
 }
 
-static int
-iptrace_read_rec_header(FILE_T fh, guint8 *header, int header_len, int *err)
-{
-       int     bytes_read;
-
-       errno = WTAP_ERR_CANT_READ;
-       bytes_read = file_read(header, 1, header_len, fh);
-       if (bytes_read != header_len) {
-               *err = file_error(fh);
-               if (*err != 0)
-                       return -1;
-               if (bytes_read != 0) {
-                       *err = WTAP_ERR_SHORT_READ;
-                       return -1;
-               }
-               return 0;
-       }
-       return 1;
-}
-
 static gboolean
-iptrace_read_rec_data(FILE_T fh, guint8 *data_ptr, int packet_size, int *err)
+iptrace_read_rec_data(FILE_T fh, Buffer *buf, struct wtap_pkthdr *phdr,
+    int *err, gchar **err_info)
 {
-       int     bytes_read;
-
-       errno = WTAP_ERR_CANT_READ;
-       bytes_read = file_read( data_ptr, 1, packet_size, fh );
-
-       if (bytes_read != packet_size) {
-               *err = file_error(fh);
-               if (*err == 0)
-                       *err = WTAP_ERR_SHORT_READ;
+       if (!wtap_read_packet_bytes(fh, buf, phdr->caplen, err, err_info))
                return FALSE;
+
+       if (phdr->pkt_encap == WTAP_ENCAP_ATM_PDUS) {
+               /*
+                * Attempt to guess from the packet data, the VPI,
+                * and the VCI information about the type of traffic.
+                */
+               atm_guess_traffic_type(phdr, ws_buffer_start_ptr(buf));
        }
+
        return TRUE;
 }
 
@@ -499,8 +479,8 @@ iptrace_read_rec_data(FILE_T fh, guint8 *data_ptr, int packet_size, int *err)
  * in some fashion what sort of traffic it is, or being told by the user.
  */
 static void
-fill_in_pseudo_header(int encap, const guint8 *pd, guint32 len,
-    union wtap_pseudo_header *pseudo_header, guint8 *header)
+fill_in_pseudo_header(int encap, union wtap_pseudo_header *pseudo_header,
+    guint8 *header)
 {
        char    if_text[9];
        char    *decimal;
@@ -516,9 +496,9 @@ fill_in_pseudo_header(int encap, const guint8 *pd, guint32 len,
                decimal = strchr(if_text, '.');
                if (decimal) {
                        *decimal = '\0';
-                       Vpi = strtoul(if_text, NULL, 10);
+                       Vpi = (int)strtoul(if_text, NULL, 10);
                        decimal++;
-                       Vci = strtoul(decimal, NULL, 10);
+                       Vci = (int)strtoul(decimal, NULL, 10);
                }
 
                /*
@@ -530,12 +510,6 @@ fill_in_pseudo_header(int encap, const guint8 *pd, guint32 len,
                pseudo_header->atm.vpi = Vpi;
                pseudo_header->atm.vci = Vci;
 
-               /*
-                * Attempt to guess from the packet data, the VPI,
-                * and the VCI information about the type of traffic.
-                */
-               atm_guess_traffic_type(pd, len, pseudo_header);
-
                /* We don't have this information */
                pseudo_header->atm.flags = 0;
                pseudo_header->atm.cells = 0;
@@ -604,6 +578,41 @@ wtap_encap_ift(unsigned int  ift)
                return ift_encap[ift];
        }
        else {
-               return WTAP_ENCAP_UNKNOWN;
+               switch(ift) {
+                       /* Infiniband*/
+                       case IPTRACE_IFT_IB:
+                               return WTAP_ENCAP_INFINIBAND;
+                               break;
+
+                       /* Host Fabric Interface */
+                       case IPTRACE_IFT_HF:
+                               /* The HFI interface on AIX provides raw IP
+                               in the packet trace. It's unclear if the HFI
+                               can be configured for any other protocol, and if
+                               any field in the iptrace header indicates what
+                               that protocol is. For now, we are hard-coding
+                               this as RAW_IP, but if we find another iptrace file
+                               using HFI that provides another protocol, we will
+                               have to figure out which field in the iptrace file
+                               encodes it. */
+                               return WTAP_ENCAP_RAW_IP;
+                               break;
+
+                       default:
+                               return WTAP_ENCAP_UNKNOWN;
+               }
        }
 }
+
+/*
+ * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
+ *
+ * Local variables:
+ * c-basic-offset: 8
+ * tab-width: 8
+ * indent-tabs-mode: t
+ * End:
+ *
+ * vi: set shiftwidth=8 tabstop=8 noexpandtab:
+ * :indentSize=8:tabSize=8:noTabs=false:
+ */