Use MAC address documentation range in filter examples
[metze/wireshark/wip.git] / epan / dissectors / packet-wow.c
index 6b71ec0b0f14f459fec809038d0bf6d714293966..766de88930d3c83a55391ebcb3c53feb66dc7b96 100644 (file)
@@ -2,8 +2,6 @@
  * Routines for World of Warcraft (WoW) protocol dissection
  * Copyright 2008-2009, Stephen Fisher (see AUTHORS file)
  *
- * $Id$
- *
  * Wireshark - Network traffic analyzer
  * By Gerald Combs <gerald@wireshark.org>
  * Copyright 1998 Gerald Combs
 
 #include "config.h"
 
-#include <glib.h>
-
 #include <epan/packet.h>
 #include <epan/prefs.h>
 #include "packet-tcp.h"
 
+void proto_register_wow(void);
+void proto_reg_handoff_wow(void);
+
 typedef enum {
        AUTH_LOGON_CHALLENGE = 0x00,
        AUTH_LOGON_PROOF     = 0x01,
@@ -59,6 +58,7 @@ static const value_string cmd_vs[] = {
        { 0, NULL                                                }
 };
 
+#if 0
 static const value_string account_type_vs[] = {
        { 0, "Player"        },
        { 1, "Moderator"     },
@@ -66,6 +66,7 @@ static const value_string account_type_vs[] = {
        { 3, "Administrator" },
        { 0, NULL            }
 };
+#endif
 
 static const value_string realm_status_vs[] = {
        { 0, "Online"  },
@@ -136,39 +137,8 @@ static gboolean wow_preference_desegment = TRUE;
 static gint ett_wow = -1;
 static gint ett_wow_realms = -1;
 
-static void dissect_wow_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree);
-static guint get_wow_pdu_len(packet_info *pinfo, tvbuff_t *tvb, int offset);
-
-
-static gboolean
-dissect_wow(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data _U_)
-{
-       gint8 size_field_offset = -1;
-       guint8 cmd;
-
-       cmd = tvb_get_guint8(tvb, 0);
-
-       if(WOW_SERVER_TO_CLIENT && cmd == REALM_LIST)
-               size_field_offset = 1;
-       if(WOW_CLIENT_TO_SERVER && cmd == AUTH_LOGON_CHALLENGE)
-               size_field_offset = 2;
-
-       if(size_field_offset > -1) {
-               tcp_dissect_pdus(tvb, pinfo, tree, wow_preference_desegment,
-                                size_field_offset+2, get_wow_pdu_len,
-                                dissect_wow_pdu);
-
-       } else {
-               /* Doesn't have a size field, so it cannot span multiple
-                  segments.  Therefore, dissect this packet normally. */
-               dissect_wow_pdu(tvb, pinfo, tree);
-       }
-
-       return TRUE;
-}
-
 static guint
-get_wow_pdu_len(packet_info *pinfo, tvbuff_t *tvb, int offset)
+get_wow_pdu_len(packet_info *pinfo, tvbuff_t *tvb, int offset, void *data _U_)
 {
        gint8 size_field_offset = -1;
        guint8 cmd;
@@ -187,8 +157,8 @@ get_wow_pdu_len(packet_info *pinfo, tvbuff_t *tvb, int offset)
 }
 
 
-static void
-dissect_wow_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
+static int
+dissect_wow_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void* data _U_)
 {
        proto_item *ti;
        proto_tree *wow_tree, *wow_realms_tree;
@@ -230,7 +200,7 @@ dissect_wow_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
                                                    tvb, offset, 2, ENC_LITTLE_ENDIAN);
                                offset += 2;
 
-                               string = g_strreverse(tvb_get_ephemeral_string(tvb, offset, 4));
+                               string = g_strreverse(tvb_get_string_enc(wmem_packet_scope(), tvb, offset, 4, ENC_ASCII));
                                proto_tree_add_string(wow_tree, hf_wow_gamename,
                                                      tvb, offset, 4, string);
                                offset += 4;
@@ -251,17 +221,17 @@ dissect_wow_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
                                                    offset, 2, ENC_LITTLE_ENDIAN);
                                offset += 2;
 
