blob: 1e46bc219051af80a8a3e7518c101899334bcaef [file] [log] [blame]
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +00001#include <errno.h>
2#include <sys/types.h>
Strake5bd9dd42012-12-23 08:46:04 -05003#include <sys/socket.h>
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +00004#include <netinet/in.h>
5
6#include "utils.h"
7
8static __inline__ int do_digit(char *str, u_int32_t addr, u_int32_t scale, size_t *pos, size_t len)
9{
10 u_int32_t tmp = addr >> (scale * 4);
11
12 if (*pos == len)
13 return 1;
14
15 tmp &= 0x0f;
16 if (tmp > 9)
17 *str = tmp + 'A' - 10;
18 else
19 *str = tmp + '0';
20 (*pos)++;
21
22 return 0;
23}
24
25static const char *ipx_ntop1(const struct ipx_addr *addr, char *str, size_t len)
26{
27 int i;
28 size_t pos = 0;
29
30 if (len == 0)
31 return str;
32
33 for(i = 7; i >= 0; i--)
34 if (do_digit(str + pos, ntohl(addr->ipx_net), i, &pos, len))
35 return str;
36
37 if (pos == len)
38 return str;
39
40 *(str + pos) = '.';
41 pos++;
Stephen Hemmingerae665a52006-12-05 10:10:22 -080042
osdl.org!shemmingeraba5acd2004-04-15 20:56:59 +000043 for(i = 0; i < 6; i++) {
44 if (do_digit(str + pos, addr->ipx_node[i], 1, &pos, len))
45 return str;
46 if (do_digit(str + pos, addr->ipx_node[i], 0, &pos, len))
47 return str;
48 }
49
50 if (pos == len)
51 return str;
52
53 *(str + pos) = 0;
54
55 return str;
56}
57
58
59const char *ipx_ntop(int af, const void *addr, char *str, size_t len)
60{
61 switch(af) {
62 case AF_IPX:
63 errno = 0;
64 return ipx_ntop1((struct ipx_addr *)addr, str, len);
65 default:
66 errno = EAFNOSUPPORT;
67 }
68
69 return NULL;
70}
71
72