HTTPS (almost) everywhere.
[metze/wireshark/wip.git] / epan / dissectors / packet-pulse.c
1 /* packet-pulse.c
2  * Routines for pulse dissection
3  * Copyright 2013, Masatake YAMATO <yamato@redhat.com>
4  * Copyright 2013, Red Hat, Inc.
5  *
6  * Wireshark - Network traffic analyzer
7  * By Gerald Combs <gerald@wireshark.org>
8  * Copyright 1998 Gerald Combs
9  *
10  * SPDX-License-Identifier: GPL-2.0-or-later
11  */
12
13
14 /* About pulse, see
15     http://sourceware.org/piranha/ */
16
17 # include "config.h"
18
19 #include <epan/packet.h>
20
21 #define PORT_PULSE 539 /* Not IANA registered */
22
23 void proto_register_pulse(void);
24 void proto_reg_handoff_pulse(void);
25
26 static int  proto_pulse    = -1;
27 static int  hf_pulse_magic = -1;
28 static gint ett_pulse      = -1;
29
30 /* piranha/pulse.c */
31 #define PULSE_HEARTBEAT_RUNNING_MAGIC     0xbdaddbda
32 #define PULSE_HEARTBEAT_STOPPED_MAGIC     0xadbddabd
33
34 static const value_string pulse_magic_type[] = {
35     { PULSE_HEARTBEAT_RUNNING_MAGIC,   "running" },
36     { PULSE_HEARTBEAT_STOPPED_MAGIC,   "stopped" },
37     { 0, NULL                                    }
38 };
39
40 static int
41 dissect_pulse(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, void* data _U_)
42 {
43     proto_item *item;
44     proto_tree *tree;
45
46     guint32 magic;
47     const char* magic_str;
48     guint little_endian;
49
50     if (tvb_captured_length(tvb) < 4)
51         return 0;
52
53     /* Try to read MAGIC in both endians */
54     little_endian = ENC_LITTLE_ENDIAN;
55     magic = tvb_get_letohl(tvb, 0);
56     magic_str = try_val_to_str(magic, pulse_magic_type);
57     if (magic_str == NULL) {
58       magic = tvb_get_ntohl(tvb, 0);
59       magic_str = try_val_to_str(magic, pulse_magic_type);
60       if (magic_str == NULL) {
61         return 0;
62       }
63       little_endian = ENC_BIG_ENDIAN;
64     }
65
66     col_set_str(pinfo->cinfo, COL_PROTOCOL, "PULSE");
67     col_set_str(pinfo->cinfo, COL_INFO, magic_str);
68
69     if (parent_tree) {
70         item = proto_tree_add_item(parent_tree, proto_pulse, tvb, 0,
71                                    -1, little_endian);
72         tree = proto_item_add_subtree(item, ett_pulse);
73         proto_tree_add_item(tree, hf_pulse_magic, tvb, 0, 4, little_endian);
74     }
75     return 4;
76 }
77
78 void
79 proto_register_pulse(void)
80 {
81     static hf_register_info hf[] = {
82         { &hf_pulse_magic,
83           { "Magic", "pulse.magic",
84             FT_UINT32, BASE_HEX, VALS(pulse_magic_type), 0x0,
85             NULL, HFILL }},
86     };
87
88     static gint *ett[] = {
89         &ett_pulse,
90     };
91
92
93     proto_pulse = proto_register_protocol("PULSE protocol for Linux Virtual Server redundancy", "PULSE", "pulse");
94     proto_register_field_array(proto_pulse, hf, array_length(hf));
95     proto_register_subtree_array(ett, array_length(ett));
96 }
97
98 void
99 proto_reg_handoff_pulse(void)
100 {
101     dissector_handle_t pulse_handle;
102     pulse_handle = create_dissector_handle(dissect_pulse, proto_pulse);
103     dissector_add_uint_with_preference("udp.port", PORT_PULSE, pulse_handle);
104 }
105
106 /*
107  * Editor modelines  -  https://www.wireshark.org/tools/modelines.html
108  *
109  * Local variables:
110  * c-basic-offset: 4
111  * tab-width: 8
112  * indent-tabs-mode: nil
113  * End:
114  *
115  * vi: set shiftwidth=4 tabstop=8 expandtab:
116  * :indentSize=4:tabSize=8:noTabs=true:
117  */