Section (3) getipnodebyname
Name
getipnodebyname, getipnodebyaddr, freehostent — get network hostnames and addresses
Synopsis
#include <sys/types.h> #include <sys/socket.h> #include <netdb.h>
struct hostent
*getipnodebyname( |
const char *name, |
int af, | |
int flags, | |
int *error_num) ; |
struct hostent
*getipnodebyaddr( |
const void *addr, |
size_t len, | |
int af, | |
int *error_num) ; |
void
freehostent( |
struct hostent *ip) ; |
DESCRIPTION
These functions are deprecated (and unavailable in glibc). Use getaddrinfo(3) and getnameinfo(3) instead.
The getipnodebyname
() and
getipnodebyaddr
() functions
return the names and addresses of a network host. These
functions return a pointer to the following structure:
struct hostent { char * h_name
;char ** h_aliases
;int h_addrtype
;int h_length
;char ** h_addr_list
;};
These functions replace the gethostbyname(3) and
gethostbyaddr(3) functions,
which could access only the IPv4 network address family. The
getipnodebyname
() and
getipnodebyaddr
() functions can
access multiple network address families.
Unlike the gethostby
functions, these functions return pointers to dynamically
allocated memory. The freehostent
() function is used to release
the dynamically allocated memory after the caller no longer
needs the hostent
structure.
getipnodebyname() arguments
The getipnodebyname
()
function looks up network addresses for the host specified
by the name
argument. The af
argument specifies one of the following values:
AF_INET
-
The
name
argument points to a dotted-quad IPv4 address or a name of an IPv4 network host. AF_INET6
-
The
name
argument points to a hexadecimal IPv6 address or a name of an IPv6 network host.
The flags
argument specifies additional options. More than one option
can be specified by bitwise OR-ing them together.
flags
should be set
to 0 if no options are desired.
AI_V4MAPPED
-
This flag is used with
AF_INET6
to request a query for IPv4 addresses instead of IPv6 addresses; the IPv4 addresses will be mapped to IPv6 addresses. AI_ALL
-
This flag is used with
AI_V4MAPPED
to request a query for both IPv4 and IPv6 addresses. Any IPv4 address found will be mapped to an IPv6 address. AI_ADDRCONFIG
-
This flag is used with
AF_INET6
to further request that queries for IPv6 addresses should not be made unless the system has at least one IPv6 address assigned to a network interface, and that queries for IPv4 addresses should not be made unless the system has at least one IPv4 address assigned to a network interface. This flag may be used by itself or with theAI_V4MAPPED
flag. AI_DEFAULT
-
This flag is equivalent to (AI_ADDRCONFIG | AI_V4MAPPED).
getipnodebyaddr() arguments
The getipnodebyaddr
()
function looks up the name of the host whose network
address is specified by the addr
argument. The af
argument specifies one of
the following values:
AF_INET
-
The
addr
argument points to a struct in_addr andlen
must be set to sizeof(struct in_addr). AF_INET6
-
The
addr
argument points to a struct in6_addr andlen
must be set to sizeof(struct in6_addr).
RETURN VALUE
NULL is returned if an error occurred, and error_num
will contain an error
code from the following list:
HOST_NOT_FOUND
-
The hostname or network address was not found.
NO_ADDRESS
-
The domain name server recognized the network address or name, but no answer was returned. This can happen if the network host has only IPv4 addresses and a request has been made for IPv6 information only, or vice versa.
NO_RECOVERY
-
The domain name server returned a permanent failure response.
TRY_AGAIN
-
The domain name server returned a temporary failure response. You might have better luck next time.
A successful query returns a pointer to a hostent structure that contains the following fields:
h_name
-
This is the official name of this network host.
h_aliases
-
This is an array of pointers to unofficial aliases for the same host. The array is terminated by a null pointer.
h_addrtype
-
This is a copy of the
af
argument togetipnodebyname
() orgetipnodebyaddr
().h_addrtype
will always beAF_INET
if theaf
argument wasAF_INET
.h_addrtype
will always beAF_INET6
if theaf
argument wasAF_INET6
. h_length
-
This field will be set to sizeof(struct in_addr) if
h_addrtype
isAF_INET
, and to sizeof(struct in6_addr) ifh_addrtype
isAF_INET6
. h_addr_list
-
This is an array of one or more pointers to network address structures for the network host. The array is terminated by a null pointer.
NOTES
These functions were present in glibc 2.1.91-95, but were removed again. Several UNIX-like systems support them, but all call them deprecated.
COLOPHON
This page is part of release 4.16 of the Linux man-pages
project. A
description of the project, information about reporting bugs,
and the latest version of this page, can be found at
https://www.kernel.org/doc/man−pages/.
Copyright 2000 Sam Varshavchik <mrsamcourier-mta.com> %%%LICENSE_START(VERBATIM) Permission is granted to make and distribute verbatim copies of this manual provided the copyright notice and this permission notice are preserved on all copies. Permission is granted to copy and distribute modified versions of this manual under the conditions for verbatim copying, provided that the entire resulting derived work is distributed under the terms of a permission notice identical to this one. Since the Linux kernel and libraries are constantly changing, this manual page may be incorrect or out-of-date. The author(s) assume no responsibility for errors or omissions, or for damages resulting from the use of the information contained herein. The author(s) may not have taken the same level of care in the production of this manual, which is licensed free of charge, as they might when working professionally. Formatted or processed versions of this manual, if unaccompanied by the source, must acknowledge the copyright and authors of this work. %%%LICENSE_END References: RFC 2553 |