Try to improve the "Kerberos requested but not OpenSSL" message.
[jelmer/wireshark.git] / epan / ipv4.c
1 /* ipv4.c
2  *
3  * IPv4 address class. They understand how to take netmasks into consideration
4  * during equivalence testing.
5  *
6  * Gilbert Ramirez <gram@alumni.rice.edu>
7  *
8  * Wireshark - Network traffic analyzer
9  * By Gerald Combs <gerald@wireshark.org>
10  * Copyright 1998 Gerald Combs
11  *
12  * This program is free software; you can redistribute it and/or
13  * modify it under the terms of the GNU General Public License
14  * as published by the Free Software Foundation; either version 2
15  * of the License, or (at your option) any later version.
16  *
17  * This program is distributed in the hope that it will be useful,
18  * but WITHOUT ANY WARRANTY; without even the implied warranty of
19  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
20  * GNU General Public License for more details.
21  *
22  * You should have received a copy of the GNU General Public License
23  * along with this program; if not, write to the Free Software
24  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
25  */
26
27 #include "config.h"
28
29 #include <glib.h>
30 #include <stdio.h>
31
32 #include "ipv4.h"
33 #include "to_str.h"
34 #include "addr_and_mask.h"
35
36
37 ipv4_addr*
38 ipv4_addr_new(void)
39 {
40         ipv4_addr       *ipv4;
41
42         ipv4 = g_new(ipv4_addr, 1);
43         return ipv4;
44 }
45
46 void
47 ipv4_addr_free(ipv4_addr *ipv4)
48 {
49         g_free(ipv4);
50 }
51
52 void
53 ipv4_addr_set_host_order_addr(ipv4_addr *ipv4, const guint32 new_addr)
54 {
55         ipv4->addr = new_addr;
56 }
57
58 void
59 ipv4_addr_set_net_order_addr(ipv4_addr *ipv4, const guint32 new_addr)
60 {
61         ipv4->addr = g_ntohl(new_addr);
62 }
63
64 void
65 ipv4_addr_set_netmask_bits(ipv4_addr *ipv4, const guint new_nmask_bits)
66 {
67         ipv4->nmask = ip_get_subnet_mask(new_nmask_bits);
68 }
69
70 guint32
71 ipv4_get_net_order_addr(ipv4_addr *ipv4)
72 {
73         return g_htonl(ipv4->addr);
74 }
75
76 guint32
77 ipv4_get_host_order_addr(ipv4_addr *ipv4)
78 {
79         return ipv4->addr;
80 }
81
82 /* We're assuming the buffer is at least MAX_IP_STR_LEN (16 bytes) */
83 void
84 ipv4_addr_str_buf(const ipv4_addr *ipv4, gchar *buf)
85 {
86         guint32 ipv4_host_order = g_htonl(ipv4->addr);
87         ip_to_str_buf((guint8*)&ipv4_host_order, buf, MAX_IP_STR_LEN);
88 }
89
90
91
92 /*
93  * w.x.y.z/32 eq w.x.y.0/24    TRUE
94  */
95
96 /* Returns TRUE if equal, FALSE if not */
97 gboolean
98 ipv4_addr_eq(const ipv4_addr *a, const ipv4_addr *b)
99 {
100         guint32 val_a, val_b, nmask;
101
102         nmask = MIN(a->nmask, b->nmask);
103         val_a = a->addr & nmask;
104         val_b = b->addr & nmask;
105         return (val_a == val_b);
106 }
107
108 gboolean
109 ipv4_addr_gt(const ipv4_addr *a, const ipv4_addr *b)
110 {
111         guint32 val_a, val_b, nmask;
112
113         nmask = MIN(a->nmask, b->nmask);
114         val_a = a->addr & nmask;
115         val_b = b->addr & nmask;
116
117         return (val_a > val_b);
118 }
119
120 gboolean
121 ipv4_addr_ge(const ipv4_addr *a, const ipv4_addr *b)
122 {
123         guint32 val_a, val_b, nmask;
124
125         nmask = MIN(a->nmask, b->nmask);
126         val_a = a->addr & nmask;
127         val_b = b->addr & nmask;
128
129         return (val_a >= val_b);
130 }
131
132 gboolean
133 ipv4_addr_lt(const ipv4_addr *a, const ipv4_addr *b)
134 {
135         guint32 val_a, val_b, nmask;
136
137         nmask = MIN(a->nmask, b->nmask);
138         val_a = a->addr & nmask;
139         val_b = b->addr & nmask;
140
141         return (val_a < val_b);
142 }
143
144 gboolean
145 ipv4_addr_le(const ipv4_addr *a, const ipv4_addr *b)
146 {
147         guint32 val_a, val_b, nmask;
148
149         nmask = MIN(a->nmask, b->nmask);
150         val_a = a->addr & nmask;
151         val_b = b->addr & nmask;
152
153         return (val_a <= val_b);
154 }