We don't use anything from <arpa/inet.h>, so we don't need to include
[obnox/wireshark/wip.git] / packet-sap.c
index 758c31925992650901e8fa87bf9f09c74006c7f3..85574f6def6a79f03f81e35fec9935920f6ad336 100644 (file)
@@ -4,10 +4,10 @@
  *
  * Heikki Vatiainen <hessu@cs.tut.fi>
  *
- * $Id: packet-sap.c,v 1.15 2000/11/19 08:54:05 guy Exp $
+ * $Id: packet-sap.c,v 1.28 2002/08/02 23:36:00 jmayer Exp $
  *
  * Ethereal - Network traffic analyzer
- * By Gerald Combs <gerald@zing.org>
+ * By Gerald Combs <gerald@ethereal.com>
  * Copyright 1998 Gerald Combs
  *
  * Copied from packet-tftp.c
 # include "config.h"
 #endif
 
-#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-ipv6.h"
 
 #define UDP_PORT_SAP   9875
@@ -135,14 +127,18 @@ dissect_sap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
         guint8 vers_flags;
         guint8 auth_len;
         guint16 tmp1;
-        guint8 *addr;
+        const guint8 *addr;
         guint8 auth_flags;
+        tvbuff_t *next_tvb;
 
         proto_item *si, *sif;
         proto_tree *sap_tree, *sap_flags_tree;
 
-       CHECK_DISPLAY_AS_DATA(proto_sap, tvb, pinfo, tree);
-
+        if (check_col(pinfo->cinfo, COL_PROTOCOL))
+                col_set_str(pinfo->cinfo, COL_PROTOCOL, "SAP");
+        if (check_col(pinfo->cinfo, COL_INFO))
+                col_clear(pinfo->cinfo, COL_INFO);
+        
        vers_flags = tvb_get_guint8(tvb, offset);
         is_ipv6 = vers_flags&MCAST_SAP_BIT_A;
         is_del = vers_flags&MCAST_SAP_BIT_T;
@@ -152,18 +148,13 @@ dissect_sap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
         sap_version = (vers_flags&MCAST_SAP_VERSION_MASK)>>MCAST_SAP_VERSION_SHIFT;
         addr_len = (is_ipv6) ? sizeof(struct e_in6_addr) : 4;
 
