aboutsummaryrefslogtreecommitdiffstats
path: root/dfilter.c
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 /dfilter.c
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 'dfilter.c')
-rw-r--r--dfilter.c104
1 files changed, 103 insertions, 1 deletions
diff --git a/dfilter.c b/dfilter.c
index ef4aa7257d..f948246535 100644
--- a/dfilter.c
+++ b/dfilter.c
@@ -1,7 +1,7 @@
/* dfilter.c
* Routines for display filters
*
- * $Id: dfilter.c,v 1.31 1999/10/19 05:31:14 gram Exp $
+ * $Id: dfilter.c,v 1.32 1999/11/15 06:32:13 gram Exp $
*
* Ethereal - Network traffic analyzer
* By Gerald Combs <gerald@zing.org>
@@ -520,6 +520,17 @@ gboolean fill_array_ether_variable(GNode *gnode, gpointer data)
return FALSE; /* FALSE = do not end traversal of GNode tree */
}
+gboolean fill_array_ipv4_variable(GNode *gnode, gpointer data)
+{
+ proto_tree_search_info *sinfo = (proto_tree_search_info*)data;
+ field_info *fi = (field_info*) (gnode->data);
+
+ if (fi->hfinfo->id == sinfo->target) {
+ g_array_append_val(sinfo->result.array, fi->value.ipv4);
+ }
+
+ return FALSE; /* FALSE = do not end traversal of GNode tree */
+}
gboolean fill_array_ipv6_variable(GNode *gnode, gpointer data)
{
proto_tree_search_info *sinfo = (proto_tree_search_info*)data;
@@ -598,6 +609,16 @@ gboolean fill_array_ether_value(GNode *gnode, gpointer data)
return FALSE; /* FALSE = do not end traversal of GNode tree */
}
+gboolean fill_array_ipv4_value(GNode *gnode, gpointer data)
+{
+ GArray *array = (GArray*)data;
+ dfilter_node *dnode = (dfilter_node*) (gnode->data);
+
+ g_array_append_val(array, dnode->value.ipv4);
+
+ return FALSE; /* FALSE = do not end traversal of GNode tree */
+}
+
gboolean fill_array_ipv6_value(GNode *gnode, gpointer data)
{
GArray *array = (GArray*)data;
@@ -775,6 +796,87 @@ gboolean check_relation_floating(gint operand, GArray *a, GArray *b)
return FALSE;
}
+gboolean check_relation_ipv4(gint operand, GArray *a, GArray *b)
+{
+ int i, j, len_a, len_b;
+ ipv4_addr *ptr_a, *ptr_b;
+
+ len_a = a->len;
+ len_b = b->len;
+
+
+ switch(operand) {
+ case TOK_EQ:
+ for(i = 0; i < len_a; i++) {
+ ptr_a = (ipv4_addr*) g_array_index_ptr(a, sizeof(ipv4_addr), i);
+ for (j = 0; j < len_b; j++) {
+ ptr_b = (ipv4_addr*) g_array_index_ptr(b, sizeof(ipv4_addr), j);
+ if (ipv4_addr_eq(ptr_a, ptr_b))
+ return TRUE;
+ }
+ }
+ return FALSE;
+
+ case TOK_NE:
+ for(i = 0; i < len_a; i++) {
+ ptr_a = (ipv4_addr*) g_array_index_ptr(a, sizeof(ipv4_addr), i);
+ for (j = 0; j < len_b; j++) {
+ ptr_b = (ipv4_addr*) g_array_index_ptr(b, sizeof(ipv4_addr), j);
+ if (!ipv4_addr_eq(ptr_a, ptr_b))
+ return TRUE;
+ }
+ }
+ return FALSE;
+
+ case TOK_GT:
+ for(i = 0; i < len_a; i++) {
+ ptr_a = (ipv4_addr*) g_array_index_ptr(a, sizeof(ipv4_addr), i);
+ for (j = 0; j < len_b; j++) {
+ ptr_b = (ipv4_addr*) g_array_index_ptr(b, sizeof(ipv4_addr), j);
+ if (ipv4_addr_gt(ptr_a, ptr_b))
+ return TRUE;
+ }
+ }
+ return FALSE;
+
+ case TOK_GE:
+ for(i = 0; i < len_a; i++) {
+ ptr_a = (ipv4_addr*) g_array_index_ptr(a, sizeof(ipv4_addr), i);
+ for (j = 0; j < len_b; j++) {
+ ptr_b = (ipv4_addr*) g_array_index_ptr(b, sizeof(ipv4_addr), j);
+ if (ipv4_addr_ge(ptr_a, ptr_b))
+ return TRUE;
+ }
+ }
+ return FALSE;
+
+ case TOK_LT:
+ for(i = 0; i < len_a; i++) {
+ ptr_a = (ipv4_addr*) g_array_index_ptr(a, sizeof(ipv4_addr), i);
+ for (j = 0; j < len_b; j++) {
+ ptr_b = (ipv4_addr*) g_array_index_ptr(b, sizeof(ipv4_addr), j);
+ if (ipv4_addr_lt(ptr_a, ptr_b))
+ return TRUE;
+ }
+ }
+ return FALSE;
+
+ case TOK_LE:
+ for(i = 0; i < len_a; i++) {
+ ptr_a = (ipv4_addr*) g_array_index_ptr(a, sizeof(ipv4_addr), i);
+ for (j = 0; j < len_b; j++) {
+ ptr_b = (ipv4_addr*) g_array_index_ptr(b, sizeof(ipv4_addr), j);
+ if (ipv4_addr_le(ptr_a, ptr_b))
+ return TRUE;
+ }
+ }
+ return FALSE;
+ }
+
+ g_assert_not_reached();
+ return FALSE;
+}
+
gboolean check_relation_ipv6(gint operand, GArray *a, GArray *b)
{
int i, j, len_a, len_b;