📄 getipnodebyname.3
字号:
.\" $FreeBSD: src/lib/libc/net/getipnodebyname.3,v 1.8 2001/10/01 16:08:55 ru Exp $.\" $KAME: getipnodebyname.3,v 1.6 2000/08/09 21:16:17 itojun Exp $.\".\" Copyright (c) 1983, 1987, 1991, 1993.\" The Regents of the University of California. All rights reserved..\".\" Redistribution and use in source and binary forms, with or without.\" modification, are permitted provided that the following conditions.\" are met:.\" 1. Redistributions of source code must retain the above copyright.\" notice, this list of conditions and the following disclaimer..\" 2. Redistributions in binary form must reproduce the above copyright.\" notice, this list of conditions and the following disclaimer in the.\" documentation and/or other materials provided with the distribution..\" 3. All advertising materials mentioning features or use of this software.\" must display the following acknowledgement:.\" This product includes software developed by the University of.\" California, Berkeley and its contributors..\" 4. Neither the name of the University nor the names of its contributors.\" may be used to endorse or promote products derived from this software.\" without specific prior written permission..\".\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION).\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF.\" SUCH DAMAGE..\".\" From: @(#)gethostbyname.3 8.4 (Berkeley) 5/25/95.\".Dd May 25, 1995.Dt GETIPNODEBYNAME 3.Os.\".Sh NAME.Nm getipnodebyname ,.Nm getipnodebyaddr ,.Nm freehostent.Nd nodename-to-address and address-to-nodename translation.\".Sh LIBRARY.Lb libc.Sh SYNOPSIS.In sys/types.h.In sys/socket.h.In netdb.h.Ft "struct hostent *".Fn getipnodebyname "const char *name" "int af" "int flags" "int *error_num".Ft "struct hostent *".Fn getipnodebyaddr "const void *src" "size_t len" "int af" "int *error_num".Ft void.Fn freehostent "struct hostent *ptr".\".Sh DESCRIPTION.Fn getipnodebynameand.Fn getipnodebyaddrfunctions are very similar to.Xr gethostbyname 3 ,.Xr gethostbyname2 3and.Xr gethostbyaddr 3 .The functions cover all the functionalities provided by the older ones,and provide better interface to programmers.The functions require additional arguments,.Ar af ,and.Ar flags ,for specifying address family and operation mode.The additional arguments allow programmer to get address for a nodename,for specific address family(such as.Dv AF_INETor.Dv AF_INET6 ) .The functions also require an additional pointer argument,.Ar error_numto return the appropriate error code,to support thread safe error code returns..PpThe type and usage of the return value,.Li "struct hostent"is described in.Xr gethostbyname 3 ..PpFor.Fn getipnodebyname ,the.Ar nameargument can be either a node name or a numeric addressstring(i.e., a dotted-decimal IPv4 address or an IPv6 hex address).The.Ar afargument specifies the address family, either.Dv AF_INETor.Dv AF_INET6 .The.Ar flagsargument specifies the types of addresses that are searched for,and the types of addresses that are returned.We note that a special flags value of.Dv AI_DEFAULT(defined below)should handle most applications.That is, porting simple applications to use IPv6 replaces the call.Bd -literal -offset hptr = gethostbyname(name);.Ed.Ppwith.Bd -literal -offset hptr = getipnodebyname(name, AF_INET6, AI_DEFAULT, &error_num);.Ed.PpApplications desiring finer control over the types of addressessearched for and returned, can specify other combinations of the.Ar flagsargument..PpA.Ar flagsof.Li 0implies a strict interpretation of the.Ar afargument:.Bl -bullet.ItIf.Ar flagsis 0 and.Ar afis.Dv AF_INET ,then the caller wants only IPv4 addresses.A query is made for.Li Arecords.If successful, the IPv4 addresses are returned and the.Li h_lengthmember of the.Li hostentstructure will be 4, else the function returns a.Dv NULLpointer..ItIf.Ar flagsis 0 and if.Ar afis.Li AF_INET6 ,then the caller wants only IPv6 addresses.A query is made for.Li AAAArecords.If successful, the IPv6 addresses are returned and the.Li h_lengthmember of the.Li hostentstructure will be 16, else the function returns a.Dv NULLpointer..El.PpOther constants can be logically-ORed into the.Ar flagsargument, to modify the behavior of the function..Bl -bullet.ItIf the.Dv AI_V4MAPPEDflag is specified along with an.Ar afof.Dv AF_INET6 ,then the caller will accept IPv4-mapped IPv6 addresses.That is, if no.Li AAAArecords are found then a query is made for.Li Arecords and any found are returned as IPv4-mapped IPv6 addresses.Li ( h_lengthwill be 16).The.Dv AI_V4MAPPEDflag is ignored unless.Ar afequals.Dv AF_INET6 ..ItThe.Dv AI_V4MAPPED_CFGflag is exact same as the.Dv AI_V4MAPPEDflag only if the kernel supports IPv4-mapped IPv6 address..ItIf the.Dv AI_ALLflag is used in conjunction with the.Dv AI_V4MAPPEDflag, and only used with the IPv6 address family.When.Dv AI_ALLis logically or'd with.Dv AI_V4MAPPEDflag then the caller wants all addresses: IPv6 and IPv4-mapped IPv6.A query is first made for.Li AAAArecords and if successful, theIPv6 addresses are returned. Another query is then made for.Li Arecords and any found are returned as IPv4-mapped IPv6 addresses..Li h_lengthwill be 16. Only if both queries fail does the functionreturn a.Dv NULLpointer. This flag is ignored unless af equalsAF_INET6. If both.Dv AI_ALLand.Dv AI_V4MAPPEDare specified,.Dv AI_ALLtakes precedence..ItThe.Dv AI_ADDRCONFIGflag specifies that a query for.Li AAAArecordsshould occur only if the node has at least one IPv6 sourceaddress configured and a query for.Li Arecords should occur only if the node has at least one IPv4 source addressconfigured..PpFor example, if the node has no IPv6 source addresses configured,and.Ar afequals AF_INET6, and the node name being looked up has both.Li AAAAand.Li Arecords, then:(a) if only.Dv AI_ADDRCONFIGisspecified, the function returns a.Dv NULLpointer;(b) if.Dv AI_ADDRCONFIG|.Dv AI_V4MAPPEDis specified, the.Li Arecords are returned as IPv4-mapped IPv6 addresses;.El.PpThe special flags value of.Dv AI_DEFAULTis defined as.Bd -literal -offset #define AI_DEFAULT (AI_V4MAPPED_CFG | AI_ADDRCONFIG).Ed.PpWe noted that the.Fn getipnodebynamefunction must allow the.Ar nameargument to be either a node name or a literal address string(i.e., a dotted-decimal IPv4 address or an IPv6 hex address).This saves applications from having to call.Xr inet_pton 3to handle literal address strings.When the.Ar nameargument is a literal address string,the.Ar flagsargument is always ignored..PpThere are four scenarios based on the type of literal address stringand the value of the.Ar afargument.The two simple cases are when.Ar nameis a dotted-decimal IPv4 address and.Ar afequals.Dv AF_INET ,or when.Ar nameis an IPv6 hex address and.Ar afequals.Dv AF_INET6 .The members of thereturned hostent structure are:.Li h_namepoints to a copy of the.Ar nameargument,.Li h_aliasesis a.Dv NULLpointer,.Li h_addrtypeis a copy of the.Ar afargument,.Li h_lengthis either 4(for.Dv AF_INET )or 16(for.Dv AF_INET6 ) ,.Li h_addr_list[0]is a pointer to the 4-byte or 16-byte binary address,and.Li h_addr_list[1]is a.Dv NULLpointer..PpWhen.Ar nameis a dotted-decimal IPv4 address and.Ar afequals.Dv AF_INET6 ,and.Dv AI_V4MAPPEDis specified,an IPv4-mapped IPv6 address is returned:.Li h_namepoints to an IPv6 hex address containing the IPv4-mapped IPv6 address,.Li h_aliasesis a.Dv NULLpointer,.Li h_addrtypeis.Dv AF_INET6 ,.Li h_lengthis 16,.Li h_addr_list[0]is a pointer to the 16-byte binary address, and.Li h_addr_list[1]is a.Dv NULLpointer..PpIt is an error when.Ar nameis an IPv6 hex address and.Ar afequals.Dv AF_INET .The function's return value is a.Dv NULLpointer and the value pointed to by.Ar error_numequals.Dv HOST_NOT_FOUND ..Pp.Fn getipnodebyaddrtakes almost the same argument as.Xr gethostbyaddr 3 ,but adds a pointer to return an error number.Additionally it takes care of IPv4-mapped IPv6 addresses,and IPv4-compatible IPv6 addresses..Pp.Fn getipnodebynameand.Fn getipnodebyaddrdynamically allocate the structure to be returned to the caller..Fn freehostentreclaims memory region allocated and returned by.Fn getipnodebynameor.Fn getipnodebyaddr ..\".Sh FILES.Bl -tag -width /etc/nsswitch.conf -compact.It Pa /etc/hosts.It Pa /etc/nsswitch.conf.It Pa /etc/resolv.conf.El.\".Sh DIAGNOSTICS.Fn getipnodebynameand.Fn getipnodebyaddrreturns.Dv NULLon errors.The integer values pointed to by.Ar error_nummay then be checked to see whether this is a temporary failureor an invalid or unknown host.The meanings of each error code are described in.Xr gethostbyname 3 ..\".Sh SEE ALSO.Xr gethostbyaddr 3 ,.Xr gethostbyname 3 ,.Xr hosts 5 ,.Xr nsswitch.conf 5 ,.Xr services 5 ,.Xr hostname 7 ,.Xr named 8.Pp.Rs.%A R. Gilligan.%A S. Thomson.%A J. Bound.%A W. Stevens.%T Basic Socket Interface Extensions for IPv6.%R RFC2553.%D March 1999.Re.\".Sh HISTORYThe implementation first appeared in KAME advanced networking kit..\".Sh STANDARDS.Fn getipnodebynameand.Fn getipnodebyaddrare documented in.Dq Basic Socket Interface Extensions for IPv6(RFC2553)..\".Sh BUGS.Fn getipnodebynameand.Fn getipnodebyaddrdo not handle scoped IPv6 address properly.If you use these functions,your program will not be able to handle scoped IPv6 addresses.For IPv6 address manipulation,.Fn getaddrinfo 3and.Fn getnameinfo 3are recommended..PpThe current implementation is not thread-safe..PpThe text was shamelessly copied from RFC2553.
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -