summaryrefslogtreecommitdiffstats
path: root/lib
diff options
context:
space:
mode:
authorMartin Mares <mj@ucw.cz>1998-11-27 20:29:27 +0100
committerMartin Mares <mj@ucw.cz>1998-11-27 20:29:27 +0100
commitdfeef5d8bb9fe19cb44d4121fd8324179a38b7a0 (patch)
treede2dd54f7d4ce687d80f8f16d1e721c09b330d71 /lib
parenta3afae585af9a544f919a95509107aae33fbe53c (diff)
downloadbird-dfeef5d8bb9fe19cb44d4121fd8324179a38b7a0.tar
bird-dfeef5d8bb9fe19cb44d4121fd8324179a38b7a0.zip
Implemented ip_pton()
Diffstat (limited to 'lib')
-rw-r--r--lib/ip.h1
-rw-r--r--lib/ipv4.c28
2 files changed, 29 insertions, 0 deletions
diff --git a/lib/ip.h b/lib/ip.h
index 2e9c8a5..1bce89f 100644
--- a/lib/ip.h
+++ b/lib/ip.h
@@ -49,5 +49,6 @@
char *ip_ntop(ip_addr a, char *);
char *ip_ntox(ip_addr a, char *);
+int ip_pton(char *a, ip_addr *o);
#endif
diff --git a/lib/ipv4.c b/lib/ipv4.c
index 5ec2ffb..54e1adb 100644
--- a/lib/ipv4.c
+++ b/lib/ipv4.c
@@ -8,6 +8,9 @@
#ifndef IPV6
+#include <string.h>
+#include <stdlib.h>
+
#include "nest/bird.h"
#include "lib/ip.h"
#include "lib/string.h"
@@ -65,4 +68,29 @@ ipv4_class_mask(u32 a)
return m;
}
+int
+ip_pton(char *a, ip_addr *o)
+{
+ int i,j;
+ unsigned long int l;
+ u32 ia = 0;
+
+ i=4;
+ while (i--)
+ {
+ char *d, *c = strchr(a, '.');
+ if (!c != !i)
+ return 0;
+ if (c)
+ *c++ = 0;
+ l = strtoul(a, &d, 10);
+ if (d && *d || l > 255)
+ return 0;
+ ia = (ia << 8) | l;
+ a = c;
+ }
+ *o = ipa_from_u32(ia);
+ return 1;
+}
+
#endif