aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2017-10-29 19:10:46 -0700
committerGuy Harris <guy@alum.mit.edu>2017-10-30 02:11:22 +0000
commit39ba9d4e7fb52ca8017bd4e934d6e6f8acba8d4c (patch)
treeeacce8999646bf94f162514e92c94747ca03dc4f
parentdd1c18dd031038cbee7e219e322cbea1eafc87ca (diff)
Add wsutil/inet_ipv4.h.
It defines a ws_in4_addr type, which is intended to hold IPv4 addresses in network byte order, and some macros to test for IPv4 addresses in the local network control block and multicast IPv4 addresses. Use those macros in places where dissectors had their own code for that purpose. Change-Id: I4252b410e37207157be85119a332e2a6913b332f Reviewed-on: https://code.wireshark.org/review/24178 Reviewed-by: Guy Harris <guy@alum.mit.edu>
-rw-r--r--epan/dissectors/packet-cipsafety.c2
-rw-r--r--epan/dissectors/packet-icmp.c3
-rw-r--r--epan/dissectors/packet-ip.c12
-rw-r--r--epan/ipv4.h2
-rw-r--r--wsutil/Makefile.am1
-rw-r--r--wsutil/inet_ipv4.h44
6 files changed, 50 insertions, 14 deletions
diff --git a/epan/dissectors/packet-cipsafety.c b/epan/dissectors/packet-cipsafety.c
index eb40a6b..233e6b5 100644
--- a/epan/dissectors/packet-cipsafety.c
+++ b/epan/dissectors/packet-cipsafety.c
@@ -1484,7 +1484,7 @@ static void
dissect_cip_safety_data( proto_tree *tree, proto_item *item, tvbuff_t *tvb, int item_length, packet_info *pinfo, cip_safety_info_t* safety_info)
{
int base_length, io_data_size;
- gboolean multicast = (((pntoh32(pinfo->dst.data)) & 0xf0000000) == 0xe0000000);
+ gboolean multicast = in4_addr_is_multicast(pntoh32(pinfo->dst.data));
gboolean server_dir = FALSE;
enum enip_connid_type conn_type = ECIDT_UNKNOWN;
enum cip_safety_format_type format = CIP_SAFETY_BASE_FORMAT;
diff --git a/epan/dissectors/packet-icmp.c b/epan/dissectors/packet-icmp.c
index e9b9767..0dd9d56 100644
--- a/epan/dissectors/packet-icmp.c
+++ b/epan/dissectors/packet-icmp.c
@@ -357,8 +357,7 @@ static const value_string interface_role_str[] = {
#define MPLS_EXTENDED_PAYLOAD_C_TYPE 1
/* Return true if the address is in the 224.0.0.0/4 network block */
-#define is_a_multicast_addr(a) \
- ((g_ntohl(a) & 0xf0000000) == 0xe0000000)
+#define is_a_multicast_addr(a) in4_addr_is_multicast(g_ntohl(a))
/* Return true if the address is the 255.255.255.255 broadcast address */
#define is_a_broadcast_addr(a) \
diff --git a/epan/dissectors/packet-ip.c b/epan/dissectors/packet-ip.c
index 998ab0a..28be99e 100644
--- a/epan/dissectors/packet-ip.c
+++ b/epan/dissectors/packet-ip.c
@@ -498,14 +498,6 @@ const value_string ip_version_vals[] = {
#define IPLOCAL_NETWRK_CTRL_BLK_ANY_TTL 0x1000 /* larger than max ttl */
#define IPLOCAL_NETWRK_CTRL_BLK_DEFAULT_TTL 0X01
-/* Return true if the address is in the 224.0.0.0/24 network block */
-#define is_a_local_network_control_block_addr(addr) \
- ((addr & 0xffffff00) == 0xe0000000)
-
-/* Return true if the address is in the 224.0.0.0/4 network block */
-#define is_a_multicast_addr(addr) \
- ((addr & 0xf0000000) == 0xe0000000)
-
static void ip_prompt(packet_info *pinfo, gchar* result)
{
g_snprintf(result, MAX_DECODE_AS_PROMPT_LEN, "IP protocol %u as",
@@ -2174,14 +2166,14 @@ dissect_ip_v4(tvbuff_t *tvb, packet_info *pinfo, proto_tree *parent_tree, void*
* (e.g. 224.0.0.0/4) ... and the payload isn't protocol 103 (PIM).
* (see http://tools.ietf.org/html/rfc3973#section-4.7).
*/
- if (is_a_local_network_control_block_addr(dst32)) {
+ if (in4_addr_is_local_network_control_block(dst32)) {
ttl = local_network_control_block_addr_valid_ttl(dst32);
if (ttl != iph->ip_ttl && ttl != IPLOCAL_NETWRK_CTRL_BLK_ANY_TTL) {
expert_add_info_format(pinfo, ttl_item, &ei_ip_ttl_lncb, "\"Time To Live\" != %d for a packet sent to the "
"Local Network Control Block (see RFC 3171)",
ttl);
}
- } else if (!is_a_multicast_addr(dst32) &&
+ } else if (!in4_addr_is_multicast(dst32) &&
/* At least BGP should appear here as well */
iph->ip_ttl < 5 &&
iph->ip_proto != IP_PROTO_PIM &&
diff --git a/epan/ipv4.h b/epan/ipv4.h
index 979f5f5..af43414 100644
--- a/epan/ipv4.h
+++ b/epan/ipv4.h
@@ -28,7 +28,7 @@
#ifndef __IPV4_H__
#define __IPV4_H__
-#include <glib.h>
+#include <wsutil/inet_ipv4.h>
typedef struct {
guint32 addr; /* stored in host order */
diff --git a/wsutil/Makefile.am b/wsutil/Makefile.am
index bea58f3..6cb212b 100644
--- a/wsutil/Makefile.am
+++ b/wsutil/Makefile.am
@@ -59,6 +59,7 @@ WSUTIL_PUBLIC_INCLUDES = \
g711.h \
glib-compat.h \
inet_addr.h \
+ inet_ipv4.h \
inet_ipv6.h \
interface.h \
jsmn.h \
diff --git a/wsutil/inet_ipv4.h b/wsutil/inet_ipv4.h
new file mode 100644
index 0000000..9c1094f
--- /dev/null
+++ b/wsutil/inet_ipv4.h
@@ -0,0 +1,44 @@
+/* inet_ipv4.h
+ *
+ * Wireshark - Network traffic analyzer
+ * By Gerald Combs <gerald@wireshark.org>
+ * Copyright 1998 Gerald Combs
+ *
+ * This program is free software; you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation; either version 2
+ * of the License, or (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
+ */
+
+#ifndef __INET_IPV4_H__
+#define __INET_IPV4_H__
+
+#include <glib.h>
+
+typedef guint32 ws_in4_addr; /* 32 bit IPv4 address, in network byte order */
+
+/**
+ * Unicast Local
+ * Returns true if the address is in the 224.0.0.0/24 local network
+ * control block
+ */
+#define in4_addr_is_local_network_control_block(addr) \
+ ((addr & 0xffffff00) == 0xe0000000)
+
+/**
+ * Multicast
+ * Returns true if the address is in the 224.0.0.0/4 network block
+ */
+#define in4_addr_is_multicast(addr) \
+ ((addr & 0xf0000000) == 0xe0000000)
+
+#endif