]> git.ipfire.org Git - thirdparty/bird.git/blob - lib/ip.c
Simplifies val_in_range().
[thirdparty/bird.git] / lib / ip.c
1 /*
2 * BIRD Library -- IP address routines common for IPv4 and IPv6
3 *
4 * (c) 1998--2000 Martin Mares <mj@ucw.cz>
5 *
6 * Can be freely distributed and used under the terms of the GNU GPL.
7 */
8
9 #include "nest/bird.h"
10 #include "lib/ip.h"
11
12 /**
13 * DOC: IP addresses
14 *
15 * BIRD uses its own abstraction of IP address in order to share the same
16 * code for both IPv4 and IPv6. IP addresses are represented as entities
17 * of type &ip_addr which are never to be treated as numbers and instead
18 * they must be manipulated using the following functions and macros.
19 */
20
21 /**
22 * ip_scope_text - get textual representation of address scope
23 * @scope: scope (%SCOPE_xxx)
24 *
25 * Returns a pointer to a textual name of the scope given.
26 */
27 char *
28 ip_scope_text(unsigned scope)
29 {
30 static char *scope_table[] = { "host", "link", "site", "org", "univ", "undef" };
31
32 if (scope > SCOPE_UNDEFINED)
33 return "?";
34 else
35 return scope_table[scope];
36 }
37
38 #if 0
39 /**
40 * ipa_equal - compare two IP addresses for equality
41 * @x: IP address
42 * @y: IP address
43 *
44 * ipa_equal() returns 1 if @x and @y represent the same IP address, else 0.
45 */
46 int ipa_equal(ip_addr x, ip_addr y) { DUMMY }
47
48 /**
49 * ipa_nonzero - test if an IP address is defined
50 * @x: IP address
51 *
52 * ipa_nonzero returns 1 if @x is a defined IP address (not all bits are zero),
53 * else 0.
54 *
55 * The undefined all-zero address is reachable as a |IPA_NONE| macro.
56 */
57 int ipa_nonzero(ip_addr x) { DUMMY }
58
59 /**
60 * ipa_and - compute bitwise and of two IP addresses
61 * @x: IP address
62 * @y: IP address
63 *
64 * This function returns a bitwise and of @x and @y. It's primarily
65 * used for network masking.
66 */
67 ip_addr ipa_and(ip_addr x, ip_addr y) { DUMMY }
68
69 /**
70 * ipa_or - compute bitwise or of two IP addresses
71 * @x: IP address
72 * @y: IP address
73 *
74 * This function returns a bitwise or of @x and @y.
75 */
76 ip_addr ipa_or(ip_addr x, ip_addr y) { DUMMY }
77
78 /**
79 * ipa_xor - compute bitwise xor of two IP addresses
80 * @x: IP address
81 * @y: IP address
82 *
83 * This function returns a bitwise xor of @x and @y.
84 */
85 ip_addr ipa_xor(ip_addr x, ip_addr y) { DUMMY }
86
87 /**
88 * ipa_not - compute bitwise negation of two IP addresses
89 * @x: IP address
90 *
91 * This function returns a bitwise negation of @x.
92 */
93 ip_addr ipa_not(ip_addr x) { DUMMY }
94
95 /**
96 * ipa_mkmask - create a netmask
97 * @x: prefix length
98 *
99 * This function returns an &ip_addr corresponding of a netmask
100 * of an address prefix of size @x.
101 */
102 ip_addr ipa_mkmask(int x) { DUMMY }
103
104 /**
105 * ipa_mkmask - calculate netmask length
106 * @x: IP address
107 *
108 * This function checks whether @x represents a valid netmask and
109 * returns the size of the associate network prefix or -1 for invalid
110 * mask.
111 */
112 int ipa_mklen(ip_addr x) { DUMMY }
113
114 /**
115 * ipa_hash - hash IP addresses
116 * @x: IP address
117 *
118 * ipa_hash() returns a 16-bit hash value of the IP address @x.
119 */
120 int ipa_hash(ip_addr x) { DUMMY }
121
122 /**
123 * ipa_hton - convert IP address to network order
124 * @x: IP address
125 *
126 * Converts the IP address @x to the network byte order.
127 *
128 * Beware, this is a macro and it alters the argument!
129 */
130 void ipa_hton(ip_addr x) { DUMMY }
131
132 /**
133 * ipa_ntoh - convert IP address to host order
134 * @x: IP address
135 *
136 * Converts the IP address @x from the network byte order.
137 *
138 * Beware, this is a macro and it alters the argument!
139 */
140 void ipa_ntoh(ip_addr x) { DUMMY }
141
142 /**
143 * ipa_classify - classify an IP address
144 * @x: IP address
145 *
146 * ipa_classify() returns an address class of @x, that is a bitwise or
147 * of address type (%IADDR_INVALID, %IADDR_HOST, %IADDR_BROADCAST, %IADDR_MULTICAST)
148 * with address scope (%SCOPE_HOST to %SCOPE_UNIVERSE) or -1 (%IADDR_INVALID)
149 * for an invalid address.
150 */
151 int ipa_classify(ip_addr x) { DUMMY }
152
153 /**
154 * ipa_class_mask - guess netmask according to address class
155 * @x: IP address
156 *
157 * This function (available in IPv4 version only) returns a
158 * network mask according to the address class of @x. Although
159 * classful addressing is nowadays obsolete, there still live
160 * routing protocols transferring no prefix lengths nor netmasks
161 * and this function could be useful to them.
162 */
163 ip_addr ipa_class_mask(ip_addr x) { DUMMY }
164
165 /**
166 * ipa_from_u32 - convert IPv4 address to an integer
167 * @x: IP address
168 *
169 * This function takes an IPv4 address and returns its numeric
170 * representation.
171 */
172 u32 ipa_from_u32(ip_addr x) { DUMMY }
173
174 /**
175 * ipa_to_u32 - convert integer to IPv4 address
176 * @x: a 32-bit integer
177 *
178 * ipa_to_u32() takes a numeric representation of an IPv4 address
179 * and converts it to the corresponding &ip_addr.
180 */
181 ip_addr ipa_to_u32(u32 x) { DUMMY }
182
183 /**
184 * ipa_compare - compare two IP addresses for order
185 * @x: IP address
186 * @y: IP address
187 *
188 * The ipa_compare() function takes two IP addresses and returns
189 * -1 if @x is less than @y in canonical ordering (lexicographical
190 * order of the bit strings), 1 if @x is greater than @y and 0
191 * if they are the same.
192 */
193 int ipa_compare(ip_addr x, ip_addr y) { DUMMY }
194
195 /**
196 * ipa_build - build an IPv6 address from parts
197 * @a1: part #1
198 * @a2: part #2
199 * @a3: part #3
200 * @a4: part #4
201 *
202 * ipa_build() takes @a1 to @a4 and assembles them to a single IPv6
203 * address. It's used for example when a protocol wants to bind its
204 * socket to a hard-wired multicast address.
205 */
206 ip_addr ipa_build(u32 a1, u32 a2, u32 a3, u32 a4) { DUMMY }
207
208 /**
209 * ipa_absolutize - convert link scope IPv6 address to universe scope
210 * @x: link scope IPv6 address
211 * @y: universe scope IPv6 prefix of the interface
212 *
213 * This function combines a link-scope IPv6 address @x with the universe
214 * scope prefix @x of the network assigned to an interface to get a
215 * universe scope form of @x.
216 */
217 ip_addr ipa_absolutize(ip_addr x, ip_addr y) { DUMMY }
218
219 /**
220 * ip_ntop - convert IP address to textual representation
221 * @a: IP address
222 * @buf: buffer of size at least %STD_ADDRESS_P_LENGTH
223 *
224 * This function takes an IP address and creates its textual
225 * representation for presenting to the user.
226 */
227 char *ip_ntop(ip_addr a, char *buf) { DUMMY }
228
229 /**
230 * ip_ntox - convert IP address to hexadecimal representation
231 * @a: IP address
232 * @buf: buffer of size at least %STD_ADDRESS_P_LENGTH
233 *
234 * This function takes an IP address and creates its hexadecimal
235 * textual representation. Primary use: debugging dumps.
236 */
237 char *ip_ntox(ip_addr a, char *buf) { DUMMY }
238
239 /**
240 * ip_pton - parse textual representation of IP address
241 * @a: textual representation
242 * @o: where to put the resulting address
243 *
244 * This function parses a textual IP address representation and
245 * stores the decoded address to a variable pointed to by @o.
246 * Returns 0 if a parse error has occurred, else 0.
247 */
248 int ip_pton(char *a, ip_addr *o) { DUMMY }
249
250 #endif