summaryrefslogtreecommitdiffstats
path: root/epan/dissectors/packet-ypbind.c
blob: 4d4965ca0ff0c5e8f4348b8bf0e9a236a6ecec47 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
/* packet-ypbind.c
 * Routines for ypbind dissection
 *
 * Wireshark - Network traffic analyzer
 * By Gerald Combs <gerald@wireshark.org>
 * Copyright 1998 Gerald Combs
 *
 * Copied from packet-smb.c
 *
 *    2001  Ronnie Sahlberg, added dissectors for the commands
 *
 * SPDX-License-Identifier: GPL-2.0-or-later
 */

#include "config.h"

#include "packet-rpc.h"
#include "packet-ypbind.h"

void proto_register_ypbind(void);
void proto_reg_handoff_ypbind(void);

static int proto_ypbind = -1;
static int hf_ypbind_procedure_v1 = -1;
static int hf_ypbind_procedure_v2 = -1;
static int hf_ypbind_domain = -1;
static int hf_ypbind_resp_type = -1;
/* static int hf_ypbind_error = -1; */
static int hf_ypbind_addr = -1;
static int hf_ypbind_port = -1;
static int hf_ypbind_setdom_version = -1;

static gint ett_ypbind = -1;


static int
dissect_ypbind_domain_v2_request(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, void* data _U_)
{
	/* domain */
	return dissect_rpc_string(tvb, tree, hf_ypbind_domain, 0, NULL);
}

#define YPBIND_RESP_TYPE_SUCC_VAL	1
#define YPBIND_RESP_TYPE_FAIL_VAL	2
static const value_string resp_type_vals[] = {
	{YPBIND_RESP_TYPE_SUCC_VAL,	"SUCC_VAL"},
	{YPBIND_RESP_TYPE_FAIL_VAL,	"FAIL_VAL"},
	{0, NULL}
};

#if 0
#define YPBIND_ERROR_ERR	1
#define YPBIND_ERROR_NOSERV	2
#define YPBIND_ERROR_RESC	3
static const value_string error_vals[] = {
	{YPBIND_ERROR_ERR,	"Internal error"},
	{YPBIND_ERROR_NOSERV,	"No bound server for passed domain"},
	{YPBIND_ERROR_RESC,	"System resource allocation failure"},
	{0, NULL}
};
#endif

static int
dissect_ypbind_domain_v2_reply(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, void* data _U_)
{
	guint32 type;
	int offset = 0;

	/* response type */
	type=tvb_get_ntohl(tvb, offset);
	offset = dissect_rpc_uint32(tvb, tree, hf_ypbind_resp_type, offset);

	switch(type){
	case YPBIND_RESP_TYPE_SUCC_VAL:
		/* ip address */
		proto_tree_add_item(tree, hf_ypbind_addr,
			tvb, offset, 4, ENC_BIG_ENDIAN);
		offset += 4;

		/* port */
		offset = dissect_rpc_uint32(tvb, tree,
				hf_ypbind_port, offset);

		break;
	case YPBIND_RESP_TYPE_FAIL_VAL:
		/* error */
		offset = dissect_rpc_uint32(tvb, tree,
				hf_ypbind_resp_type, offset);
		break;
	}

	return offset;
}

static int
dissect_ypbind_setdomain_v2_request(tvbuff_t *tvb, packet_info *pinfo _U_, proto_tree *tree, void* data _U_)
{
	int offset = 0;

	/* domain */
	offset = dissect_rpc_string(tvb, tree,
			hf_ypbind_domain, offset, NULL);

	/* ip address */
	proto_tree_add_item(tree, hf_ypbind_addr,
		tvb, offset, 4, ENC_BIG_ENDIAN);
	offset += 4;

	/* port */
	offset = dissect_rpc_uint32(tvb, tree,
			hf_ypbind_port, offset);

	/* version */
	offset = dissect_rpc_uint32(tvb, tree,
			hf_ypbind_setdom_version, offset);

	return offset;
}



