Removed trailing whitespaces from .h and .c files using the
[obnox/wireshark/wip.git] / packet-ipsec.c
index 7a89465b3b63f4033de55da8109b158ca99fe067..f919bb334d8de72ea76b71726652516b59bc56cc 100644 (file)
@@ -1,7 +1,7 @@
 /* packet-ipsec.c
  * Routines for IPsec/IPComp packet disassembly 
  *
- * $Id: packet-ipsec.c,v 1.33 2001/11/09 08:16:24 guy Exp $
+ * $Id: packet-ipsec.c,v 1.41 2002/08/02 23:35:51 jmayer Exp $
  *
  * Ethereal - Network traffic analyzer
  * By Gerald Combs <gerald@ethereal.com>
 
 #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 "packet.h"
+#include <epan/packet.h>
 #include "packet-ipsec.h"
 #include "packet-ip.h"
-#include "resolv.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;
@@ -62,6 +54,8 @@ static gint ett_ah = -1;
 static gint ett_esp = -1;
 static gint ett_ipcomp = -1;
 
+static dissector_handle_t data_handle;
+
 struct newah {
        guint8  ah_nxt;         /* Next Header */
        guint8  ah_len;         /* Length of data + 1, in 32bit */
@@ -117,12 +111,12 @@ dissect_ah(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
     next_tvb = tvb_new_subset(tvb, advance, -1, -1);
 
     if (g_ah_payload_in_subtree) {
-       col_set_writable(pinfo->fd, FALSE);
+       col_set_writable(pinfo->cinfo, FALSE);
     }
 
     /* do lookup with the subdissector table */
     if (!dissector_try_port(ip_dissector_table, nxt, next_tvb, pinfo, next_tree)) {
-      dissect_data(next_tvb, 0, pinfo, next_tree);
+      call_dissector(data_handle,next_tvb, pinfo, next_tree);
     }
 }
 
@@ -135,17 +129,17 @@ dissect_ah_header(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree,
     struct newah ah;
     int advance;
 
-    if (check_col(pinfo->fd, COL_PROTOCOL))
-       col_set_str(pinfo->fd, COL_PROTOCOL, "AH");
-    if (check_col(pinfo->fd, COL_INFO))
-       col_clear(pinfo->fd, COL_INFO);
+    if (check_col(pinfo->cinfo, COL_PROTOCOL))
+       col_set_str(pinfo->cinfo, COL_PROTOCOL, "AH");
+    if (check_col(pinfo->cinfo, COL_INFO))
+       col_clear(pinfo->cinfo, COL_INFO);
 
     tvb_memcpy(tvb, (guint8 *)&ah, 0, sizeof(ah)); 
     advance = sizeof(ah) + ((ah.ah_len - 1) << 2);
 
-    if (check_col(pinfo->fd, COL_INFO)) {
-       col_add_fstr(pinfo->fd, COL_INFO, "AH (SPI=0x%08x)",
-           (guint32)ntohl(ah.ah_spi));
+    if (check_col(pinfo->cinfo, COL_INFO)) {
+       col_add_fstr(pinfo->cinfo, COL_INFO, "AH (SPI=0x%08x)",
+           (guint32)g_ntohl(ah.ah_spi));
     }
 
     if (tree) {
@@ -162,10 +156,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");
@@ -202,16 +196,16 @@ dissect_esp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
      * load the top pane info. This should be overwritten by
      * the next protocol in the stack
      */
-    if (check_col(pinfo->fd, COL_PROTOCOL))
-       col_set_str(pinfo->fd, COL_PROTOCOL, "ESP");
-    if (check_col(pinfo->fd, COL_INFO))
-       col_clear(pinfo->fd, COL_INFO);
+    if (check_col(pinfo->cinfo, COL_PROTOCOL))
+       col_set_str(pinfo->cinfo, COL_PROTOCOL, "ESP");
+    if (check_col(pinfo->cinfo, COL_INFO))
+       col_clear(pinfo->cinfo, COL_INFO);
 
     tvb_memcpy(tvb, (guint8 *)&esp, 0, sizeof(esp)); 
 
-    if (check_col(pinfo->fd, COL_INFO)) {
-       col_add_fstr(pinfo->fd, COL_INFO, "ESP (SPI=0x%08x)",
-           (guint32)ntohl(esp.esp_spi));
+    if (check_col(pinfo->cinfo, COL_INFO)) {
+       col_add_fstr(pinfo->cinfo, COL_INFO, "ESP (SPI=0x%08x)",
+           (guint32)g_ntohl(esp.esp_spi));
     }
 
     /*
@@ -219,16 +213,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, 
                            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));
-       dissect_data(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);
     }
 }
 
@@ -244,20 +239,20 @@ dissect_ipcomp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
      * load the top pane info. This should be overwritten by
      * the next protocol in the stack
      */
-    if (check_col(pinfo->fd, COL_PROTOCOL))
-       col_set_str(pinfo->fd, COL_PROTOCOL, "IPComp");
-    if (check_col(pinfo->fd, COL_INFO))
-       col_clear(pinfo->fd, COL_INFO);
+    if (check_col(pinfo->cinfo, COL_PROTOCOL))
+       col_set_str(pinfo->cinfo, COL_PROTOCOL, "IPComp");
+    if (check_col(pinfo->cinfo, COL_INFO))
+       col_clear(pinfo->cinfo, COL_INFO);
 
     tvb_memcpy(tvb, (guint8 *)&ipcomp, 0, sizeof(ipcomp)); 
 
-    if (check_col(pinfo->fd, COL_INFO)) {
-       p = match_strval(ntohs(ipcomp.comp_cpi), cpi2val);
+    if (check_col(pinfo->cinfo, COL_INFO)) {
+       p = match_strval(g_ntohs(ipcomp.comp_cpi), cpi2val);
        if (p == NULL) {
-           col_add_fstr(pinfo->fd, COL_INFO, "IPComp (CPI=0x%04x)",
-               ntohs(ipcomp.comp_cpi));
+           col_add_fstr(pinfo->cinfo, COL_INFO, "IPComp (CPI=0x%04x)",
+               g_ntohs(ipcomp.comp_cpi));
        } else
-           col_add_fstr(pinfo->fd, COL_INFO, "IPComp (CPI=%s)", p);
+           col_add_fstr(pinfo->cinfo, COL_INFO, "IPComp (CPI=%s)", p);
     }
 
     /*
@@ -265,8 +260,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,8 +272,10 @@ dissect_ipcomp(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
            ipcomp.comp_flags);
        proto_tree_add_uint(ipcomp_tree, hf_ipcomp_cpi, tvb, 
            offsetof(struct ipcomp, comp_cpi), 2,
-           ntohs(ipcomp.comp_cpi));
-       dissect_data(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);
     }
 }
 
@@ -348,7 +344,13 @@ proto_register_ipsec(void)
 void
 proto_reg_handoff_ipsec(void)
 {
-  dissector_add("ip.proto", IP_PROTO_AH, dissect_ah, proto_ah);
-  dissector_add("ip.proto", IP_PROTO_ESP, dissect_esp, proto_esp);
-  dissector_add("ip.proto", IP_PROTO_IPCOMP, dissect_ipcomp, proto_ipcomp);
+  dissector_handle_t esp_handle, ah_handle, ipcomp_handle;
+
+  data_handle = find_dissector("data");
+  ah_handle = find_dissector("ah");
+  dissector_add("ip.proto", IP_PROTO_AH, ah_handle);
+  esp_handle = find_dissector("esp");
+  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);
 }