---
name: "getaddrinfo"
section: "1"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["linux", "freebsd"]
url: "https://new.carta.tech/getaddrinfo"
---

# getaddrinfo(1)

resolve names to socket addresses

## NAME

**getaddrinfo** – resolve names to socket addresses

## SYNOPSIS

**getaddrinfo** \[**-cNnP**\] \[**-f** *family*\] \[**-p** *protocol*\] \[**-s** *service*\[/*protocol*\]\] \[**-t** *socktype*\] \[*hostname*\]

## DESCRIPTION

The **getaddrinfo** utility resolves host and service names to socket addresses with [getaddrinfo(3)](/getaddrinfo/3.md) and prints them to standard output in a user-friendly format.

The output is a sequence of lines with 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.

Depending on the settings in [nsswitch.conf(5)](/nsswitch.conf/5.md), **getaddrinfo** might query DNS for answers. However, it is not intended to be a general-purpose DNS query utility. Use [drill(1)](/drill/1.md) for that.

These options are available:

- **-c**

  Look up a canonical name as if with the AI\_CANONNAME flag to [getaddrinfo(3)](/getaddrinfo/3.md) and print it on the first line before the socket addresses.

- **-f** *family*

  Specify an address family. Address families are named like the AF\_... 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**

  Treat the service as numeric and do not attempt service name resolution, as if with the AI\_NUMERICSERV flag to [getaddrinfo(3)](/getaddrinfo/3.md).

- **-n**

  Treat the hostname as a numeric address and do not attempt name resolution, as if with the AI\_NUMERICHOST flag to [getaddrinfo(3)](/getaddrinfo/3.md).

- **-P**

  Return socket addresses intended for use with [bind(2)](/bind/2.md), as if with the AI\_PASSIVE flag to [getaddrinfo(3)](/getaddrinfo/3.md). By default, the socket addresses are intended for use with [connect(2)](/connect/2.md), [sendto(2)](/sendto/2.md), or [sendmsg(2)](/sendmsg/2.md).

- **-p** *protocol*

  Specify a protocol. Protocols are numeric or symbolic as listed in [protocols(5)](/protocols/5.md).

- **-s** *service*\[/*protocol*\]

  Specify a service to look up. Services are symbolic or numeric with an optional protocol suffix as listed in [services(5)](/services/5.md). If a service is not specified, a hostname is required.

- **-t** *socktype*

  Specify a socket type. Socket types are named like the SOCK\_... 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.

## EXIT STATUS

The **getaddrinfo** utility exits 0 on success, and \>0 if an error occurs.

## EXAMPLES

Look up “www.NetBSD.org”:

```
$ 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
```

## SEE ALSO

[drill(1)](/drill/1.md), [getent(1)](/getent/1.md), [getaddrinfo(3)](/getaddrinfo/3.md), [getnameinfo(3)](/getnameinfo/3.md), [resolver(3)](/resolver/3.md), [hosts(5)](/hosts/5.md), [nsswitch.conf(5)](/nsswitch.conf/5.md), [protocols(5)](/protocols/5.md), [resolv.conf(5)](/resolv.conf/5.md), [services(5)](/services/5.md), [ip6addrctl(8)](/ip6addrctl/8.md)

## HISTORY

The **getaddrinfo** command first appeared in NetBSD 7.0.
