summaryrefslogtreecommitdiff
path: root/polux/application/iproute2/lib/ipx_pton.c
diff options
context:
space:
mode:
authorJean-Philippe SAVE2012-02-20 16:38:56 +0100
committerJean-Philippe SAVE2012-02-20 16:38:56 +0100
commit55a15cc820e926219ebce47218ce1e2f35bb0c48 (patch)
treedba3ff39a766e47859ab7fd837d8da5d30b56b1f /polux/application/iproute2/lib/ipx_pton.c
parent1353d3215782b997fdec3f9182cbda547d92d7e9 (diff)
parentcfc4d43d4d19c398d994b75cb1eeda3c499bd234 (diff)
Add polux base by subtree merge
Diffstat (limited to 'polux/application/iproute2/lib/ipx_pton.c')
-rw-r--r--polux/application/iproute2/lib/ipx_pton.c107
1 files changed, 107 insertions, 0 deletions
diff --git a/polux/application/iproute2/lib/ipx_pton.c b/polux/application/iproute2/lib/ipx_pton.c
new file mode 100644
index 0000000000..1a52b7f1a5
--- /dev/null
+++ b/polux/application/iproute2/lib/ipx_pton.c
@@ -0,0 +1,107 @@
+#include <errno.h>
+#include <string.h>
+#include <sys/types.h>
+#include <netinet/in.h>
+
+#include "utils.h"
+
+static u_int32_t hexget(char c)
+{
+ if (c >= 'A' && c <= 'F')
+ return c - 'A' + 10;
+ if (c >= 'a' && c <= 'f')
+ return c - 'a' + 10;
+ if (c >= '0' && c <= '9')
+ return c - '0';
+
+ return 0xf0;
+}
+
+static int ipx_getnet(u_int32_t *net, const char *str)
+{
+ int i;
+ u_int32_t tmp;
+
+ for(i = 0; *str && (i < 8); i++) {
+
+ if ((tmp = hexget(*str)) & 0xf0) {
+ if (*str == '.')
+ return 0;
+ else
+ return -1;
+ }
+
+ str++;
+ (*net) <<= 4;
+ (*net) |= tmp;
+ }
+
+ if (*str == 0)
+ return 0;
+
+ return -1;
+}
+
+static int ipx_getnode(u_int8_t *node, const char *str)
+{
+ int i;
+ u_int32_t tmp;
+
+ for(i = 0; i < 6; i++) {
+ if ((tmp = hexget(*str++)) & 0xf0)
+ return -1;
+ node[i] = (u_int8_t)tmp;
+ node[i] <<= 4;
+ if ((tmp = hexget(*str++)) & 0xf0)
+ return -1;
+ node[i] |= (u_int8_t)tmp;
+ if (*str == ':')
+ str++;
+ }
+
+ return 0;
+}
+
+static int ipx_pton1(const char *src, struct ipx_addr *addr)
+{
+ char *sep = (char *)src;
+ int no_node = 0;
+
+ memset(addr, 0, sizeof(struct ipx_addr));
+
+ while(*sep && (*sep != '.'))
+ sep++;
+
+ if (*sep != '.')
+ no_node = 1;
+
+ if (ipx_getnet(&addr->ipx_net, src))
+ return 0;
+
+ addr->ipx_net = htonl(addr->ipx_net);
+
+ if (no_node)
+ return 1;
+
+ if (ipx_getnode(addr->ipx_node, sep + 1))
+ return 0;
+
+ return 1;
+}
+
+int ipx_pton(int af, const char *src, void *addr)
+{
+ int err;
+
+ switch (af) {
+ case AF_IPX:
+ errno = 0;
+ err = ipx_pton1(src, (struct ipx_addr *)addr);
+ break;
+ default:
+ errno = EAFNOSUPPORT;
+ err = -1;
+ }
+
+ return err;
+}