-                               string = g_strreverse(tvb_get_ephemeral_string(tvb, offset, 4));
+                               string = g_strreverse(tvb_get_string_enc(wmem_packet_scope(), tvb, offset, 4, ENC_ASCII));
                                proto_tree_add_string(wow_tree, hf_wow_platform,
                                                      tvb, offset, 4, string);
                                offset += 4;
 
-                               string = g_strreverse(tvb_get_ephemeral_string(tvb, offset, 4));
+                               string = g_strreverse(tvb_get_string_enc(wmem_packet_scope(), tvb, offset, 4, ENC_ASCII));
                                proto_tree_add_string(wow_tree, hf_wow_os, tvb,
                                                      offset, 4, string);
                                offset += 4;
 
-                               string = g_strreverse(tvb_get_ephemeral_string(tvb, offset, 4));
+                               string = g_strreverse(tvb_get_string_enc(wmem_packet_scope(), tvb, offset, 4, ENC_ASCII));
                                proto_tree_add_string(wow_tree, hf_wow_country,
                                                      tvb, offset, 4, string);
                                offset += 4;
@@ -382,16 +352,15 @@ dissect_wow_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
                                offset += 2;
 
                                for(ii = 0; ii < num_realms; ii++) {
-                                       realm_name = tvb_get_ephemeral_stringz(tvb,
+                                       realm_name = tvb_get_stringz_enc(wmem_packet_scope(), tvb,
                                                                     offset + 3,
-                                                                    &len);
+                                                                    &len, ENC_ASCII);
 
-                                       ti = proto_tree_add_text(wow_tree, tvb,
+                                       wow_realms_tree = proto_tree_add_subtree(wow_tree, tvb,
                                                                 offset, 0,
-                                                                "%s",
+                                                                ett_wow_realms, NULL,
                                                                 realm_name);
 
-                                       wow_realms_tree = proto_item_add_subtree(ti, ett_wow_realms);
                                        proto_tree_add_item(wow_realms_tree, hf_wow_realm_type, tvb, offset, 1, ENC_LITTLE_ENDIAN);
                                        offset += 1;
 
@@ -404,8 +373,8 @@ dissect_wow_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
                                        proto_tree_add_string(wow_realms_tree, hf_wow_realm_name, tvb, offset, len, realm_name);
                                        offset += len;
 
-                                       string = tvb_get_ephemeral_stringz(tvb, offset,
-                                                                &len);
+                                       string = tvb_get_stringz_enc(wmem_packet_scope(), tvb, offset,
+                                                                &len, ENC_ASCII);
                                        proto_tree_add_string(wow_realms_tree, hf_wow_realm_socket, tvb, offset, len, string);
                                        offset += len;
 
@@ -425,6 +394,35 @@ dissect_wow_pdu(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree)
                        }
                }
        }
+
+       return tvb_captured_length(tvb);
+}
+
+static gboolean
+dissect_wow(tvbuff_t *tvb, packet_info *pinfo, proto_tree *tree, void *data)
+{
+       gint8 size_field_offset = -1;
+       guint8 cmd;
+
+       cmd = tvb_get_guint8(tvb, 0);
+
+       if(WOW_SERVER_TO_CLIENT && cmd == REALM_LIST)
+               size_field_offset = 1;
+       if(WOW_CLIENT_TO_SERVER && cmd == AUTH_LOGON_CHALLENGE)
+               size_field_offset = 2;
+
+       if(size_field_offset > -1) {
+               tcp_dissect_pdus(tvb, pinfo, tree, wow_preference_desegment,
+                                size_field_offset+2, get_wow_pdu_len,
+                                dissect_wow_pdu, data);
+
+       } else {
+               /* Doesn't have a size field, so it cannot span multiple
+                  segments.  Therefore, dissect this packet normally. */
+               dissect_wow_pdu(tvb, pinfo, tree, data);
+       }
+
+       return TRUE;
 }
 
 
@@ -641,3 +639,16 @@ proto_reg_handoff_wow(void)
        dissector_add_uint("tcp.port", WOW_PORT, wow_handle);
 
 }
+
+/*
+ * Editor modelines  -  http://www.wireshark.org/tools/modelines.html
+ *
+ * Local variables:
+ * c-basic-offset: 8
+ * tab-width: 8
+ * indent-tabs-mode: t
+ * End:
+ *
+ * vi: set shiftwidth=8 tabstop=8 noexpandtab:
+ * :indentSize=8:tabSize=8:noTabs=false:
+ */