]>
git.ipfire.org Git - thirdparty/bird.git/blob - lib/ipv4.c
2 * BIRD Library -- IPv4 Address Manipulation Functions
4 * (c) 1998 Martin Mares <mj@ucw.cz>
6 * Can be freely distributed and used under the terms of the GNU GPL.
11 #include "nest/bird.h"
13 #include "lib/string.h"
23 return IADDR_HOST
| SCOPE_HOST
;
25 (a
& 0xffff0000) == 0xc0a80000 ||
26 (a
& 0xfff00000) == 0xac100000)
27 return IADDR_HOST
| SCOPE_SITE
;
29 return IADDR_HOST
| SCOPE_UNIVERSE
;
31 if (b
>= 0xe0 && b
<= 0xef)
32 return IADDR_MULTICAST
| SCOPE_UNIVERSE
;
34 return IADDR_BROADCAST
| SCOPE_LINK
;
39 ip_ntop(ip_addr a
, char *b
)
43 return b
+ bsprintf(b
, "%d.%d.%d.%d",
51 ip_ntox(ip_addr a
, char *b
)
53 return b
+ bsprintf(b
, "%08x", _I(a
));
57 ipv4_class_mask(u32 a
)
63 else if (a
< 0xc0000000)
73 ip_pton(char *a
, ip_addr
*o
)
82 char *d
, *c
= strchr(a
, '.');
85 l
= strtoul(a
, &d
, 10);
86 if (d
!= c
&& *d
|| l
> 255)
93 *o
= ipa_from_u32(ia
);
98 ipv4_skip_header(byte
*pkt
, int *len
)
103 if (l
< 20 || (*pkt
& 0xf0) != 0x40)
105 q
= (*pkt
& 0x0f) * 4;