aboutsummaryrefslogtreecommitdiffstats
path: root/epan
diff options
context:
space:
mode:
authorGuy Harris <guy@alum.mit.edu>2017-10-26 00:03:09 -0700
committerGuy Harris <guy@alum.mit.edu>2017-10-26 07:03:43 +0000
commit859405fd2dd7b76e00d650e1674db2378e05beff (patch)
tree5398bf88a4ae3290d5412bdb352ccf42da57f8e5 /epan
parente7abfc397bfa8981b3813c19a64c36cfb275f21d (diff)
Swallow up the stuff from epan/ipv4.c into epan/ftypes/ftype-ipv4.c and epan/ipv4.h.
Most of it doesn't need to be public; pull it into epan/ipv4.c. Pull the two routines that *are* used outside epan/ftypes/ftype-ipv4.c into epan/ipv4.h as static inline functions. This allows some optimization, and makes epan/ipv4.h more like epan/ipv6.h. Change-Id: I80229acde559d810aecec2acd5c995076440c181 Reviewed-on: https://code.wireshark.org/review/24071 Reviewed-by: Guy Harris <guy@alum.mit.edu>
Diffstat (limited to 'epan')
-rw-r--r--epan/CMakeLists.txt1
-rw-r--r--epan/Makefile.am1
-rw-r--r--epan/ftypes/ftype-ipv4.c77
-rw-r--r--epan/ipv4.c167
-rw-r--r--epan/ipv4.h42
5 files changed, 69 insertions, 219 deletions
diff --git a/epan/CMakeLists.txt b/epan/CMakeLists.txt
index a5dcd6a6de..2b1be27c80 100644
--- a/epan/CMakeLists.txt
+++ b/epan/CMakeLists.txt
@@ -238,7 +238,6 @@ set(LIBWIRESHARK_FILES
iana_charsets.c
in_cksum.c
ipproto.c
- ipv4.c
media_params.c
next_tvb.c
oids.c
diff --git a/epan/Makefile.am b/epan/Makefile.am
index bee2753f6c..94c9452706 100644
--- a/epan/Makefile.am
+++ b/epan/Makefile.am
@@ -81,7 +81,6 @@ LIBWIRESHARK_SRC = \
iana_charsets.c \
in_cksum.c \
ipproto.c \
- ipv4.c \
media_params.c \
next_tvb.c \
oids.c \
diff --git a/epan/ftypes/ftype-ipv4.c b/epan/ftypes/ftype-ipv4.c
index c2b0365251..00a085ad21 100644
--- a/epan/ftypes/ftype-ipv4.c
+++ b/epan/ftypes/ftype-ipv4.c
@@ -24,14 +24,14 @@
#include <ftypes-int.h>
#include <epan/ipv4.h>
+#include <epan/addr_and_mask.h>
#include <epan/addr_resolv.h>
-
static void
set_uinteger(fvalue_t *fv, guint32 value)
{
- ipv4_addr_and_mask_set_net_order_addr(&(fv->value.ipv4), value);
- ipv4_addr_and_mask_set_netmask_bits(&(fv->value.ipv4), 32);
+ fv->value.ipv4.addr = g_ntohl(value);
+ fv->value.ipv4.nmask = ip_get_subnet_mask(32);
}
static gpointer
@@ -75,7 +75,7 @@ val_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_,
if (addr_str_to_free)
wmem_free(NULL, addr_str_to_free);
- ipv4_addr_and_mask_set_net_order_addr(&(fv->value.ipv4), addr);
+ fv->value.ipv4.addr = g_ntohl(addr);
/* If CIDR, get netmask bits. */
if (slash) {
@@ -97,11 +97,11 @@ val_from_unparsed(fvalue_t *fv, const char *s, gboolean allow_partial_value _U_,
}
return FALSE;
}
- ipv4_addr_and_mask_set_netmask_bits(&fv->value.ipv4, nmask_bits);
+ fv->value.ipv4.nmask = ip_get_subnet_mask(nmask_bits);
}
else {
/* Not CIDR; mask covers entire address. */
- ipv4_addr_and_mask_set_netmask_bits(&(fv->value.ipv4), 32);
+ fv->value.ipv4.nmask = ip_get_subnet_mask(32);
}
return TRUE;
@@ -116,46 +116,85 @@ val_repr_len(fvalue_t *fv _U_, ftrepr_t rtype _U_, int field_display _U_)
return 15;
}
+/* We're assuming the buffer is at least MAX_IP_STR_LEN (16 bytes) */
static void
val_to_repr(fvalue_t *fv, ftrepr_t rtype _U_, int field_display _U_, char *buf, unsigned int size _U_)
{
- ipv4_addr_and_mask_str_buf(&fv->value.ipv4, buf);
+ guint32 ipv4_net_order = g_htonl(fv->value.ipv4.addr);
+ ip_to_str_buf((guint8*)&ipv4_net_order, buf, MAX_IP_STR_LEN);
}
+
+/* Compares two ipv4_addr_and_masks, taking into account the less restrictive of the
+ * two netmasks, applying that netmask to both addrs.
+ *
+ * So, for example, w.x.y.z/32 eq w.x.y.0/24 is TRUE.
+ */
+
static gboolean
-cmp_eq(const fvalue_t *a, const fvalue_t *b)
+cmp_eq(const fvalue_t *fv_a, const fvalue_t *fv_b)
{
- return ipv4_addr_and_mask_eq(&a->value.ipv4, &b->value.ipv4);
+ guint32 addr_a, addr_b, nmask;
+
+ nmask = MIN(fv_a->value.ipv4.nmask, fv_b->value.ipv4.nmask);
+ addr_a = fv_a->value.ipv4.addr & nmask;
+ addr_b = fv_b->value.ipv4.addr & nmask;
+ return (addr_a == addr_b);
}
static gboolean
-cmp_ne(const fvalue_t *a, const fvalue_t *b)
+cmp_ne(const fvalue_t *fv_a, const fvalue_t *fv_b)
{
- return ipv4_addr_and_mask_ne(&a->value.ipv4, &b->value.ipv4);
+ guint32 addr_a, addr_b, nmask;
+
+ nmask = MIN(fv_a->value.ipv4.nmask, fv_b->value.ipv4.nmask);
+ addr_a = fv_a->value.ipv4.addr & nmask;
+ addr_b = fv_b->value.ipv4.addr & nmask;
+ return (addr_a != addr_b);
}
static gboolean
-cmp_gt(const fvalue_t *a, const fvalue_t *b)
+cmp_gt(const fvalue_t *fv_a, const fvalue_t *fv_b)
{
- return ipv4_addr_and_mask_gt(&a->value.ipv4, &b->value.ipv4);
+ guint32 addr_a, addr_b, nmask;
+
+ nmask = MIN(fv_a->value.ipv4.nmask, fv_b->value.ipv4.nmask);
+ addr_a = fv_a->value.ipv4.addr & nmask;
+ addr_b = fv_b->value.ipv4.addr & nmask;
+ return (addr_a > addr_b);
}
static gboolean
-cmp_ge(const fvalue_t *a, const fvalue_t *b)
+cmp_ge(const fvalue_t *fv_a, const fvalue_t *fv_b)
{
- return ipv4_addr_and_mask_ge(&a->value.ipv4, &b->value.ipv4);
+ guint32 addr_a, addr_b, nmask;
+
+ nmask = MIN(fv_a->value.ipv4.nmask, fv_b->value.ipv4.nmask);
+ addr_a = fv_a->value.ipv4.addr & nmask;
+ addr_b = fv_b->value.ipv4.addr & nmask;
+ return (addr_a >= addr_b);
}
static gboolean
-cmp_lt(const fvalue_t *a, const fvalue_t *b)
+cmp_lt(const fvalue_t *fv_a, const fvalue_t *fv_b)
{
- return ipv4_addr_and_mask_lt(&a->value.ipv4, &b->value.ipv4);
+ guint32 addr_a, addr_b, nmask;
+
+ nmask = MIN(fv_a->value.ipv4.nmask, fv_b->value.ipv4.nmask);
+ addr_a = fv_a->value.ipv4.addr & nmask;
+ addr_b = fv_b->value.ipv4.addr & nmask;
+ return (addr_a < addr_b);
}
static gboolean
-cmp_le(const fvalue_t *a, const fvalue_t *b)
+cmp_le(const fvalue_t *fv_a, const fvalue_t *fv_b)
{
- return ipv4_addr_and_mask_le(&a->value.ipv4, &b->value.ipv4);
+ guint32 addr_a, addr_b, nmask;
+
+ nmask = MIN(fv_a->value.ipv4.nmask, fv_b->value.ipv4.nmask);
+ addr_a = fv_a->value.ipv4.addr & nmask;
+ addr_b = fv_b->value.ipv4.addr & nmask;
+ return (addr_a <= addr_b);
}
static gboolean
diff --git a/epan/ipv4.c b/epan/ipv4.c
deleted file mode 100644
index 103e7b47d4..0000000000
--- a/epan/ipv4.c
+++ /dev/null
@@ -1,167 +0,0 @@
-/* ipv4.c
- *
- * IPv4 address class. They understand how to take netmasks into consideration
- * during equivalence testing.
- *
- * Gilbert Ramirez <gram@alumni.rice.edu>
- *
- * 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.
- */
-
-#include "config.h"
-
-#include <glib.h>
-#include <stdio.h>
-
-#include "ipv4.h"
-#include "to_str.h"
-#include "addr_and_mask.h"
-
-
-ipv4_addr_and_mask*
-ipv4_addr_and_mask_new(void)
-{
- ipv4_addr_and_mask *ipv4;
-
- ipv4 = g_new(ipv4_addr_and_mask, 1);
- return ipv4;
-}
-
-void
-ipv4_addr_and_mask_free(ipv4_addr_and_mask *ipv4)
-{
- g_free(ipv4);
-}
-
-void
-ipv4_addr_and_mask_set_host_order_addr(ipv4_addr_and_mask *ipv4, const guint32 new_addr)
-{
- ipv4->addr = new_addr;
-}
-
-void
-ipv4_addr_and_mask_set_net_order_addr(ipv4_addr_and_mask *ipv4, const guint32 new_addr)
-{
- ipv4->addr = g_ntohl(new_addr);
-}
-
-void
-ipv4_addr_and_mask_set_netmask_bits(ipv4_addr_and_mask *ipv4, const guint new_nmask_bits)
-{
- ipv4->nmask = ip_get_subnet_mask(new_nmask_bits);
-}
-
-guint32
-ipv4_get_net_order_addr(ipv4_addr_and_mask *ipv4)
-{
- return g_htonl(ipv4->addr);
-}
-
-guint32
-ipv4_get_host_order_addr(ipv4_addr_and_mask *ipv4)
-{
- return ipv4->addr;
-}
-
-/* We're assuming the buffer is at least MAX_IP_STR_LEN (16 bytes) */
-void
-ipv4_addr_and_mask_str_buf(const ipv4_addr_and_mask *ipv4, gchar *buf)
-{
- guint32 ipv4_host_order = g_htonl(ipv4->addr);
- ip_to_str_buf((guint8*)&ipv4_host_order, buf, MAX_IP_STR_LEN);
-}
-
-
-
-/*
- * w.x.y.z/32 eq w.x.y.0/24 TRUE
- */
-
-/* Returns TRUE if equal, FALSE if not */
-gboolean
-ipv4_addr_and_mask_eq(const ipv4_addr_and_mask *a, const ipv4_addr_and_mask *b)
-{
- guint32 val_a, val_b, nmask;
-
- nmask = MIN(a->nmask, b->nmask);
- val_a = a->addr & nmask;
- val_b = b->addr & nmask;
- return (val_a == val_b);
-}
-
-gboolean
-ipv4_addr_and_mask_gt(const ipv4_addr_and_mask *a, const ipv4_addr_and_mask *b)
-{
- guint32 val_a, val_b, nmask;
-
- nmask = MIN(a->nmask, b->nmask);
- val_a = a->addr & nmask;
- val_b = b->addr & nmask;
-
- return (val_a > val_b);
-}
-
-gboolean
-ipv4_addr_and_mask_ge(const ipv4_addr_and_mask *a, const ipv4_addr_and_mask *b)
-{
- guint32 val_a, val_b, nmask;
-
- nmask = MIN(a->nmask, b->nmask);
- val_a = a->addr & nmask;
- val_b = b->addr & nmask;
-
- return (val_a >= val_b);
-}
-
-gboolean
-ipv4_addr_and_mask_lt(const ipv4_addr_and_mask *a, const ipv4_addr_and_mask *b)
-{
- guint32 val_a, val_b, nmask;
-
- nmask = MIN(a->nmask, b->nmask);
- val_a = a->addr & nmask;
- val_b = b->addr & nmask;
-
- return (val_a < val_b);
-}
-
-gboolean
-ipv4_addr_and_mask_le(const ipv4_addr_and_mask *a, const ipv4_addr_and_mask *b)
-{
- guint32 val_a, val_b, nmask;
-
- nmask = MIN(a->nmask, b->nmask);
- val_a = a->addr & nmask;
- val_b = b->addr & nmask;
-
- return (val_a <= val_b);
-}
-
-/*
- * 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:
- */
diff --git a/epan/ipv4.h b/epan/ipv4.h
index fce104aedb..3adbbed8c3 100644
--- a/epan/ipv4.h
+++ b/epan/ipv4.h
@@ -30,41 +30,21 @@
#include <glib.h>
#include "ws_symbol_export.h"
-
typedef struct {
guint32 addr; /* stored in host order */
guint32 nmask; /* stored in host order */
} ipv4_addr_and_mask;
-/* Allocate a new ipv4_addr_and_mask struct, initialize it,
- * and return pointer
- */
-ipv4_addr_and_mask* ipv4_addr_and_mask_new(void);
-
-/* Frees an ipv4_addr_and_mask struct */
-void ipv4_addr_and_mask_free(ipv4_addr_and_mask *ipv4);
-
-void ipv4_addr_and_mask_set_host_order_addr(ipv4_addr_and_mask *ipv4, const guint32 new_addr);
-void ipv4_addr_and_mask_set_net_order_addr(ipv4_addr_and_mask *ipv4, const guint32 new_addr);
-void ipv4_addr_and_mask_set_netmask_bits(ipv4_addr_and_mask *ipv4, const guint new_nmask_bits);
-
-WS_DLL_PUBLIC
-guint32 ipv4_get_net_order_addr(ipv4_addr_and_mask *ipv4);
-guint32 ipv4_get_host_order_addr(ipv4_addr_and_mask *ipv4);
-
-/* Fills in a buffer with a dotted-decimal notation representation of an IPv4
- * address. */
-void ipv4_addr_and_mask_str_buf(const ipv4_addr_and_mask *ipv4, gchar *buf);
-
-/* Compares two ipv4_addr_and_masks, taking into account the less restrictive of the
- * two netmasks, applying that netmask to both addrs.
- */
-gboolean ipv4_addr_and_mask_eq(const ipv4_addr_and_mask *a, const ipv4_addr_and_mask *b);
-gboolean ipv4_addr_and_mask_gt(const ipv4_addr_and_mask *a, const ipv4_addr_and_mask *b);
-gboolean ipv4_addr_and_mask_ge(const ipv4_addr_and_mask *a, const ipv4_addr_and_mask *b);
-gboolean ipv4_addr_and_mask_lt(const ipv4_addr_and_mask *a, const ipv4_addr_and_mask *b);
-gboolean ipv4_addr_and_mask_le(const ipv4_addr_and_mask *a, const ipv4_addr_and_mask *b);
-
-#define ipv4_addr_and_mask_ne(a,b) !ipv4_addr_and_mask_eq((a),(b))
+static inline guint32
+ipv4_get_net_order_addr(ipv4_addr_and_mask *ipv4)
+{
+ return g_htonl(ipv4->addr);
+}
+
+static inline guint32
+ipv4_get_host_order_addr(ipv4_addr_and_mask *ipv4)
+{
+ return ipv4->addr;
+}
#endif