]>
git.proxmox.com Git - mirror_iproute2.git/blob - lib/dnet_ntop.c
9500df86d691302b1e18aa0d4d134a6d005a2584
3 #include <netinet/in.h>
7 static __inline__ u_int16_t
dn_ntohs(u_int16_t addr
)
15 return ((u_int16_t
)u
.byte
[0]) | (((u_int16_t
)u
.byte
[1]) << 8);
18 static __inline__
int do_digit(char *str
, u_int16_t
*addr
, u_int16_t scale
, size_t *pos
, size_t len
, int *started
)
20 u_int16_t tmp
= *addr
/ scale
;
25 if (((tmp
) > 0) || *started
|| (scale
== 1)) {
29 *addr
-= (tmp
* scale
);
36 static const char *dnet_ntop1(const struct dn_naddr
*dna
, char *str
, size_t len
)
38 u_int16_t addr
= dn_ntohs(*(u_int16_t
*)dna
->a_addr
);
39 u_int16_t area
= addr
>> 10;
51 if (do_digit(str
+ pos
, &area
, 10, &pos
, len
, &started
))
54 if (do_digit(str
+ pos
, &area
, 1, &pos
, len
, &started
))
64 if (do_digit(str
+ pos
, &addr
, 1000, &pos
, len
, &started
))
67 if (do_digit(str
+ pos
, &addr
, 100, &pos
, len
, &started
))
70 if (do_digit(str
+ pos
, &addr
, 10, &pos
, len
, &started
))
73 if (do_digit(str
+ pos
, &addr
, 1, &pos
, len
, &started
))
85 const char *dnet_ntop(int af
, const void *addr
, char *str
, size_t len
)
90 return dnet_ntop1((struct dn_naddr
*)addr
, str
, len
);