1 '\" te
2 .\" Copyright (c) 2007, Sun Microsystems, Inc. All Rights Reserved.
3 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
4 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
5 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
6 .TH GETIPNODEBYNAME 3SOCKET "Aug 22, 2007"
7 .SH NAME
8 getipnodebyname, getipnodebyaddr, freehostent \- get IP node entry
9 .SH SYNOPSIS
10 .LP
11 .nf
12 \fBcc\fR [ \fIflag\fR... ] \fIfile\fR... \fB-lsocket\fR \fB -lnsl \fR [ \fIlibrary\fR... ]
13 #include <sys/socket.h>
14 #include <netdb.h>
15
16 \fBstruct hostent *\fR\fBgetipnodebyname\fR(\fBconst char *\fR\fIname\fR, \fBint\fR \fIaf\fR,
17 \fBint\fR \fIflags\fR, \fBint *\fR\fIerror_num\fR);
18 .fi
19
20 .LP
21 .nf
22 \fBstruct hostent *\fR\fBgetipnodebyaddr\fR(\fBconst void *\fR\fIsrc\fR, \fBsize_t\fR \fIlen\fR,
23 \fBint\fR \fIaf\fR, \fBint *\fR\fIerror_num\fR);
24 .fi
25
26 .LP
437
438 .sp
439 .in +2
440 .nf
441 #include <stdio.h>
442 #include <string.h>
443 #include <sys/types.h>
444 #include <sys/socket.h>
445 #include <netinet/in.h>
446 #include <arpa/inet.h>
447 #include <netdb.h>
448
449 main(int argc, const char **argv)
450 {
451 char abuf[INET6_ADDRSTRLEN];
452 int error_num;
453 struct hostent *hp;
454 char **p;
455
456 if (argc != 2) {
457 (void) printf("usage: %s hostname\n", argv[0]);
458 exit (1);
459 }
460
461 /* argv[1] can be a pointer to a hostname or literal IP address */
462 hp = getipnodebyname(argv[1], AF_INET6, AI_ALL | AI_ADDRCONFIG |
463 AI_V4MAPPED, &error_num);
464 if (hp == NULL) {
465 if (error_num == TRY_AGAIN) {
466 printf("%s: unknown host or invalid literal address "
467 "(try again later)\n", argv[1]);
468 } else {
469 printf("%s: unknown host or invalid literal address\n",
470 argv[1]);
471 }
472 exit (1);
473 }
474 for (p = hp->h_addr_list; *p != 0; p++) {
475 struct in6_addr in6;
476 char **q;
477
478 bcopy(*p, (caddr_t)&in6, hp->h_length);
479 (void) printf("%s\t%s", inet_ntop(AF_INET6, (void *)&in6,
480 abuf, sizeof(abuf)), hp->h_name);
481 for (q = hp->h_aliases; *q != 0; q++)
482 (void) printf(" %s", *q);
483 (void) putchar('\n');
484 }
485 freehostent(hp);
486 exit (0);
487 }
488 .fi
489 .in -2
490
491 .SH ATTRIBUTES
492 .sp
493 .LP
494 See \fBattributes\fR(5) for descriptions of the following attributes:
495 .sp
496
497 .sp
498 .TS
499 box;
500 c | c
501 l | l .
502 ATTRIBUTE TYPE ATTRIBUTE VALUE
503 _
|
1 '\" te
2 .\" Copyright (c) 2007, Sun Microsystems, Inc. All Rights Reserved.
3 .\" The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
4 .\" You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
5 .\" When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
6 .TH GETIPNODEBYNAME 3SOCKET "Sep 10, 2013"
7 .SH NAME
8 getipnodebyname, getipnodebyaddr, freehostent \- get IP node entry
9 .SH SYNOPSIS
10 .LP
11 .nf
12 \fBcc\fR [ \fIflag\fR... ] \fIfile\fR... \fB-lsocket\fR \fB -lnsl \fR [ \fIlibrary\fR... ]
13 #include <sys/socket.h>
14 #include <netdb.h>
15
16 \fBstruct hostent *\fR\fBgetipnodebyname\fR(\fBconst char *\fR\fIname\fR, \fBint\fR \fIaf\fR,
17 \fBint\fR \fIflags\fR, \fBint *\fR\fIerror_num\fR);
18 .fi
19
20 .LP
21 .nf
22 \fBstruct hostent *\fR\fBgetipnodebyaddr\fR(\fBconst void *\fR\fIsrc\fR, \fBsize_t\fR \fIlen\fR,
23 \fBint\fR \fIaf\fR, \fBint *\fR\fIerror_num\fR);
24 .fi
25
26 .LP
437
438 .sp
439 .in +2
440 .nf
441 #include <stdio.h>
442 #include <string.h>
443 #include <sys/types.h>
444 #include <sys/socket.h>
445 #include <netinet/in.h>
446 #include <arpa/inet.h>
447 #include <netdb.h>
448
449 main(int argc, const char **argv)
450 {
451 char abuf[INET6_ADDRSTRLEN];
452 int error_num;
453 struct hostent *hp;
454 char **p;
455
456 if (argc != 2) {
457 (void) printf("usage: %s hostname\en", argv[0]);
458 exit (1);
459 }
460
461 /* argv[1] can be a pointer to a hostname or literal IP address */
462 hp = getipnodebyname(argv[1], AF_INET6, AI_ALL | AI_ADDRCONFIG |
463 AI_V4MAPPED, &error_num);
464 if (hp == NULL) {
465 if (error_num == TRY_AGAIN) {
466 printf("%s: unknown host or invalid literal address "
467 "(try again later)\en", argv[1]);
468 } else {
469 printf("%s: unknown host or invalid literal address\en",
470 argv[1]);
471 }
472 exit (1);
473 }
474 for (p = hp->h_addr_list; *p != 0; p++) {
475 struct in6_addr in6;
476 char **q;
477
478 bcopy(*p, (caddr_t)&in6, hp->h_length);
479 (void) printf("%s\t%s", inet_ntop(AF_INET6, (void *)&in6,
480 abuf, sizeof(abuf)), hp->h_name);
481 for (q = hp->h_aliases; *q != 0; q++)
482 (void) printf(" %s", *q);
483 (void) putchar('\en');
484 }
485 freehostent(hp);
486 exit (0);
487 }
488 .fi
489 .in -2
490
491 .SH ATTRIBUTES
492 .sp
493 .LP
494 See \fBattributes\fR(5) for descriptions of the following attributes:
495 .sp
496
497 .sp
498 .TS
499 box;
500 c | c
501 l | l .
502 ATTRIBUTE TYPE ATTRIBUTE VALUE
503 _
|