Implemented ip_pton()

This commit is contained in:
Martin Mares 1998-11-27 19:29:27 +00:00
parent a3afae585a
commit dfeef5d8bb
2 changed files with 29 additions and 0 deletions

View file

@ -49,5 +49,6 @@
char *ip_ntop(ip_addr a, char *); char *ip_ntop(ip_addr a, char *);
char *ip_ntox(ip_addr a, char *); char *ip_ntox(ip_addr a, char *);
int ip_pton(char *a, ip_addr *o);
#endif #endif

View file

@ -8,6 +8,9 @@
#ifndef IPV6 #ifndef IPV6
#include <string.h>
#include <stdlib.h>
#include "nest/bird.h" #include "nest/bird.h"
#include "lib/ip.h" #include "lib/ip.h"
#include "lib/string.h" #include "lib/string.h"
@ -65,4 +68,29 @@ ipv4_class_mask(u32 a)
return m; 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 #endif