diff options
author | Martin Mares <mj@ucw.cz> | 1998-07-10 10:38:29 +0200 |
---|---|---|
committer | Martin Mares <mj@ucw.cz> | 1998-07-10 10:38:29 +0200 |
commit | 786d0bb9e7c5db5104e3fd0ff7fdfbd1e19844ea (patch) | |
tree | ed0caedabb17318a5d1207097eecbf34c65e8d10 /lib/ipv4.c | |
parent | 28a9a189d71ef3b05daa21d60277149edb8e98ad (diff) | |
download | bird-786d0bb9e7c5db5104e3fd0ff7fdfbd1e19844ea.tar bird-786d0bb9e7c5db5104e3fd0ff7fdfbd1e19844ea.zip |
Added ipa_class_mask() which guesses netmask for classful addressing.
For pure A/B/C class addresses it just returns the class netmask, for
subnets it tries to guess subnet mask. Please make sure the address
you pass to this function is really a valid host address (i.e., call
ipa_validate() first).
Diffstat (limited to 'lib/ipv4.c')
-rw-r--r-- | lib/ipv4.c | 17 |
1 files changed, 16 insertions, 1 deletions
@@ -43,11 +43,26 @@ ip_ntop(ip_addr a, char *b) (x & 0xff)); } - char * ip_ntox(ip_addr a, char *b) { return b + bsprintf(b, "%08x", _I(a)); } +u32 +ipv4_class_mask(u32 a) +{ + u32 m; + + if (a < 0x80000000) + m = 0xff000000; + if (a < 0xc0000000) + m = 0xffff0000; + else + m = 0xffffff00; + while (a & ~m) + m |= m >> 1; + return m; +} + #endif |