-       pinfo->current_proto = "SAP";
-
-        if (check_col(pinfo->fd, COL_PROTOCOL))
-                col_set_str(pinfo->fd, COL_PROTOCOL, "SAP");
-        
-        if (check_col(pinfo->fd, COL_INFO)) {
-                col_add_fstr(pinfo->fd, COL_INFO, "%s (v%u)",
+        if (check_col(pinfo->cinfo, COL_INFO)) {
+                col_add_fstr(pinfo->cinfo, COL_INFO, "%s (v%u)",
                              (is_del) ? "Deletion" : "Announcement", sap_version);
         }
 
        if (tree) {
-         si = proto_tree_add_item(tree, proto_sap, tvb, offset, END_OF_FRAME, FALSE);
+         si = proto_tree_add_item(tree, proto_sap, tvb, offset, -1, FALSE);
          sap_tree = proto_item_add_subtree(si, ett_sap);
 
          sif = proto_tree_add_uint(sap_tree, hf_sap_flags, tvb, offset, 1, vers_flags);
@@ -232,14 +223,13 @@ dissect_sap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
                   if (is_enc && is_comp) mangle = "compressed and encrypted";
                   else if (is_enc) mangle = "encrypted";
                   else mangle = "compressed";
-                  proto_tree_add_text(sap_tree, tvb, offset,
-                                      tvb_length_remaining(tvb, offset),
+                  proto_tree_add_text(sap_tree, tvb, offset, -1,
                                       "The rest of the packet is %s", mangle);
                   return;
           }
 
           /* Do we have the optional payload type aka. MIME content specifier */
-          if (!tvb_strneql(tvb, offset, "v=", strlen("v="))) {
+          if (tvb_strneql(tvb, offset, "v=", strlen("v="))) {
                   gint remaining_len;
                   guint32 pt_len;
                   int pt_string_len;
@@ -276,11 +266,12 @@ dissect_sap(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
                       tvb_get_ptr(tvb, offset, pt_string_len));
                   offset += pt_len;
           }
-          
-          /* Done with SAP */
-          call_dissector(sdp_handle, tvb, pinfo, tree);
        }
 
+        /* Done with SAP */
+        next_tvb = tvb_new_subset(tvb, offset, -1, -1);
+        call_dissector(sdp_handle, next_tvb, pinfo, tree);
+
         return;
 }
 
@@ -291,62 +282,62 @@ void proto_register_sap(void)
     { &hf_sap_flags,
       { "Flags",         "sap.flags",
        FT_UINT8, BASE_HEX, NULL, 0x0,
-       "Bits in the beginning of the SAP header" }},
+       "Bits in the beginning of the SAP header", HFILL }},
 
     { &hf_sap_flags_v,
       { "Version Number",         "sap.flags.v",
        FT_UINT8, BASE_DEC, VALS(mcast_sap_ver), MCAST_SAP_VERSION_MASK,
-       "3 bit version field in the SAP header" }},
+       "3 bit version field in the SAP header", HFILL }},
 
     { &hf_sap_flags_a,
       { "Address Type",           "sap.flags.a",
        FT_BOOLEAN, 8, TFS(&mcast_sap_address_type), MCAST_SAP_BIT_A,
-       "Originating source address type" }},
+       "Originating source address type", HFILL }},
 
     { &hf_sap_flags_r,
       { "Reserved",               "sap.flags.r",
        FT_BOOLEAN, 8, TFS(&flags_set_truth), MCAST_SAP_BIT_R,
-       "Reserved" }},
+       "Reserved", HFILL }},
 
     { &hf_sap_flags_t,
       { "Message Type",           "sap.flags.t",
        FT_BOOLEAN, 8, TFS(&mcast_sap_message_type), MCAST_SAP_BIT_T,
-       "Announcement type" }},
+       "Announcement type", HFILL }},
 
     { &hf_sap_flags_e,
       { "Encryption Bit",         "sap.flags.e",
        FT_BOOLEAN, 8, TFS(&mcast_sap_crypt_type), MCAST_SAP_BIT_E,
-       "Encryption" }},
+       "Encryption", HFILL }},
 
     { &hf_sap_flags_c,
       { "Compression Bit",         "sap.flags.c",
        FT_BOOLEAN, 8, TFS(&mcast_sap_comp_type), MCAST_SAP_BIT_C,
-       "Compression" }},
+       "Compression", HFILL }},
 
     { &hf_auth_data,
       { "Authentication data",     "sap.auth",
        FT_NONE, BASE_NONE, NULL, 0x0,
-       "Auth data" }},
+       "Auth data", HFILL }},
 
     { &hf_auth_flags,
       { "Authentication data flags", "sap.auth.flags",
        FT_UINT8, BASE_HEX, NULL, 0x0,
-       "Auth flags" }},
+       "Auth flags", HFILL }},
 
     { &hf_auth_flags_v,
       { "Version Number",         "sap.auth.flags.v",
        FT_UINT8, BASE_DEC, VALS(&mcast_sap_auth_ver), MCAST_SAP_VERSION_MASK,
-       "Version" }},
+       "Version", HFILL }},
 
     { &hf_auth_flags_p,
       { "Padding Bit",            "sap.auth.flags.p",
        FT_BOOLEAN, 8, TFS(&mcast_sap_auth_pad), MCAST_SAP_AUTH_BIT_P,
-       "Compression" }},
+       "Compression", HFILL }},
 
     { &hf_auth_flags_t,
       { "Authentication Type",         "sap.auth.flags.t",
        FT_UINT8, BASE_DEC, VALS(&mcast_sap_auth_type), MCAST_SAP_AUTH_TYPE_MASK,
-       "Auth type" }}
+       "Auth type", HFILL }}
   };
   static gint *ett[] = {
     &ett_sap,
@@ -355,7 +346,8 @@ void proto_register_sap(void)
     &ett_sap_authf,
   };
 
-  proto_sap = proto_register_protocol("Session Announcement Protocol", "sap");
+  proto_sap = proto_register_protocol("Session Announcement Protocol", "SAP",
+                                     "sap");
   proto_register_field_array(proto_sap, hf, array_length(hf));
   proto_register_subtree_array(ett, array_length(ett));
 }
@@ -363,7 +355,10 @@ void proto_register_sap(void)
 void
 proto_reg_handoff_sap(void)
 {
-  dissector_add("udp.port", UDP_PORT_SAP, dissect_sap);
+  dissector_handle_t sap_handle;
+
+  sap_handle = create_dissector_handle(dissect_sap, proto_sap);
+  dissector_add("udp.port", UDP_PORT_SAP, sap_handle);
 
   /*
    * Get a handle for the SDP dissector.