1.\" $NetBSD: getaddrinfo.1,v 1.5 2014/04/22 06:02:06 wiz Exp $ 2.\" 3.\" Copyright (c) 2013 The NetBSD Foundation, Inc. 4.\" All rights reserved. 5.\" 6.\" This documentation is derived from text contributed to The NetBSD 7.\" Foundation by Taylor R. Campbell. 8.\" 9.\" Redistribution and use in source and binary forms, with or without 10.\" modification, are permitted provided that the following conditions 11.\" are met: 12.\" 1. Redistributions of source code must retain the above copyright 13.\" notice, this list of conditions and the following disclaimer. 14.\" 2. Redistributions in binary form must reproduce the above copyright 15.\" notice, this list of conditions and the following disclaimer in the 16.\" documentation and/or other materials provided with the distribution. 17.\" 18.\" THIS SOFTWARE IS PROVIDED BY THE NETBSD FOUNDATION, INC. AND CONTRIBUTORS 19.\" ``AS IS'' AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED 20.\" TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR 21.\" PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE FOUNDATION OR CONTRIBUTORS 22.\" BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR 23.\" CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF 24.\" SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS 25.\" INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN 26.\" CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) 27.\" ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE 28.\" POSSIBILITY OF SUCH DAMAGE. 29.\" 30.Dd April 22, 2014 31.Dt GETADDRINFO 1 32.Os 33.Sh NAME 34.Nm getaddrinfo 35.Nd resolve names to socket addresses 36.Sh SYNOPSIS 37.Nm 38.Op Fl cNnP 39.Op Fl f Ar family 40.Op Fl p Ar protocol 41.Op Fl s Ar service Ns Op Ns / Ns Ar protocol 42.Op Fl t Ar socktype 43.Op Ar hostname 44.Sh DESCRIPTION 45The 46.Nm 47utility resolves host and service names to socket addresses as if with 48the 49.Xr getaddrinfo 3 50routine and formats them to standard output. 51.Pp 52The output is a sequence of lines of space-separated fields: 53.Pp 54.Dl socket-type address-family protocol [af-specific data ...] 55.Pp 56For the 57.Dq inet 58and 59.Dq inet6 60address families, the af-specific data are the IP/IPv6 address and port 61number. 62.Pp 63Although the 64.Nm 65utility may query the DNS to give answers, depending on the 66system's 67.Xr nsswitch.conf 5 68configuration, it is not intended to be a general-purpose utility to 69query the DNS; use the 70.Xr dig 1 71utility for that. 72.Pp 73The following options are available: 74.Bl -tag -width Ds 75.It Fl c 76Look up a canonical name as if with the 77.Dv AI_CANONNAME 78flag to 79.Xr getaddrinfo 3 80and print it on the first line before the socket addresses. 81.It Fl f Ar family 82Specify an address family. 83Address families are named like the 84.Dv AF_... 85constants for address family numbers in the 86.Aq Pa sys/socket.h 87header file but without the 88.Dv AF_ 89prefix and lowercase. 90For example, 91.Dq inet 92corresponds with 93.Dv AF_INET . 94.It Fl N 95Treat the service as numeric and do not attempt service name 96resolution, as if with the 97.Dv AI_NUMERICSERV 98flag to 99.Xr getaddrinfo 3 . 100.It Fl n 101Treat the hostname as a numeric address and do not attempt name 102resolution, as if with the 103.Dv AI_NUMERICHOST 104flag to 105.Xr getaddrinfo 3 . 106.It Fl P 107Return socket addresses intended for use with 108.Xr bind 2 , 109as if with the 110.Dv AI_PASSIVE 111flag to 112.Xr getaddrinfo 3 . 113By default, the socket addresses are intended for use with 114.Xr connect 2 , 115.Xr sendto 2 , 116or 117.Xr sendmsg 2 . 118.It Fl p Ar protocol 119Specify a protocol. 120Protocols may be numeric, or symbolic as listed in 121.Xr protocols 5 . 122.It Fl s Ar service Ns Op Ns / Ns Ar protocol 123Specify a service to look up. 124Services may be symbolic or numeric with an optional 125protocol suffix as listed in 126.Xr services 5 . 127If no service is specified, a hostname must be specified. 128.It Fl t Ar socktype 129Specify a socket type. 130Socket types are named like the 131.Dv SOCK_... 132constants for socket type numbers in the 133.Aq Pa sys/socket.h 134header file but without the 135.Dv SOCK_ 136prefix and lowercase. 137For example, 138.Dq dgram 139corresponds with 140.Dv SOCK_DGRAM . 141.El 142.Sh EXIT STATUS 143.Ex -std getaddrinfo 144.Sh EXAMPLES 145Look up 146.Dq www.NetBSD.org : 147.Bd -literal -offset indent 148$ getaddrinfo www.NetBSD.org 149dgram inet6 udp 2001:4f8:3:7:2e0:81ff:fe52:9ab6 0 150dgram inet udp 149.20.53.67 0 151stream inet6 tcp 2001:4f8:3:7:2e0:81ff:fe52:9ab6 0 152stream inet tcp 149.20.53.67 0 153.Ed 154.Pp 155The port number here is zero because no service was specified. 156.Pp 157Look up 158.Dq morden.NetBSD.org 159for stream sockets on port 80, and show the canonical name: 160.Bd -literal -offset indent 161$ getaddrinfo -c -t stream -s 80 morden.NetBSD.org 162canonname ftp.NetBSD.org 163stream inet6 tcp 2001:470:1f05:3d::21 80 164stream inet tcp 199.233.217.249 80 165.Ed 166.Sh SEE ALSO 167.Xr dig 1 , 168.Xr getent 1 , 169.Xr getaddrinfo 3 , 170.Xr getnameinfo 3 , 171.Xr resolver 3 , 172.Xr hosts 5 , 173.Xr nsswitch.conf 5 , 174.Xr protocols 5 , 175.Xr resolv.conf 5 , 176.Xr services 5 177.Sh HISTORY 178The 179.Nm 180command first appeared in 181.Nx 7.0 . 182