2 * Routines for TSDNS (TeamSpeak3 DNS) packet disassembly
3 * Copyright 2018, Maciej Krueger <mkg20001@gmail.com>
5 * Wireshark - Network traffic analyzer
6 * By Gerald Combs <gerald@wireshark.org>
7 * Copyright 1998 Gerald Combs
9 * SPDX-License-Identifier: GPL-2.0-or-later
14 #include <epan/packet.h>
15 #include <epan/expert.h>
16 #include <epan/strutil.h>
17 #include <wsutil/strtoi.h>
19 #define TSDNS_PORT 41144 /* Not IANA registered */
21 void proto_register_tsdns(void);
22 void proto_reg_handoff_tsdns(void);
23 static dissector_handle_t tsdns_handle
;
25 static int proto_tsdns
;
27 static int hf_tsdns_data
;
28 static int hf_tsdns_request
;
29 static int hf_tsdns_request_domain
;
30 static int hf_tsdns_response
;
31 static int hf_tsdns_response_ip
;
32 static int hf_tsdns_response_address
;
33 static int hf_tsdns_response_port
;
35 static expert_field ei_response_port_malformed
;
39 static int dissect_tsdns(tvbuff_t
*tvb
, packet_info
*pinfo
, proto_tree
*tree
, void* data _U_
)
45 if (pinfo
->destport
== pinfo
->match_uint
) {
49 col_set_str(pinfo
->cinfo
, COL_PROTOCOL
, "TSDNS");
51 int pLen
= tvb_reported_length(tvb
);
54 col_set_str(pinfo
->cinfo
, COL_INFO
, "Request");
55 col_append_fstr(pinfo
->cinfo
, COL_INFO
, " %s", tvb_get_string_enc(pinfo
->pool
, tvb
, 0, pLen
- 5, ENC_ASCII
));
57 col_set_str(pinfo
->cinfo
, COL_INFO
, "Response");
58 col_append_fstr(pinfo
->cinfo
, COL_INFO
, " %s", tvb_get_string_enc(pinfo
->pool
, tvb
, 0, pLen
, ENC_ASCII
));
61 proto_tree
*tsdns_tree
;
62 proto_item
*ti
, *hidden_item
, *address_item
;
64 ti
= proto_tree_add_item(tree
, proto_tsdns
, tvb
, offset
, -1, ENC_NA
);
65 tsdns_tree
= proto_item_add_subtree(ti
, ett_tsdns
);
67 hidden_item
= proto_tree_add_item(tsdns_tree
, hf_tsdns_data
, tvb
, offset
, -1, ENC_ASCII
);
68 proto_item_set_hidden(hidden_item
);
70 if (request
) { // request is DOMAIN\n\r\r\r\n
71 hidden_item
= proto_tree_add_boolean(tsdns_tree
, hf_tsdns_request
, tvb
, 0, 0, 1); // using pLen - 5 as the last chars are \n\r\r\r\n which are just indicating the end of the request
72 proto_tree_add_item(tsdns_tree
, hf_tsdns_request_domain
, tvb
, offset
, pLen
- 5, ENC_ASCII
);
73 } else { // response is IP:PORT
74 hidden_item
= proto_tree_add_boolean(tsdns_tree
, hf_tsdns_response
, tvb
, 0, 0, 1);
75 address_item
= proto_tree_add_item(tsdns_tree
, hf_tsdns_response_address
, tvb
, offset
, pLen
, ENC_ASCII
);
77 splitAddress
= wmem_strsplit(pinfo
->pool
, tvb_format_text(pinfo
->pool
, tvb
, 0, pLen
), ":", 1); // unsure if TSDNS also does IPv6...
78 if (splitAddress
== NULL
|| splitAddress
[0] == NULL
|| splitAddress
[1] == NULL
) {
79 expert_add_info(pinfo
, address_item
, &ei_response_port_malformed
);
81 proto_tree_add_string(tsdns_tree
, hf_tsdns_response_ip
, tvb
, 0, pLen
, splitAddress
[0]);
83 if (ws_strtou32(splitAddress
[1], NULL
, &port
))
84 proto_tree_add_uint(tsdns_tree
, hf_tsdns_response_port
, tvb
, 0, pLen
, port
);
87 proto_item_set_hidden(hidden_item
);
89 return tvb_captured_length(tvb
);
93 void proto_register_tsdns(void)
96 static hf_register_info hf
[] = {
98 { "Data", "tsdns.data",
99 FT_STRING
, BASE_NONE
, NULL
, 0x0,
102 { "Request", "tsdns.request",
103 FT_BOOLEAN
, BASE_NONE
, NULL
, 0x0,
104 "true if TSDNS Request", HFILL
}},
105 { &hf_tsdns_request_domain
,
106 { "Requested Domain", "tsdns.request.domain",
107 FT_STRING
, BASE_NONE
, NULL
, 0x0,
109 { &hf_tsdns_response
,
110 { "Response","tsdns.response",
111 FT_BOOLEAN
, BASE_NONE
, NULL
, 0x0,
112 "true if TSDNS Response", HFILL
}},
113 { &hf_tsdns_response_address
,
114 { "Response Address","tsdns.response.address",
115 FT_STRING
, BASE_NONE
, NULL
, 0x0,
117 { &hf_tsdns_response_ip
,
118 { "Response IP","tsdns.response.ip",
119 FT_STRING
, BASE_NONE
, NULL
, 0x0,
121 { &hf_tsdns_response_port
,
122 { "Response Port","tsdns.response.port",
123 FT_UINT16
, BASE_DEC
, NULL
, 0x0,
127 static ei_register_info ei
[] = {
128 { &ei_response_port_malformed
, { "tsdns.response.port.malformed", PI_MALFORMED
, PI_ERROR
, "Address port is not an integer or not contained in address", EXPFILL
}}
130 expert_module_t
* expert_tsdns
;
132 static int *ett
[] = {
136 proto_tsdns
= proto_register_protocol("TeamSpeak3 DNS", "TSDNS", "tsdns");
137 proto_register_field_array(proto_tsdns
, hf
, array_length(hf
));
138 proto_register_subtree_array(ett
, array_length(ett
));
139 expert_tsdns
= expert_register_protocol(proto_tsdns
);
140 expert_register_field_array(expert_tsdns
, ei
, array_length(ei
));
142 tsdns_handle
= register_dissector("tsdns", dissect_tsdns
, proto_tsdns
);
145 void proto_reg_handoff_tsdns(void)
147 /* Default port to not dissect the protocol*/
148 dissector_add_uint_with_preference("tcp.port", 0, tsdns_handle
);
152 * Editor modelines - https://www.wireshark.org/tools/modelines.html
157 * indent-tabs-mode: t
160 * vi: set shiftwidth=8 tabstop=8 noexpandtab:
161 * :indentSize=8:tabSize=8:noTabs=false: