Accept strings in standard Internet notation (except the broadcast
address). git-svn-id: svn://svn.h5l.se/heimdal/trunk/heimdal@1750 ec53bebd-3082-4978-b11e-865c3cabbd6b
This commit is contained in:
@@ -57,30 +57,12 @@ RCSID("$Id$");
|
||||
#include <arpa/inet.h>
|
||||
#endif
|
||||
|
||||
/* Minimal implementation of inet_aton. Doesn't handle hex numbers. */
|
||||
/* Minimal implementation of inet_aton.
|
||||
* Cannot distinguish between failure and a local broadcast address. */
|
||||
|
||||
int inet_aton(const char *cp, struct in_addr *adr)
|
||||
int
|
||||
inet_aton(const char *cp, struct in_addr *addr)
|
||||
{
|
||||
unsigned int a, b, c, d;
|
||||
|
||||
int num;
|
||||
|
||||
num = sscanf(cp, "%u.%u.%u.%u", &a, &b, &c, &d);
|
||||
|
||||
if(num < 2)
|
||||
return 0;
|
||||
|
||||
if(num == 2){
|
||||
c = b & 0xffff;
|
||||
b = b >> 16;
|
||||
}
|
||||
if(num < 4){
|
||||
d = c & 0xff;
|
||||
c = c >> 8;
|
||||
}
|
||||
|
||||
if(a > 255 || b > 255 || c > 255 || d > 255)
|
||||
return 0;
|
||||
adr->s_addr = htonl((a << 24) | (b << 16) | (c << 8) | d);
|
||||
return 1;
|
||||
addr->s_addr = inet_addr(cp);
|
||||
return (addr->s_addr == INADDR_NONE) ? 0 : 1;
|
||||
}
|
||||
|
Reference in New Issue
Block a user