Sync usage with man page.
[netbsd-mini2440.git] / dist / ntp / libntp / decodenetnum.c
blob6d64744c3a1faadd2ef93c34435d4b90e70cf9b4
1 /* $NetBSD: decodenetnum.c,v 1.2 2003/12/04 16:23:36 drochner Exp $ */
3 /*
4 * decodenetnum - return a net number (this is crude, but careful)
5 */
6 #include <sys/types.h>
7 #include <ctype.h>
8 #include <sys/socket.h>
9 #include <netinet/in.h>
11 #include "ntp_stdlib.h"
13 int
14 decodenetnum(
15 const char *num,
16 struct sockaddr_storage *netnum
19 struct addrinfo hints, *ai = NULL;
20 register int err, i;
21 register const char *cp;
22 char name[80];
24 cp = num;
26 if (*cp == '[') {
27 cp++;
28 for (i = 0; *cp != ']'; cp++, i++)
29 name[i] = *cp;
30 name[i] = '\0';
31 num = name;
33 memset(&hints, 0, sizeof(struct addrinfo));
34 hints.ai_flags = AI_NUMERICHOST;
35 err = getaddrinfo(num, NULL, &hints, &ai);
36 if (err != 0)
37 return 0;
38 memcpy(netnum, (struct sockaddr_storage *)ai->ai_addr, ai->ai_addrlen);
39 freeaddrinfo(ai);
40 return 1;