From Martin Regner: fix dissection of non-standard parameters.
[obnox/wireshark/wip.git] / packet-ipsec.c
index 870bc528a79b671ea5311326afdb73717aada3d9..a246ae242c4e0913b1cf1254be14647d0aff4b29 100644 (file)
@@ -1,22 +1,22 @@
 /* packet-ipsec.c
- * Routines for IPsec/IPComp packet disassembly 
+ * Routines for IPsec/IPComp packet disassembly
  *
- * $Id: packet-ipsec.c,v 1.37 2002/01/21 07:36:35 guy Exp $
+ * $Id: packet-ipsec.c,v 1.44 2003/08/16 00:11:07 gerald Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
  * Copyright 1998 Gerald Combs
- * 
+ *
  * This program is free software; you can redistribute it and/or
  * modify it under the terms of the GNU General Public License
  * as published by the Free Software Foundation; either version 2
  * of the License, or (at your option) any later version.
- * 
+ *
  * This program is distributed in the hope that it will be useful,
  * but WITHOUT ANY WARRANTY; without even the implied warranty of
  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
  * GNU General Public License for more details.
- * 
+ *
  * 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.
 
 #include <stdio.h>
 
-#ifdef HAVE_SYS_TYPES_H
-# include <sys/types.h>
-#endif
-
-#ifdef HAVE_NETINET_IN_H
-# include <netinet/in.h>
-#endif
-
 #include <string.h>
 #include <glib.h>
 #include <epan/packet.h>
 #include "packet-ipsec.h"
-#include "packet-ip.h"
 #include <epan/resolv.h>
 #include "ipproto.h"
 #include "prefs.h"
 
 /* Place AH payload in sub tree */
-gboolean g_ah_payload_in_subtree = FALSE;
+static gboolean g_ah_payload_in_subtree = FALSE;
 
 static int proto_ah = -1;
 static int hf_ah_spi = -1;
@@ -64,6 +55,8 @@ static gint ett_ipcomp = -1;
 
 static dissector_handle_t data_handle;
 
+static dissector_table_t ip_dissector_table;
+
 struct newah {
        guint8  ah_nxt;         /* Next Header */
        guint8  ah_len;         /* Length of data + 1, in 32bit */
@@ -142,12 +135,12 @@ dissect_ah_header(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
     if (check_col(pinfo->cinfo, COL_INFO))
        col_clear(pinfo->cinfo, COL_INFO);
 
-    tvb_memcpy(tvb, (guint8 *)&ah, 0, sizeof(ah)); 
+    tvb_memcpy(tvb, (guint8 *)&ah, 0, sizeof(ah));
     advance = sizeof(ah) + ((ah.ah_len - 1) << 2);
 
     if (check_col(pinfo->cinfo, COL_INFO)) {
        col_add_fstr(pinfo->cinfo, COL_INFO, "AH (SPI=0x%08x)",
-           (guint32)ntohl(ah.ah_spi));
+           (guint32)g_ntohl(ah.ah_spi));
     }
 
     if (tree) {
@@ -164,10 +157,10 @@ dissect_ah_header(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
                            "Length: %u", (ah.ah_len + 2) << 2);
        proto_tree_add_uint(ah_tree, hf_ah_spi, tvb,
                            offsetof(struct newah, ah_spi), 4,
-                           (guint32)ntohl(ah.ah_spi));
+                           (guint32)g_ntohl(ah.ah_spi));
        proto_tree_add_uint(ah_tree, hf_ah_sequence, tvb,
                            offsetof(struct newah, ah_seq), 4,
-                           (guint32)ntohl(ah.ah_seq));
+                           (guint32)g_ntohl(ah.ah_seq));
        proto_tree_add_text(ah_tree, tvb,
                            sizeof(ah), (ah.ah_len - 1) << 2,
                            "ICV");
@@ -209,11 +202,11 @@ dissect_esp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
     if (check_col(pinfo->cinfo, COL_INFO))
        col_clear(pinfo->cinfo, COL_INFO);
 
-    tvb_memcpy(tvb, (guint8 *)&esp, 0, sizeof(esp)); 
+    tvb_memcpy(tvb, (guint8 *)&esp, 0, sizeof(esp));
 
     if (check_col(pinfo->cinfo, COL_INFO)) {
        col_add_fstr(pinfo->cinfo, COL_INFO, "ESP (SPI=0x%08x)",
-           (guint32)ntohl(esp.esp_spi));
+           (guint32)g_ntohl(esp.esp_spi));
     }
 
     /*
@@ -221,16 +214,17 @@ dissect_esp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
      * (ie none)
      */
     if(tree) {
-       ti = proto_tree_add_item(tree, proto_esp, tvb, 0,
-                                tvb_length(tvb), FALSE);
+       ti = proto_tree_add_item(tree, proto_esp, tvb, 0, -1, FALSE);
        esp_tree = proto_item_add_subtree(ti, ett_esp);
-       proto_tree_add_uint(esp_tree, hf_esp_spi, tvb, 
+       proto_tree_add_uint(esp_tree, hf_esp_spi, tvb,
                            offsetof(struct newesp, esp_spi), 4,
-                           (guint32)ntohl(esp.esp_spi));
+                           (guint32)g_ntohl(esp.esp_spi));
        proto_tree_add_uint(esp_tree, hf_esp_sequence, tvb,
                            offsetof(struct newesp, esp_seq), 4,
-                           (guint32)ntohl(esp.esp_seq));
-       call_dissector(data_handle,tvb_new_subset(tvb, sizeof(struct newesp),-1,tvb_reported_length_remaining(tvb,sizeof(struct newesp))), pinfo, esp_tree);
+                           (guint32)g_ntohl(esp.esp_seq));
+       call_dissector(data_handle,
+           tvb_new_subset(tvb, sizeof(struct newesp), -1, -1),
+           pinfo, esp_tree);
     }
 }
 
@@ -251,13 +245,13 @@ dissect_ipcomp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
     if (check_col(pinfo->cinfo, COL_INFO))
        col_clear(pinfo->cinfo, COL_INFO);
 
-    tvb_memcpy(tvb, (guint8 *)&ipcomp, 0, sizeof(ipcomp)); 
+    tvb_memcpy(tvb, (guint8 *)&ipcomp, 0, sizeof(ipcomp));
 
     if (check_col(pinfo->cinfo, COL_INFO)) {
-       p = match_strval(ntohs(ipcomp.comp_cpi), cpi2val);
+       p = match_strval(g_ntohs(ipcomp.comp_cpi), cpi2val);
        if (p == NULL) {
            col_add_fstr(pinfo->cinfo, COL_INFO, "IPComp (CPI=0x%04x)",
-               ntohs(ipcomp.comp_cpi));
+               g_ntohs(ipcomp.comp_cpi));
        } else
            col_add_fstr(pinfo->cinfo, COL_INFO, "IPComp (CPI=%s)", p);
     }
@@ -267,8 +261,7 @@ dissect_ipcomp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
      * (ie none)
      */
     if (tree) {
-       ti = proto_tree_add_item(tree, proto_ipcomp, tvb, 0,
-           tvb_length(tvb), FALSE);
+       ti = proto_tree_add_item(tree, proto_ipcomp, tvb, 0, -1, FALSE);
        ipcomp_tree = proto_item_add_subtree(ti, ett_ipcomp);
 
        proto_tree_add_text(ipcomp_tree, tvb,
@@ -278,10 +271,12 @@ dissect_ipcomp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
        proto_tree_add_uint(ipcomp_tree, hf_ipcomp_flags, tvb,
            offsetof(struct ipcomp, comp_flags), 1,
            ipcomp.comp_flags);
-       proto_tree_add_uint(ipcomp_tree, hf_ipcomp_cpi, tvb, 
+       proto_tree_add_uint(ipcomp_tree, hf_ipcomp_cpi, tvb,
            offsetof(struct ipcomp, comp_cpi), 2,
-           ntohs(ipcomp.comp_cpi));
-       call_dissector(data_handle,tvb_new_subset(tvb, sizeof(struct ipcomp), -1,tvb_reported_length_remaining(tvb,sizeof(struct ipcomp))),pinfo, ipcomp_tree);
+           g_ntohs(ipcomp.comp_cpi));
+       call_dissector(data_handle,
+           tvb_new_subset(tvb, sizeof(struct ipcomp), -1, -1), pinfo,
+           ipcomp_tree);
     }
 }
 
@@ -294,7 +289,7 @@ proto_register_ipsec(void)
       { "SPI",         "ah.spi",       FT_UINT32,      BASE_HEX, NULL, 0x0,
        "", HFILL }},
     { &hf_ah_sequence,
-      { "Sequence",     "ah.sequence", FT_UINT32,      BASE_HEX, NULL, 0x0,
+      { "Sequence",     "ah.sequence", FT_UINT32,      BASE_DEC, NULL, 0x0,
        "", HFILL }}
   };
 
@@ -303,7 +298,7 @@ proto_register_ipsec(void)
       { "SPI",         "esp.spi",      FT_UINT32,      BASE_HEX, NULL, 0x0,
        "", HFILL }},
     { &hf_esp_sequence,
-      { "Sequence",     "esp.sequence",        FT_UINT32,      BASE_HEX, NULL, 0x0,
+      { "Sequence",     "esp.sequence",        FT_UINT32,      BASE_DEC, NULL, 0x0,
        "", HFILL }}
   };
 
@@ -312,7 +307,7 @@ proto_register_ipsec(void)
       { "Flags",       "ipcomp.flags", FT_UINT8,       BASE_HEX, NULL, 0x0,
        "", HFILL }},
     { &hf_ipcomp_cpi,
-      { "CPI",         "ipcomp.cpi",   FT_UINT16,      BASE_HEX, 
+      { "CPI",         "ipcomp.cpi",   FT_UINT16,      BASE_HEX,
         VALS(cpi2val), 0x0,            "", HFILL }},
   };
   static gint *ett[] = {
@@ -359,4 +354,6 @@ proto_reg_handoff_ipsec(void)
   dissector_add("ip.proto", IP_PROTO_ESP, esp_handle);
   ipcomp_handle = create_dissector_handle(dissect_ipcomp, proto_ipcomp);
   dissector_add("ip.proto", IP_PROTO_IPCOMP, ipcomp_handle);
+
+  ip_dissector_table = find_dissector_table("ip.proto");
 }