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