Added Guy's patch to use the pseudo header facility to pass up the Ascend
authorgerald <gerald@f5534014-38df-0310-8fa8-9805f1628bb7>
Sat, 11 Sep 1999 22:36:38 +0000 (22:36 +0000)
committergerald <gerald@f5534014-38df-0310-8fa8-9805f1628bb7>
Sat, 11 Sep 1999 22:36:38 +0000 (22:36 +0000)
metadata.

Also added filter items for the session and task number.

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

packet-ascend.c
proto.c
wiretap/ascend-grammar.y
wiretap/ascend-scanner.l
wiretap/ascend.c
wiretap/ascend.h
wiretap/wtap.h

index b1da4c2cf03f5f48f0b4e089504ada7222428982..ddd546143152058808f7775d0e44df2bc9eb908f 100644 (file)
@@ -1,7 +1,7 @@
 /* packet-ascend.c
  * Routines for decoding Lucent/Ascend packet traces
  *
- * $Id: packet-ascend.c,v 1.2 1999/09/11 06:51:28 guy Exp $
+ * $Id: packet-ascend.c,v 1.3 1999/09/11 22:36:29 gerald Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@zing.org>
 #include <string.h>
 #include "packet.h"
 
-#include "wiretap/ascend.h"
+static int proto_ascend  = -1;
+static int hf_session_id = -1;
+static int hf_task       = -1;
+
+static const value_string encaps_vals[] = {
+  {ASCEND_PFX_ETHER, "Ethernet"    },
+  {ASCEND_PFX_PPP_X, "PPP Transmit"},
+  {ASCEND_PFX_PPP_R, "PPP Receive" },
+  {0,                NULL          } };
 
 void
 dissect_ascend( const u_char *pd, frame_data *fd, proto_tree *tree ) {
   proto_tree *fh_tree;
   proto_item *ti;
-  ascend_pkthdr header;
-  static const value_string encaps_vals[] = {
-    {ASCEND_PFX_ETHER, "Ethernet"    },
-    {ASCEND_PFX_PPP_X, "PPP Transmit"},
-    {ASCEND_PFX_PPP_R, "PPP Receive" },
-    {0,                NULL          } };
-
-  memcpy(&header, pd, ASCEND_PKTHDR_OFFSET);
 
   /* load the top pane info. This should be overwritten by
      the next protocol in the stack */
@@ -64,18 +64,24 @@ dissect_ascend( const u_char *pd, frame_data *fd, proto_tree *tree ) {
   if(tree) {
     ti = proto_tree_add_text(tree, 0, 0, "Lucent/Ascend packet trace" );
     fh_tree = proto_item_add_subtree(ti, ETT_RAW);
-    proto_tree_add_text(fh_tree, 0, 0, "Link type: %s", val_to_str(header.type,
-      encaps_vals, "Unknown (%d)"));
-    proto_tree_add_text(fh_tree, 0, 0, "Username: %s", header.user);
-    proto_tree_add_text(fh_tree, 0, 0, "Session: %d", header.sess);
-    proto_tree_add_text(fh_tree, 0, 0, "Task: %08X", header.task);
+
+    /* XXX - should these be added with "proto_tree_add_item_format()"
+       (see "dissect_packet()" for an example of how to add items
+       that aren't in the packet data in that fashion) so that we
+       can filter on them? */
+    proto_tree_add_text(fh_tree, 0, 0, "Link type: %s",
+      val_to_str(fd->pseudo_header.ascend.type, encaps_vals, "Unknown (%d)"));
+    proto_tree_add_text(fh_tree, 0, 0, "Username: %s",
+      fd->pseudo_header.ascend.user);
+    proto_tree_add_item_format(fh_tree, hf_session_id, 0, 0,
+      fd->pseudo_header.ascend.sess, "Session: %d",
+      fd->pseudo_header.ascend.sess);
+    proto_tree_add_item_format(fh_tree, hf_task, 0, 0,
+      fd->pseudo_header.ascend.task, "Task: 0x%08X",
+      fd->pseudo_header.ascend.task);
   }
 
-  /* The header is metadata, so we copy the packet data to the front */
-  /* XXX Maybe we should leave it in, and mark it as metadata, so that
-     it can be filtered upon? */
-  memmove(pd, pd + ASCEND_PKTHDR_OFFSET, fd->cap_len);
-  switch (header.type) {
+  switch (fd->pseudo_header.ascend.type) {
     case ASCEND_PFX_ETHER:
       dissect_eth(pd, 0, fd, tree);
       break;
@@ -86,3 +92,18 @@ dissect_ascend( const u_char *pd, frame_data *fd, proto_tree *tree ) {
   }
 }
 
+void
+proto_register_ascend(void)
+{
+  static hf_register_info hf[] = {
+    { &hf_session_id,
+    { "Session ID",    "ascend.sess",  FT_UINT32,      NULL }},
+
+    { &hf_task,
+    { "Task",          "ascend.task",  FT_UINT32,      NULL }}
+  };
+
+  proto_ascend = proto_register_protocol("Lucent/Ascend debug output", "ascend");
+  proto_register_field_array(proto_ascend, hf, array_length(hf));
+}
+
diff --git a/proto.c b/proto.c
index 184afed38d4e043ec99c20d1345c352fcb5fd5a7..4e5e9672525d16eac859d312a3462490275fc40e 100644 (file)
--- a/proto.c
+++ b/proto.c
@@ -1,7 +1,7 @@
 /* proto.c
  * Routines for protocol tree
  *
- * $Id: proto.c,v 1.22 1999/09/11 16:41:18 deniel Exp $
+ * $Id: proto.c,v 1.23 1999/09/11 22:36:30 gerald Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@zing.org>
@@ -87,6 +87,7 @@ static int proto_register_field_init(header_field_info *hfinfo, int parent);
 /* centralization of registration functions */
 void proto_register_aarp(void);
 void proto_register_arp(void);
+void proto_register_ascend(void);
 void proto_register_atalk(void);
 void proto_register_atm(void);
 void proto_register_bootp(void);
@@ -191,6 +192,7 @@ proto_init(void)
         * just to make it easy. */
        proto_register_aarp();
        proto_register_arp();
+       proto_register_ascend();
        proto_register_atalk();
        proto_register_atm();
        proto_register_bootp();
index 07a4762281fd9916a54ec383acd7fafbd14f55bb..dc244bf9ad8283e827a2809daa3eb79bc6de1046 100644 (file)
@@ -35,7 +35,8 @@ void yyerror(char *);
 
 int bcur = 0, bcount;
 guint32 secs, usecs, caplen, wirelen;
-ascend_pkthdr header;
+ascend_pkthdr *header;
+struct ascend_phdr *pseudo_header;
 char *pkt_data;
 FILE *nfh = NULL;
 
@@ -84,10 +85,12 @@ header: prefix username sessnum KEYWORD tasknum KEYWORD timeval timeval octets K
   else
   secs = $7;
   usecs = $8;
-  /* header.user is set in ascend-scanner.l */
-  header.type = $1;
-  header.sess = $3;
-  header.task = $5;
+  if (pseudo_header != NULL) {
+    /* pseudo_header->user is set in ascend-scanner.l */
+    pseudo_header->type = $1;
+    pseudo_header->sess = $3;
+    pseudo_header->task = $5;
+  }
   
   bcur = 0;
 }
@@ -95,16 +98,17 @@ header: prefix username sessnum KEYWORD tasknum KEYWORD timeval timeval octets K
  
 byte: BYTE {
   if (bcur < caplen) {
-    pkt_data[bcur + ASCEND_PKTHDR_OFFSET] = $1;
+    pkt_data[bcur] = $1;
     bcur++;
   }
 
   if (bcur >= caplen) {
-    header.secs = secs;
-    header.usecs = usecs;
-    header.caplen = caplen;
-    header.len = wirelen;
-    memcpy(pkt_data, &header, ASCEND_PKTHDR_OFFSET);
+    if (header != NULL) {
+      header->secs = secs;
+      header->usecs = usecs;
+      header->caplen = caplen;
+      header->len = wirelen;
+    }
     YYACCEPT;
   }
 } 
@@ -160,15 +164,17 @@ init_parse_ascend()
 /* Parse the capture file.  Return the offset of the next packet, or zero
    if there is none. */
 int
-parse_ascend(FILE *fh, void *pd, int len)
+parse_ascend(FILE *fh, void *pd, struct ascend_phdr *phdr,
+               ascend_pkthdr *hdr, int len)
 {
   /* yydebug = 1; */
  
   ascend_init_lexer(fh, nfh);
   pkt_data = pd;
+  pseudo_header = phdr;
+  header = hdr;
   bcount = len;
   
-  /* Skip errors until we get something parsed. */
   if (yyparse())
     return 0;
   else
index e70f16277897cb5ec0e73d1c00ded4d763f9d595..2b7f21545bce891d3c07e73760ec647f7734061c 100644 (file)
@@ -10,7 +10,7 @@
 #include "ascend.h"
 #include "ascend-grammar.h"
 
-extern ascend_pkthdr header;
+struct ascend_phdr *pseudo_header;
 
 int at_eof;
 int mul, scratch;
@@ -57,8 +57,10 @@ EPFX "ETHER "
 
 <sc_user>[^:]+ {
   BEGIN(sc_sess);
-  strncpy(header.user, ascendtext, ASCEND_MAX_STR_LEN);
-  header.user[ASCEND_MAX_STR_LEN - 1] = '\0';
+  if (pseudo_header != NULL) {
+    strncpy(pseudo_header->user, ascendtext, ASCEND_MAX_STR_LEN);
+    pseudo_header->user[ASCEND_MAX_STR_LEN - 1] = '\0';
+  }
   return USERNAME;
 }
 
index 3ff602e35fd3389b4f99e307de2fd7608fa980d0..54efbf5425b4bbd7d317b811baeed785e7f77d9b 100644 (file)
@@ -1,6 +1,6 @@
 /* ascend.c
  *
- * $Id: ascend.c,v 1.3 1999/09/11 07:07:41 guy Exp $
+ * $Id: ascend.c,v 1.4 1999/09/11 22:36:38 gerald Exp $
  *
  * Wiretap Library
  * Copyright (c) 1998 by Gilbert Ramirez <gram@verdict.uthscsa.edu>
@@ -129,13 +129,18 @@ int ascend_open(wtap *wth, int *err)
   wth->subtype_read = ascend_read;
   wth->capture.ascend = g_malloc(sizeof(ascend_t));
 
+  /* MAXen and Pipelines report the time since reboot.  In order to keep 
+     from reporting packet times near the epoch, we subtract the first
+     packet's timestamp from the capture file's ctime, which gives us an
+     offset that we can apply to each packet.
+   */
   fstat(fileno(wth->fh), &statbuf);
   wth->capture.ascend->inittime = statbuf.st_ctime;
   wth->capture.ascend->adjusted = 0;
   wth->capture.ascend->seek_add = -1;
 
   init_parse_ascend();
-  
+
   return 1;
 }
 
@@ -157,15 +162,13 @@ static int ascend_read(wtap *wth, int *err)
   if (offset < 1) {
     return 0;
   }
-  if (! parse_ascend(wth->fh, buf, 0)) {
+  if (! parse_ascend(wth->fh, buf, &wth->phdr.pseudo_header.ascend, &header, 0)) {
     *err = WTAP_ERR_BAD_RECORD;
     return -1;
   }
 
-  buffer_assure_space(wth->frame_buffer, wth->snapshot_length +
-    ASCEND_PKTHDR_OFFSET);
+  buffer_assure_space(wth->frame_buffer, wth->snapshot_length);
 
-  memcpy(&header, buf, ASCEND_PKTHDR_OFFSET);
   if (! wth->capture.ascend->adjusted) {
     wth->capture.ascend->adjusted = 1;
     if (wth->capture.ascend->inittime > header.secs)
@@ -177,12 +180,12 @@ static int ascend_read(wtap *wth, int *err)
   wth->phdr.len = header.len;
   wth->phdr.pkt_encap = wth->file_encap;
   wth->data_offset = offset;
-  
+
   return offset;
 }
 
 int ascend_seek_read (FILE *fh, int seek_off, guint8 *pd, int len)
 {
   fseek(fh, seek_off - 1, SEEK_SET);
-  return parse_ascend(fh, pd, len);
+  return parse_ascend(fh, pd, NULL, NULL, len);
 }
index fb7accd6de5806e119999e6d8ddc240f41a51c64..c9db11ae1d01ef89db50dda65674ee6816abf1b1 100644 (file)
@@ -1,6 +1,6 @@
 /* ascend.h
  *
- * $Id: ascend.h,v 1.2 1999/09/11 06:49:42 guy Exp $
+ * $Id: ascend.h,v 1.3 1999/09/11 22:36:38 gerald Exp $
  *
  * Wiretap Library
  * Copyright (c) 1998 by Gilbert Ramirez <gram@verdict.uthscsa.edu>
  *
  */
 
-#define ASCEND_MAX_STR_LEN 64
 #define ASCEND_MAX_DATA_ROWS 8
 #define ASCEND_MAX_DATA_COLS 16
 #define ASCEND_MAX_PKT_LEN (ASCEND_MAX_DATA_ROWS * ASCEND_MAX_DATA_COLS)
 
-#define ASCEND_PFX_ETHER 1
-#define ASCEND_PFX_PPP_X 2
-#define ASCEND_PFX_PPP_R 3
-
 typedef struct {
-  guint16 type;                       /* ASCEND_PFX_*, as defined above */
-  char    user[ASCEND_MAX_STR_LEN];   /* Username, from header */
-  guint32 sess;                       /* Session number */
-  guint32 task;                       /* Task number */
-  guint32 secs;
-  guint32 usecs;
+  time_t secs;
+  time_t usecs;
   guint32 caplen;
   guint32 len;
 } ascend_pkthdr;
 
-#define ASCEND_PKTHDR_OFFSET sizeof(ascend_pkthdr)
-
 int ascend_open(wtap *wth, int *err);
 void init_parse_ascend();
-int parse_ascend(FILE *fh, void *pd, int len);
+int parse_ascend(FILE *fh, void *pd, struct ascend_phdr *phdr,
+               ascend_pkthdr *hdr, int len);
 int ascend_seek_read (FILE *fh, int seek_off, guint8 *pd, int len);
index 10bb64db5a2d6656117ea138061daabd34b41624..6f46121182dfb3a84e523865f42aa1adb8c2f889 100644 (file)
@@ -1,6 +1,6 @@
 /* wtap.h
  *
- * $Id: wtap.h,v 1.36 1999/09/11 04:50:44 gerald Exp $
+ * $Id: wtap.h,v 1.37 1999/09/11 22:36:38 gerald Exp $
  *
  * Wiretap Library
  * Copyright (c) 1998 by Gilbert Ramirez <gram@verdict.uthscsa.edu>
@@ -189,6 +189,22 @@ struct ngsniffer_atm_phdr {
        guint32 aal5t_chksum;   /* checksum for AAL5 packet */
 };
 
+/* Packet "pseudo-header" for the output from "wandsession", "wannext",
+   "wandisplay", and similar commands on Lucent/Ascend access equipment. */
+
+#define ASCEND_MAX_STR_LEN 64
+
+#define ASCEND_PFX_ETHER 1
+#define ASCEND_PFX_PPP_X 2
+#define ASCEND_PFX_PPP_R 3
+
+struct ascend_phdr {
+       guint16 type;                   /* ASCEND_PFX_*, as defined above */
+       char    user[ASCEND_MAX_STR_LEN];   /* Username, from header */
+       guint32 sess;                   /* Session number */
+       guint32 task;                   /* Task number */
+};
+
 /*
  * Bits in AppTrafType.
  *
@@ -244,6 +260,7 @@ struct ngsniffer_atm_phdr {
 union pseudo_header {
        struct x25_phdr x25;
        struct ngsniffer_atm_phdr ngsniffer_atm;
+       struct ascend_phdr ascend;
 };
 
 struct wtap_pkthdr {