Manual Pages for UNIX Darwin command on man freehostent
MyWebUniversity

Manual Pages for UNIX Darwin command on man freehostent

GETIPNODEBYNAME(3) BSD Library Functions Manual GETIPNODEBYNAME(3)

NAME

ggeettiippnnooddeebbyynnaammee, ggeettiippnnooddeebbyyaaddddrr, ffrreeeehhoosstteenntt - nodename-to-address and

address-to-nodename translation

LLIIBBRRAARRYY

Standard C Library (libc, -lc)

SYNOPSIS

##iinncclluuddee <>

##iinncclluuddee <>

##iinncclluuddee <>

struct hostent * ggeettiippnnooddeebbyynnaammee(const char *name, int af, int flags, int *errornum); struct hostent * ggeettiippnnooddeebbyyaaddddrr(const void *src, sizet len, int af, int *errornum); void ffrreeeehhoosstteenntt(struct hostent *ptr);

DESCRIPTION

ggeettiippnnooddeebbyynnaammee() and ggeettiippnnooddeebbyyaaddddrr() functions are very similar to gethostbyname(3), gethostbyname2(3) and gethostbyaddr(3). The functions cover all the functionalities provided by the older ones, and provide

better interface to programmers. The functions require additional argu-

ments, af, and 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 AFINET or AFINET6). The functions also require an additional pointer argument, errornum to return the appropriate error code, to support thread safe error code returns. The type and usage of the return value, struct hostent is described in gethostbyname(3). For ggeettiippnnooddeebbyynnaammee(), the name argument can be either a node name or a

numeric address string (i.e., a dotted-decimal IPv4 address or an IPv6

hex address). The af argument specifies the address family, either AFINET or AFINET6. The flags argument 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 AIDEFAULT (defined below) should han-

dle most applications. That is, porting simple applications to use IPv6 replaces the call hptr = gethostbyname(name); with hptr = getipnodebyname(name, AFINET6, AIDEFAULT, &errornum); Applications desiring finer control over the types of addresses searched for and returned, can specify other combinations of the flags argument. A flags of 0 implies a strict interpretation of the af argument: ++oo If flags is 0 and af is AFINET, then the caller wants only IPv4 addresses. A query is made for A records. If successful, the IPv4

addresses are returned and the hlength member of the hostent struc-

ture will be 4, else the function returns a NULL pointer. ++oo If flags is 0 and if af is AFINET6, then the caller wants only IPv6 addresses. A query is made for AAAA records. If successful, the IPv6 addresses are returned and the hlength member of the hostent structure will be 16, else the function returns a NULL pointer.

Other constants can be logically-ORed into the flags argument, to modify

the behavior of the function. ++oo If the AIV4MAPPED flag is specified along with an af of AFINET6,

then the caller will accept IPv4-mapped IPv6 addresses. That is, if

no AAAA records are found then a query is made for A records and any

found are returned as IPv4-mapped IPv6 addresses (hlength will be

16). The AIV4MAPPED flag is ignored unless af equals AFINET6. ++oo The AIV4MAPPEDCFG flag is exact same as the AIV4MAPPED flag only

if the kernel supports IPv4-mapped IPv6 address.

++oo If the AIALL flag is used in conjunction with the AIV4MAPPED flag, and only used with the IPv6 address family. When AIALL is logically or'd with AIV4MAPPED flag then the caller wants all addresses: IPv6

and IPv4-mapped IPv6. A query is first made for AAAA records and if

successful, the IPv6 addresses are returned. Another query is then

made for A records and any found are returned as IPv4-mapped IPv6

addresses. hlength will be 16. Only if both queries fail does the function return a NULL pointer. This flag is ignored unless af equals AFINET6. If both AIALL and AIV4MAPPED are specified, AIALL takes precedence. ++oo The AIADDRCONFIG flag specifies that a query for AAAA records should

occur only if the node has at least one IPv6 source address config-

ured and a query for A records should occur only if the node has at least one IPv4 source address configured. For example, if the node has no IPv6 source addresses configured, and af equals AFINET6, and the node name being looked up has both AAAA and A records, then: (a) if only AIADDRCONFIG is specified, the function returns a NULL pointer; (b) if AIADDRCONFIG | AIV4MAPPED

is specified, the A records are returned as IPv4-mapped IPv6

addresses; The special flags value of AIDEFAULT is defined as

#define AIDEFAULT (AIV4MAPPEDCFG | AIADDRCONFIG)

We noted that the ggeettiippnnooddeebbyynnaammee() function must allow the name argument

to be either a node name or a literal address string (i.e., a dotted-dec-

imal IPv4 address or an IPv6 hex address). This saves applications from having to call inetpton(3) to handle literal address strings. When the name argument is a literal address string, the flags argument is always ignored. There are four scenarios based on the type of literal address string and the value of the af argument. The two simple cases are when name is a

dotted-decimal IPv4 address and af equals AFINET, or when name is an

IPv6 hex address and af equals AFINET6. The members of the returned hostent structure are: hname points to a copy of the name argument, haliases is a NULL pointer, haddrtype is a copy of the af argument, hlength is either 4 (for AFINET) or 16 (for AFINET6), haddrlist[0]

is a pointer to the 4-byte or 16-byte binary address, and haddrlist[1]

is a NULL pointer.

When name is a dotted-decimal IPv4 address and af equals AFINET6, and

AIV4MAPPED is specified, an IPv4-mapped IPv6 address is returned: hname

points to an IPv6 hex address containing the IPv4-mapped IPv6 address,

haliases is a NULL pointer, haddrtype is AFINET6, hlength is 16,

haddrlist[0] is a pointer to the 16-byte binary address, and

haddrlist[1] is a NULL pointer. It is an error when name is an IPv6 hex address and af equals AFINET. The function's return value is a NULL pointer and the value pointed to by errornum equals HOSTNOTFOUND. ggeettiippnnooddeebbyyaaddddrr() takes almost the same argument as 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.

ggeettiippnnooddeebbyynnaammee() and ggeettiippnnooddeebbyyaaddddrr() dynamically allocate the struc-

ture to be returned to the caller. ffrreeeehhoosstteenntt() reclaims memory region allocated and returned by ggeettiippnnooddeebbyynnaammee() or ggeettiippnnooddeebbyyaaddddrr(). FILES /etc/hosts /etc/host.conf /etc/resolv.conf DIAGNOSTICS ggeettiippnnooddeebbyynnaammee() and ggeettiippnnooddeebbyyaaddddrr() returns NULL on errors. The integer values pointed to by errornum may then be checked to see whether this is a temporary failure or an invalid or unknown host. The meanings of each error code are described in gethostbyname(3).

SEE ALSO

gethostbyaddr(3), gethostbyname(3), hosts(5), services(5), hostname(7), named(8) R. Gilligan, S. Thomson, J. Bound, and W. Stevens, Basic Socket Interface Extensions for IPv6, RFC2553, March 1999. HISTORY The implementation first appeared in KAME advanced networking kit. STANDARDS ggeettiippnnooddeebbyynnaammee() and ggeettiippnnooddeebbyyaaddddrr() are documented in ``Basic Socket Interface Extensions for IPv6'' (RFC2553).

BUGS

ggeettiippnnooddeebbyynnaammee() and ggeettiippnnooddeebbyyaaddddrr() do 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, ggeettaaddddrriinnffoo(3) and ggeettnnaammeeiinnffoo(3) are recommended. The text was shamelessly copied from RFC2553. BSD May 25, 1995 BSD




Contact us      |      About us      |      Term of use      |       Copyright © 2000-2019 MyWebUniversity.com ™