aboutsummaryrefslogtreecommitdiffstats
path: root/ipv4.h
diff options
context:
space:
mode:
authorGilbert Ramirez <gram@alumni.rice.edu>1999-11-15 06:32:38 +0000
committerGilbert Ramirez <gram@alumni.rice.edu>1999-11-15 06:32:38 +0000
commit6a20c7bbc5e98c72bda45f7b7e17336694ec5580 (patch)
treea387ae6866e8e50e796c83937e84df6ee7838647 /ipv4.h
parent1fca132c59ad267b19719cd1b061255ef5751e17 (diff)
Add "class" that understands IPv4 addresses and subnet masks.
We now store IPv4 addresses in host order, allowing non-equivalence comparisons. That is, display filters with lt, le, gt, and ge will work on big-endian and little-endian machines. CIDR notation is now supported for IPv4 addresses in display filters. You can test to see if an IPv4 address is on a certain subnet by using this notation. For example, to test for IPv4 packets on a Class-C network: ip.addr == 192.168.1.0/24 svn path=/trunk/; revision=1032
Diffstat (limited to 'ipv4.h')
-rw-r--r--ipv4.h60
1 files changed, 60 insertions, 0 deletions
diff --git a/ipv4.h b/ipv4.h
new file mode 100644
index 0000000000..c6f4da99fc
--- /dev/null
+++ b/ipv4.h
@@ -0,0 +1,60 @@
+/* ip4.h
+ *
+ * IPv4 address class. They understand how to take netmasks into consideration
+ * during equivalence testing.
+ *
+ * Gilbert Ramirez <gramirez@tivoli.cm>
+ *
+ * $Id: ipv4.h,v 1.1 1999/11/15 06:32:14 gram Exp $
+ *
+ * Ethereal - Network traffic analyzer
+ * By Gerald Combs <gerald@unicom.net>
+ * 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef __IPV4_H__
+#define __IPV4_H__
+
+typedef struct {
+ guint32 addr; /* stored in host order */
+ guint32 nmask; /* stored in host order */
+} ipv4_addr;
+
+/* Allocate a new ipv4_addr struct, initialize it, and return pointer */
+ipv4_addr* ipv4_addr_new(void);
+
+/* Frees an ipv4 struct */
+void ipv4_addr_free(ipv4_addr *ipv4);
+
+void ipv4_addr_set_host_order_addr(ipv4_addr *ipv4, guint32 new_addr);
+void ipv4_addr_set_net_order_addr(ipv4_addr *ipv4, guint32 new_addr);
+void ipv4_addr_set_netmask_bits(ipv4_addr *ipv4, guint new_nmask_bits);
+
+guint32 ipv4_get_net_order_addr(ipv4_addr *ipv4);
+guint32 ipv4_get_host_order_addr(ipv4_addr *ipv4);
+
+/* Compares two ipv4_addrs, taking into account the less restrictive of the
+ * two netmasks, applying that netmask to both addrs.
+ */
+gboolean ipv4_addr_eq(ipv4_addr *a, ipv4_addr *b);
+gboolean ipv4_addr_gt(ipv4_addr *a, ipv4_addr *b);
+gboolean ipv4_addr_ge(ipv4_addr *a, ipv4_addr *b);
+gboolean ipv4_addr_lt(ipv4_addr *a, ipv4_addr *b);
+gboolean ipv4_addr_le(ipv4_addr *a, ipv4_addr *b);
+
+#endif