GETADDRINFO(1) | General Commands Manual | GETADDRINFO(1) |
getaddrinfo
—
getaddrinfo |
[-cNnP ] [-f
family] [-p
protocol] [-s
service[/protocol]]
[-t socktype]
[hostname] |
getaddrinfo
utility resolves host and service names
to socket addresses as if with the
getaddrinfo(3) routine and
formats them to standard output.
The output is a sequence of lines of space-separated fields:
socket-type address-family protocol
[af-specific data ...]
For the “inet” and “inet6” address families, the af-specific data are the IP/IPv6 address and port number.
Although the getaddrinfo
utility may query
the DNS to give answers, depending on the system's
nsswitch.conf(5)
configuration, it is not intended to be a general-purpose utility to query
the DNS; use the dig(1) utility
for that.
The following options are available:
-c
AI_CANONNAME
flag to
getaddrinfo(3) and
print it on the first line before the socket addresses.-f
familyAF_...
constants for address family numbers in the
⟨sys/socket.h⟩ header file but
without the AF_
prefix and lowercase. For example,
“inet” corresponds with
AF_INET
.-N
AI_NUMERICSERV
flag to
getaddrinfo(3).-n
AI_NUMERICHOST
flag to
getaddrinfo(3).-P
AI_PASSIVE
flag to
getaddrinfo(3). By
default, the socket addresses are intended for use with
connect(2),
sendto(2), or
sendmsg(2).-p
protocol-s
service[/protocol]-t
socktypeSOCK_...
constants for socket type numbers in the
⟨sys/socket.h⟩ header file but
without the SOCK_
prefix and lowercase. For
example, “dgram” corresponds with
SOCK_DGRAM
.getaddrinfo
utility exits 0 on success,
and >0 if an error occurs.
$ getaddrinfo www.NetBSD.org dgram inet6 udp 2001:4f8:3:7:2e0:81ff:fe52:9ab6 0 dgram inet udp 149.20.53.67 0 stream inet6 tcp 2001:4f8:3:7:2e0:81ff:fe52:9ab6 0 stream inet tcp 149.20.53.67 0
The port number here is zero because no service was specified.
Look up “morden.NetBSD.org” for stream sockets on port 80, and show the canonical name:
$ getaddrinfo -c -t stream -s 80 morden.NetBSD.org canonname ftp.NetBSD.org stream inet6 tcp 2001:470:1f05:3d::21 80 stream inet tcp 199.233.217.249 80
getaddrinfo
command first appeared in
NetBSD 7.0.
April 22, 2014 | NetBSD 9.4 |