Statistics
| Branch: | Revision:

iof-bird-daemon / lib / ip.c @ 725270cb

History | View | Annotate | Download (6.81 KB)

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" };
31

    
32
  if (scope > SCOPE_UNIVERSE)
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_opposite - return address of point-to-point neighbor
155
 * @x: IP address of our end of the link
156
 *
157
 * ipa_opposite() returns an address of the opposite end of a numbered
158
 * point-to-point link.
159
 *
160
 * This function is available in IPv4 version only.
161
 */
162
ip_addr ipa_opposite(ip_addr x) { DUMMY }
163

164
/**
165
 * ipa_class_mask - guess netmask according to address class
166
 * @x: IP address
167
 *
168
 * This function (available in IPv4 version only) returns a
169
 * network mask according to the address class of @x. Although
170
 * classful addressing is nowadays obsolete, there still live
171
 * routing protocols transferring no prefix lengths nor netmasks
172
 * and this function could be useful to them.
173
 */
174
ip_addr ipa_classify(ip_addr x) { DUMMY }
175

176
/**
177
 * ipa_from_u32 - convert IPv4 address to an integer
178
 * @x: IP address
179
 *
180
 * This function takes an IPv4 address and returns its numeric
181
 * representation.
182
 */
183
u32 ipa_from_u32(ip_addr x) { DUMMY }
184

185
/**
186
 * ipa_to_u32 - convert integer to IPv4 address
187
 * @x: a 32-bit integer
188
 *
189
 * ipa_to_u32() takes a numeric representation of an IPv4 address
190
 * and converts it to the corresponding &ip_addr.
191
 */
192
ip_addr ipa_to_u32(u32 x) { DUMMY }
193

194
/**
195
 * ipa_compare - compare two IP addresses for order
196
 * @x: IP address
197
 * @y: IP address
198
 *
199
 * The ipa_compare() function takes two IP addresses and returns
200
 * -1 if @x is less than @y in canonical ordering (lexicographical
201
 * order of the bit strings), 1 if @x is greater than @y and 0
202
 * if they are the same.
203
 */
204
int ipa_compare(ip_addr x, ip_addr y) { DUMMY }
205

206
/**
207
 * ipa_build - build an IPv6 address from parts
208
 * @a1: part #1
209
 * @a2: part #2
210
 * @a3: part #3
211
 * @a4: part #4
212
 *
213
 * ipa_build() takes @a1 to @a4 and assembles them to a single IPv6
214
 * address. It's used for example when a protocol wants to bind its
215
 * socket to a hard-wired multicast address.
216
 */
217
ip_addr ipa_build(u32 a1, u32 a2, u32 a3, u32 a4) { DUMMY }
218

219
/**
220
 * ipa_absolutize - convert link scope IPv6 address to universe scope
221
 * @x: link scope IPv6 address
222
 * @y: universe scope IPv6 prefix of the interface
223
 *
224
 * This function combines a link-scope IPv6 address @x with the universe
225
 * scope prefix @x of the network assigned to an interface to get a
226
 * universe scope form of @x.
227
 */
228
ip_addr ipa_absolutize(ip_addr x, ip_addr y) { DUMMY }
229

230
/**
231
 * ip_ntop - convert IP address to textual representation
232
 * @a: IP address
233
 * @buf: buffer of size at least %STD_ADDRESS_P_LENGTH
234
 *
235
 * This function takes an IP address and creates its textual
236
 * representation for presenting to the user.
237
 */
238
char *ip_ntop(ip_addr a, char *buf) { DUMMY }
239

240
/**
241
 * ip_ntox - convert IP address to hexadecimal representation
242
 * @a: IP address
243
 * @buf: buffer of size at least %STD_ADDRESS_P_LENGTH
244
 *
245
 * This function takes an IP address and creates its hexadecimal
246
 * textual representation. Primary use: debugging dumps.
247
 */
248
char *ip_ntox(ip_addr a, char *buf) { DUMMY }
249

250
/**
251
 * ip_pton - parse textual representation of IP address
252
 * @a: textual representation
253
 * @o: where to put the resulting address
254
 *
255
 * This function parses a textual IP address representation and
256
 * stores the decoded address to a variable pointed to by @o.
257
 * Returns 0 if a parse error has occurred, else 0.
258
 */
259
int ip_pton(char *a, ip_addr *o) { DUMMY }
260

261
#endif