]>
git.ipfire.org Git - thirdparty/bird.git/blob - lib/ip.c
2 * BIRD Library -- IP address routines common for IPv4 and IPv6
4 * (c) 1998--2000 Martin Mares <mj@ucw.cz>
6 * Can be freely distributed and used under the terms of the GNU GPL.
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.
22 * ip_scope_text - get textual representation of address scope
23 * @scope: scope (%SCOPE_xxx)
25 * Returns a pointer to a textual name of the scope given.
28 ip_scope_text(unsigned scope
)
30 static char *scope_table
[] = { "host", "link", "site", "org", "univ", "undef" };
32 if (scope
> SCOPE_UNDEFINED
)
35 return scope_table
[scope
];
40 * ipa_equal - compare two IP addresses for equality
44 * ipa_equal() returns 1 if @x and @y represent the same IP address, else 0.
46 int ipa_equal(ip_addr x
, ip_addr y
) { DUMMY
}
49 * ipa_nonzero - test if an IP address is defined
52 * ipa_nonzero returns 1 if @x is a defined IP address (not all bits are zero),
55 * The undefined all-zero address is reachable as a |IPA_NONE| macro.
57 int ipa_nonzero(ip_addr x
) { DUMMY
}
60 * ipa_and - compute bitwise and of two IP addresses
64 * This function returns a bitwise and of @x and @y. It's primarily
65 * used for network masking.
67 ip_addr
ipa_and(ip_addr x
, ip_addr y
) { DUMMY
}
70 * ipa_or - compute bitwise or of two IP addresses
74 * This function returns a bitwise or of @x and @y.
76 ip_addr
ipa_or(ip_addr x
, ip_addr y
) { DUMMY
}
79 * ipa_xor - compute bitwise xor of two IP addresses
83 * This function returns a bitwise xor of @x and @y.
85 ip_addr
ipa_xor(ip_addr x
, ip_addr y
) { DUMMY
}
88 * ipa_not - compute bitwise negation of two IP addresses
91 * This function returns a bitwise negation of @x.
93 ip_addr
ipa_not(ip_addr x
) { DUMMY
}
96 * ipa_mkmask - create a netmask
99 * This function returns an &ip_addr corresponding of a netmask
100 * of an address prefix of size @x.
102 ip_addr
ipa_mkmask(int x
) { DUMMY
}
105 * ipa_mkmask - calculate netmask length
108 * This function checks whether @x represents a valid netmask and
109 * returns the size of the associate network prefix or -1 for invalid
112 int ipa_mklen(ip_addr x
) { DUMMY
}
115 * ipa_hash - hash IP addresses
118 * ipa_hash() returns a 16-bit hash value of the IP address @x.
120 int ipa_hash(ip_addr x
) { DUMMY
}
123 * ipa_hton - convert IP address to network order
126 * Converts the IP address @x to the network byte order.
128 * Beware, this is a macro and it alters the argument!
130 void ipa_hton(ip_addr x
) { DUMMY
}
133 * ipa_ntoh - convert IP address to host order
136 * Converts the IP address @x from the network byte order.
138 * Beware, this is a macro and it alters the argument!
140 void ipa_ntoh(ip_addr x
) { DUMMY
}
143 * ipa_classify - classify an IP address
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.
151 int ipa_classify(ip_addr x
) { DUMMY
}
154 * ipa_class_mask - guess netmask according to address class
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.
163 ip_addr
ipa_class_mask(ip_addr x
) { DUMMY
}
166 * ipa_from_u32 - convert IPv4 address to an integer
169 * This function takes an IPv4 address and returns its numeric
172 u32
ipa_from_u32(ip_addr x
) { DUMMY
}
175 * ipa_to_u32 - convert integer to IPv4 address
176 * @x: a 32-bit integer
178 * ipa_to_u32() takes a numeric representation of an IPv4 address
179 * and converts it to the corresponding &ip_addr.
181 ip_addr
ipa_to_u32(u32 x
) { DUMMY
}
184 * ipa_compare - compare two IP addresses for order
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.
193 int ipa_compare(ip_addr x
, ip_addr y
) { DUMMY
}
196 * ipa_build - build an IPv6 address from parts
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.
206 ip_addr
ipa_build(u32 a1
, u32 a2
, u32 a3
, u32 a4
) { DUMMY
}
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
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.
217 ip_addr
ipa_absolutize(ip_addr x
, ip_addr y
) { DUMMY
}
220 * ip_ntop - convert IP address to textual representation
222 * @buf: buffer of size at least %STD_ADDRESS_P_LENGTH
224 * This function takes an IP address and creates its textual
225 * representation for presenting to the user.
227 char *ip_ntop(ip_addr a
, char *buf
) { DUMMY
}
230 * ip_ntox - convert IP address to hexadecimal representation
232 * @buf: buffer of size at least %STD_ADDRESS_P_LENGTH
234 * This function takes an IP address and creates its hexadecimal
235 * textual representation. Primary use: debugging dumps.
237 char *ip_ntox(ip_addr a
, char *buf
) { DUMMY
}
240 * ip_pton - parse textual representation of IP address
241 * @a: textual representation
242 * @o: where to put the resulting address
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.
248 int ip_pton(char *a
, ip_addr
*o
) { DUMMY
}