Busybox: Upgrade to 1.21.1 (stable). lsof active.
[tomato.git] / release / src / router / iproute2 / lib / ipx_pton.c
blob1a52b7f1a58f9633b9c93eb2d5cda85139df7d8a
1 #include <errno.h>
2 #include <string.h>
3 #include <sys/types.h>
4 #include <netinet/in.h>
6 #include "utils.h"
8 static u_int32_t hexget(char c)
10 if (c >= 'A' && c <= 'F')
11 return c - 'A' + 10;
12 if (c >= 'a' && c <= 'f')
13 return c - 'a' + 10;
14 if (c >= '0' && c <= '9')
15 return c - '0';
17 return 0xf0;
20 static int ipx_getnet(u_int32_t *net, const char *str)
22 int i;
23 u_int32_t tmp;
25 for(i = 0; *str && (i < 8); i++) {
27 if ((tmp = hexget(*str)) & 0xf0) {
28 if (*str == '.')
29 return 0;
30 else
31 return -1;
34 str++;
35 (*net) <<= 4;
36 (*net) |= tmp;
39 if (*str == 0)
40 return 0;
42 return -1;
45 static int ipx_getnode(u_int8_t *node, const char *str)
47 int i;
48 u_int32_t tmp;
50 for(i = 0; i < 6; i++) {
51 if ((tmp = hexget(*str++)) & 0xf0)
52 return -1;
53 node[i] = (u_int8_t)tmp;
54 node[i] <<= 4;
55 if ((tmp = hexget(*str++)) & 0xf0)
56 return -1;
57 node[i] |= (u_int8_t)tmp;
58 if (*str == ':')
59 str++;
62 return 0;
65 static int ipx_pton1(const char *src, struct ipx_addr *addr)
67 char *sep = (char *)src;
68 int no_node = 0;
70 memset(addr, 0, sizeof(struct ipx_addr));
72 while(*sep && (*sep != '.'))
73 sep++;
75 if (*sep != '.')
76 no_node = 1;
78 if (ipx_getnet(&addr->ipx_net, src))
79 return 0;
81 addr->ipx_net = htonl(addr->ipx_net);
83 if (no_node)
84 return 1;
86 if (ipx_getnode(addr->ipx_node, sep + 1))
87 return 0;
89 return 1;
92 int ipx_pton(int af, const char *src, void *addr)
94 int err;
96 switch (af) {
97 case AF_IPX:
98 errno = 0;
99 err = ipx_pton1(src, (struct ipx_addr *)addr);
100 break;
101 default:
102 errno = EAFNOSUPPORT;
103 err = -1;
106 return err;