Create a more modular type system for the FT_* types. Put them
[obnox/wireshark/wip.git] / epan / ftypes / ftype-ipv4.c
1
2 #ifdef HAVE_CONFIG_H
3 #include "config.h"
4 #endif
5
6 #include <ftypes-int.h>
7 #include "ipv4.h"
8 #include "resolv.h"
9
10 static void
11 ftype_from_tvbuff(field_info *fi, tvbuff_t *tvb, int start, int length,
12         gboolean little_endian)
13 {
14         /* XXX */
15         g_assert_not_reached();
16 }
17
18
19
20 static void
21 set_integer(fvalue_t *fv, guint32 value)
22 {
23         ipv4_addr_set_net_order_addr(&(fv->value.ipv4), value);
24         ipv4_addr_set_netmask_bits(&(fv->value.ipv4), 32);
25 }
26
27 static gpointer
28 value_get(fvalue_t *fv)
29 {
30         return &(fv->value.ipv4);
31 }
32
33 static gboolean
34 val_from_string(fvalue_t *fv, char *s, LogFunc log)
35 {
36         guint32 addr;
37
38         if (!get_host_ipaddr(s, &addr)) {
39                 log("\"%s\" is not a valid hostname or IPv4 address.", s);
40                 return FALSE;
41         }
42         ipv4_addr_set_host_order_addr(&(fv->value.ipv4), addr);
43         /*ipv4_addr_set_netmask_bits(&node->value.ipv4, nmask_bits);*/
44         ipv4_addr_set_netmask_bits(&(fv->value.ipv4), 32);
45         return TRUE;
46 }
47
48 static gboolean
49 cmp_eq(fvalue_t *a, fvalue_t *b)
50 {
51         return ipv4_addr_eq(&a->value.ipv4, &b->value.ipv4);
52 }
53
54 static gboolean
55 cmp_ne(fvalue_t *a, fvalue_t *b)
56 {
57         return ipv4_addr_ne(&a->value.ipv4, &b->value.ipv4);
58 }
59
60 static gboolean
61 cmp_gt(fvalue_t *a, fvalue_t *b)
62 {
63         return ipv4_addr_gt(&a->value.ipv4, &b->value.ipv4);
64 }
65
66 static gboolean
67 cmp_ge(fvalue_t *a, fvalue_t *b)
68 {
69         return ipv4_addr_ge(&a->value.ipv4, &b->value.ipv4);
70 }
71
72 static gboolean
73 cmp_lt(fvalue_t *a, fvalue_t *b)
74 {
75         return ipv4_addr_lt(&a->value.ipv4, &b->value.ipv4);
76 }
77
78 static gboolean
79 cmp_le(fvalue_t *a, fvalue_t *b)
80 {
81         return ipv4_addr_le(&a->value.ipv4, &b->value.ipv4);
82 }
83
84 void
85 ftype_register_ipv4(void)
86 {
87
88         static ftype_t ipv4_type = {
89                 "FT_IPv4",
90                 "IPv4 address",
91                 4,
92                 NULL,
93                 NULL,
94                 ftype_from_tvbuff,
95                 val_from_string,
96
97                 NULL,
98                 set_integer,
99                 NULL,
100
101                 value_get,
102                 NULL,
103                 NULL,
104
105                 cmp_eq,
106                 cmp_ne,
107                 cmp_gt,
108                 cmp_ge,
109                 cmp_lt,
110                 cmp_le,
111         };
112
113         ftype_register(FT_IPv4, &ipv4_type);
114 }