1999-12-09 13:01:21 +00:00
|
|
|
/*
|
|
|
|
* decodenetnum - return a net number (this is crude, but careful)
|
|
|
|
*/
|
|
|
|
#include <sys/types.h>
|
|
|
|
#include <ctype.h>
|
|
|
|
#include <sys/socket.h>
|
|
|
|
#include <netinet/in.h>
|
|
|
|
|
|
|
|
#include "ntp_stdlib.h"
|
|
|
|
|
|
|
|
int
|
|
|
|
decodenetnum(
|
|
|
|
const char *num,
|
2004-07-20 15:01:56 +00:00
|
|
|
struct sockaddr_storage *netnum
|
1999-12-09 13:01:21 +00:00
|
|
|
)
|
|
|
|
{
|
2004-07-20 15:01:56 +00:00
|
|
|
struct addrinfo hints, *ai = NULL;
|
|
|
|
register int err, i;
|
1999-12-09 13:01:21 +00:00
|
|
|
register const char *cp;
|
2004-07-20 15:01:56 +00:00
|
|
|
char name[80];
|
1999-12-09 13:01:21 +00:00
|
|
|
|
|
|
|
cp = num;
|
|
|
|
|
|
|
|
if (*cp == '[') {
|
|
|
|
cp++;
|
2004-07-20 15:01:56 +00:00
|
|
|
for (i = 0; *cp != ']'; cp++, i++)
|
|
|
|
name[i] = *cp;
|
|
|
|
name[i] = '\0';
|
|
|
|
num = name;
|
1999-12-09 13:01:21 +00:00
|
|
|
}
|
2004-07-20 15:01:56 +00:00
|
|
|
memset(&hints, 0, sizeof(struct addrinfo));
|
|
|
|
hints.ai_flags = AI_NUMERICHOST;
|
|
|
|
err = getaddrinfo(num, NULL, &hints, &ai);
|
|
|
|
if (err != 0)
|
|
|
|
return 0;
|
|
|
|
memcpy(netnum, (struct sockaddr_storage *)ai->ai_addr, ai->ai_addrlen);
|
|
|
|
freeaddrinfo(ai);
|
1999-12-09 13:01:21 +00:00
|
|
|
return 1;
|
|
|
|
}
|