Ethereal-dev: [Ethereal-dev] nettl (HP-UX) changes for FDDI & Token Ring

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: "Mark C. Brown" <mbrown@xxxxxxxxxx>
Date: Thu, 01 Apr 2004 17:21:52 -0500
Greetings,

nettl (HP-UX) changes to add the following interfaces:

fddi4  - PCI FDDI
pcitr  - PCI Token Ring
token2 - PB Token Ring

Mark

-- 
"If a train station is where a train stops, | Mark C. Brown
 then what's a workstation?" -- D. Huber    | mbrown@xxxxxxxxxx
Index: wiretap/nettl.h
===================================================================
RCS file: /cvsroot/ethereal/wiretap/nettl.h,v
retrieving revision 1.11
diff -u -r1.11 nettl.h
--- wiretap/nettl.h	27 Mar 2004 11:16:54 -0000	1.11
+++ wiretap/nettl.h	1 Apr 2004 22:00:24 -0000
@@ -80,6 +80,13 @@
 #define NETTL_SUBSYS_IGELAN		0xFC
 #define NETTL_SUBSYS_IETHER		0xFD
 
+/* FDDI cards */
+#define NETTL_SUBSYS_PCI_FDDI		0xB0
+                                                                                
+/* TOKEN RING cards */
+#define NETTL_SUBSYS_TOKEN		0x1F
+#define NETTL_SUBSYS_PCI_TR		0xBB
+
 
 int nettl_open(wtap *wth, int *err, gchar **err_info);
 
Index: wiretap/nettl.c
===================================================================
RCS file: /cvsroot/ethereal/wiretap/nettl.c,v
retrieving revision 1.35
diff -u -r1.35 nettl.c
--- wiretap/nettl.c	27 Mar 2004 11:16:53 -0000	1.35
+++ wiretap/nettl.c	1 Apr 2004 22:00:25 -0000
@@ -280,6 +280,9 @@
 	case NETTL_SUBSYS_INTL100 :
 	case NETTL_SUBSYS_IGELAN :
 	case NETTL_SUBSYS_IETHER :
+        case NETTL_SUBSYS_PCI_FDDI :
+        case NETTL_SUBSYS_TOKEN :
+        case NETTL_SUBSYS_PCI_TR :
 	case NETTL_SUBSYS_NS_LS_IP :
 	case NETTL_SUBSYS_NS_LS_LOOPBACK :
 	case NETTL_SUBSYS_NS_LS_TCP :
@@ -292,6 +295,17 @@
 		phdr->pkt_encap = WTAP_ENCAP_RAW_IP;
 	    } else if (encap[3] == NETTL_SUBSYS_NS_LS_ICMP) {
 		phdr->pkt_encap = WTAP_ENCAP_UNKNOWN;
+            } else if (encap[3] == NETTL_SUBSYS_PCI_FDDI) {
+                wth->file_encap = WTAP_ENCAP_FDDI;
+                phdr->pkt_encap = WTAP_ENCAP_FDDI;
+                /* We assume there's no FCS in this frame. */
+                pseudo_header->eth.fcs_len = 0;
+            } else if( (encap[3] == NETTL_SUBSYS_PCI_TR)
+	           ||  (encap[3] == NETTL_SUBSYS_TOKEN) ){
+                wth->file_encap = WTAP_ENCAP_TOKEN_RING;
+                phdr->pkt_encap = WTAP_ENCAP_TOKEN_RING;
+                /* We assume there's no FCS in this frame. */
+                pseudo_header->eth.fcs_len = 0;
 	    } else {
 		wth->file_encap = WTAP_ENCAP_ETHERNET;
 		phdr->pkt_encap = WTAP_ENCAP_ETHERNET;
@@ -329,12 +343,32 @@
 		offset += 4;
 	    }
 
-	    length = pntohl(&ip_hdr.length);
-	    if (length <= 0) return 0;
-	    phdr->len = length;
-	    length = pntohl(&ip_hdr.caplen);
-	    phdr->caplen = length;
-
+            /* PCI FDDI has an extra 3 bytes of padding */
+            if (encap[3] == NETTL_SUBSYS_PCI_FDDI) {
+                bytes_read = file_read(dummy, 1, 3, fh);
+                if (bytes_read != 3) {
+                    *err = file_error(fh);
+                    if (*err != 0)
+                        return -1;
+                    if (bytes_read != 0) {
+                        *err = WTAP_ERR_SHORT_READ;
+                        return -1;
+                    }
+                    return 0;
+                }
+                offset += 3;
+                length = pntohl(&ip_hdr.length);
+                if (length <= 0) return 0;
+                phdr->len = length - 3;
+                length = pntohl(&ip_hdr.caplen);
+                phdr->caplen = length - 3;
+            } else {
+                length = pntohl(&ip_hdr.length);
+                if (length <= 0) return 0;
+                phdr->len = length;                                             
+                length = pntohl(&ip_hdr.caplen);
+                phdr->caplen = length;
+            }
 
 	    phdr->ts.tv_sec = pntohl(&ip_hdr.sec);
 	    phdr->ts.tv_usec = pntohl(&ip_hdr.usec);