]>
Commit | Line | Data |
---|---|---|
6054c1eb | 1 | /* SPDX-License-Identifier: GPL-2.0 */ |
aba5acdf SH |
2 | #include <errno.h> |
3 | #include <sys/types.h> | |
5bd9dd49 | 4 | #include <sys/socket.h> |
aba5acdf SH |
5 | #include <netinet/in.h> |
6 | ||
7 | #include "utils.h" | |
8 | ||
9 | static __inline__ int do_digit(char *str, u_int32_t addr, u_int32_t scale, size_t *pos, size_t len) | |
10 | { | |
11 | u_int32_t tmp = addr >> (scale * 4); | |
12 | ||
13 | if (*pos == len) | |
14 | return 1; | |
15 | ||
16 | tmp &= 0x0f; | |
17 | if (tmp > 9) | |
18 | *str = tmp + 'A' - 10; | |
19 | else | |
20 | *str = tmp + '0'; | |
21 | (*pos)++; | |
22 | ||
23 | return 0; | |
24 | } | |
25 | ||
26 | static const char *ipx_ntop1(const struct ipx_addr *addr, char *str, size_t len) | |
27 | { | |
28 | int i; | |
29 | size_t pos = 0; | |
30 | ||
31 | if (len == 0) | |
32 | return str; | |
33 | ||
34 | for(i = 7; i >= 0; i--) | |
35 | if (do_digit(str + pos, ntohl(addr->ipx_net), i, &pos, len)) | |
36 | return str; | |
37 | ||
38 | if (pos == len) | |
39 | return str; | |
40 | ||
41 | *(str + pos) = '.'; | |
42 | pos++; | |
ae665a52 | 43 | |
aba5acdf SH |
44 | for(i = 0; i < 6; i++) { |
45 | if (do_digit(str + pos, addr->ipx_node[i], 1, &pos, len)) | |
46 | return str; | |
47 | if (do_digit(str + pos, addr->ipx_node[i], 0, &pos, len)) | |
48 | return str; | |
49 | } | |
50 | ||
51 | if (pos == len) | |
52 | return str; | |
53 | ||
54 | *(str + pos) = 0; | |
55 | ||
56 | return str; | |
57 | } | |
58 | ||
59 | ||
60 | const char *ipx_ntop(int af, const void *addr, char *str, size_t len) | |
61 | { | |
62 | switch(af) { | |
63 | case AF_IPX: | |
64 | errno = 0; | |
65 | return ipx_ntop1((struct ipx_addr *)addr, str, len); | |
66 | default: | |
67 | errno = EAFNOSUPPORT; | |
68 | } | |
69 | ||
70 | return NULL; | |
71 | } |