/* proc number, "proc name", dissect_request, dissect_reply */
static const vsff ypbind1_proc[] = {
	{ YPBINDPROC_NULL,	"NULL",
		dissect_rpc_void,	dissect_rpc_void },
	{ YPBINDPROC_DOMAIN,	"DOMAIN",	dissect_rpc_unknown,	dissect_rpc_unknown },
	{ YPBINDPROC_SETDOM,	"SETDOMAIN",	dissect_rpc_unknown,	dissect_rpc_unknown },
	{ 0,			NULL,		NULL,	NULL }
};
static const value_string ypbind1_proc_vals[] = {
	{ YPBINDPROC_NULL,	"NULL" },
	{ YPBINDPROC_DOMAIN,	"DOMAIN" },
	{ YPBINDPROC_SETDOM,	"SETDOMAIN" },
	{ 0,	NULL }
};
/* end of YPBind version 1 */

static const vsff ypbind2_proc[] = {
	{ YPBINDPROC_NULL,	"NULL",
		dissect_rpc_void,	dissect_rpc_void },
	{ YPBINDPROC_DOMAIN,	"DOMAIN",
		dissect_ypbind_domain_v2_request, dissect_ypbind_domain_v2_reply},
	{ YPBINDPROC_SETDOM,	"SETDOMAIN",
		dissect_ypbind_setdomain_v2_request, dissect_rpc_void },
	{ 0,    		NULL,       	NULL,	NULL }
};
static const value_string ypbind2_proc_vals[] = {
	{ YPBINDPROC_NULL,	"NULL" },
	{ YPBINDPROC_DOMAIN,	"DOMAIN" },
	{ YPBINDPROC_SETDOM,	"SETDOMAIN" },
	{ 0,    NULL }
};
/* end of YPBind version 2 */


static const rpc_prog_vers_info ypbind_vers_info[] = {
	{ 1, ypbind1_proc, &hf_ypbind_procedure_v1 },
	{ 2, ypbind2_proc, &hf_ypbind_procedure_v2 },
};

void
proto_register_ypbind(void)
{
	static hf_register_info hf[] = {
		{ &hf_ypbind_procedure_v1, {
			"V1 Procedure", "ypbind.procedure_v1", FT_UINT32, BASE_DEC,
			VALS(ypbind1_proc_vals), 0, NULL, HFILL }},
		{ &hf_ypbind_procedure_v2, {
			"V2 Procedure", "ypbind.procedure_v2", FT_UINT32, BASE_DEC,
			VALS(ypbind2_proc_vals), 0, NULL, HFILL }},
		{ &hf_ypbind_domain, {
			"Domain", "ypbind.domain", FT_STRING, BASE_NONE,
			NULL, 0, "Name of the NIS/YP Domain", HFILL }},

		{ &hf_ypbind_resp_type, {
			"Response Type", "ypbind.resp_type", FT_UINT32, BASE_DEC,
			VALS(resp_type_vals), 0, NULL, HFILL }},

#if 0
		{ &hf_ypbind_error, {
			"Error", "ypbind.error", FT_UINT32, BASE_DEC,
			VALS(error_vals), 0, "YPBIND Error code", HFILL }},
#endif
		{ &hf_ypbind_addr, {
			"IP Addr", "ypbind.addr", FT_IPv4, BASE_NONE,
			NULL, 0, "IP Address of server", HFILL }},

		{ &hf_ypbind_port, {
			"Port", "ypbind.port", FT_UINT32, BASE_DEC,
			NULL, 0, "Port to use", HFILL }},

		{ &hf_ypbind_setdom_version, {
			"Version", "ypbind.setdom.version", FT_UINT32, BASE_DEC,
			NULL, 0, "Version of setdom", HFILL }},

	};

	static gint *ett[] = {
		&ett_ypbind,
	};

	proto_ypbind = proto_register_protocol("Yellow Pages Bind",
	    "YPBIND", "ypbind");
	proto_register_field_array(proto_ypbind, hf, array_length(hf));
	proto_register_subtree_array(ett, array_length(ett));
}

void
proto_reg_handoff_ypbind(void)
{
	/* Register the protocol as RPC */
	rpc_init_prog(proto_ypbind, YPBIND_PROGRAM, ett_ypbind,
	    G_N_ELEMENTS(ypbind_vers_info), ypbind_vers_info);
}

/*
 * Editor modelines  -  https://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:
 */