]> CyberLeo.Net >> Repos - FreeBSD/FreeBSD.git/blob - contrib/ntp/libntp/decodenetnum.c
This commit was generated by cvs2svn to compensate for changes in r159952,
[FreeBSD/FreeBSD.git] / contrib / ntp / libntp / decodenetnum.c
1 /*
2  * decodenetnum - return a net number (this is crude, but careful)
3  */
4 #include <sys/types.h>
5 #include <ctype.h>
6 #include <sys/socket.h>
7 #include <netinet/in.h>
8 #include <netdb.h>
9
10 #include "ntp_stdlib.h"
11
12 int
13 decodenetnum(
14         const char *num,
15         struct sockaddr_storage *netnum
16         )
17 {
18         struct addrinfo hints, *ai = NULL;
19         register int err, i;
20         register const char *cp;
21         char name[80];
22
23         cp = num;
24
25         if (*cp == '[') {
26                 cp++;
27                 for (i = 0; *cp != ']'; cp++, i++)
28                         name[i] = *cp;
29         name[i] = '\0';
30         num = name; 
31         }
32         memset(&hints, 0, sizeof(struct addrinfo));
33         hints.ai_flags = AI_NUMERICHOST;
34         err = getaddrinfo(num, NULL, &hints, &ai);
35         if (err != 0)
36                 return 0;
37         memcpy(netnum, (struct sockaddr_storage *)ai->ai_addr, ai->ai_addrlen); 
38         freeaddrinfo(ai);
39         return 1;
40 }