X-Git-Url: https://git.proxmox.com/?a=blobdiff_plain;f=lib%2Fipx_ntop.c;h=b2d67902546fb4352a6f517a8afcb1a2925086cb;hb=aba5acdfdb347d2c21fc67d613d83d4430ca3937;hp=e69de29bb2d1d6434b8b29ae775ad8c2e48c5391;hpb=86fdf0e47be697587efcf9602cd1f952a1d73170;p=mirror_iproute2.git diff --git a/lib/ipx_ntop.c b/lib/ipx_ntop.c index e69de29b..b2d67902 100644 --- a/lib/ipx_ntop.c +++ b/lib/ipx_ntop.c @@ -0,0 +1,71 @@ +#include +#include +#include + +#include "utils.h" + +static __inline__ int do_digit(char *str, u_int32_t addr, u_int32_t scale, size_t *pos, size_t len) +{ + u_int32_t tmp = addr >> (scale * 4); + + if (*pos == len) + return 1; + + tmp &= 0x0f; + if (tmp > 9) + *str = tmp + 'A' - 10; + else + *str = tmp + '0'; + (*pos)++; + + return 0; +} + +static const char *ipx_ntop1(const struct ipx_addr *addr, char *str, size_t len) +{ + int i; + size_t pos = 0; + + if (len == 0) + return str; + + for(i = 7; i >= 0; i--) + if (do_digit(str + pos, ntohl(addr->ipx_net), i, &pos, len)) + return str; + + if (pos == len) + return str; + + *(str + pos) = '.'; + pos++; + + for(i = 0; i < 6; i++) { + if (do_digit(str + pos, addr->ipx_node[i], 1, &pos, len)) + return str; + if (do_digit(str + pos, addr->ipx_node[i], 0, &pos, len)) + return str; + } + + if (pos == len) + return str; + + *(str + pos) = 0; + + return str; +} + + +const char *ipx_ntop(int af, const void *addr, char *str, size_t len) +{ + switch(af) { + case AF_IPX: + errno = 0; + return ipx_ntop1((struct ipx_addr *)addr, str, len); + default: + errno = EAFNOSUPPORT; + } + + return NULL; +} + +