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

# realhostname\_sa(3)

convert a struct sockaddr to the real host name

## NAME

**realhostname\_sa** – convert a *struct sockaddr* to the real host name

## LIBRARY

System Utilities Library (libutil, -lutil)

## SYNOPSIS

**#include \<sys/types.h\>**

**#include \<netinet/in.h\>**

**#include \<libutil.h\>**

*int*\

**realhostname\_sa**(*char \*host*, *size\_t hsize*, *struct sockaddr \*addr*, *int addrlen*);

## DESCRIPTION

The function **realhostname\_sa**() converts *addr* to the corresponding host name. This is done by resolving *addr* to a host name and then ensuring that the host name resolves back to *addr*.

*host* must point to a buffer of at least *hsize* bytes, and will always be written to by this function.

If the name resolution does not work both ways or if the host name is longer than *hsize* bytes, [getnameinfo(3)](/getnameinfo/3.md) with NI\_NUMERICHOST specified, is used to convert *addr* to an ASCII form.

If the string written to *host* is *hsize* bytes long, *host* will not be NUL terminated.

## RETURN VALUES

The **realhostname\_sa**() function will return one of the following constants which are defined in ⟨libutil.h⟩:

- HOSTNAME\_FOUND

  A valid host name was found.

- HOSTNAME\_INCORRECTNAME

  A host name was found, but it did not resolve back to the passed *ip*. *host* now contains the numeric value of *ip*.

- HOSTNAME\_INVALIDADDR

  *ip* could not be resolved. *host* now contains the numeric value of *ip*.

- HOSTNAME\_INVALIDNAME

  A host name was found, but it could not be resolved back to any ip number. *host* now contains the numeric value of *ip*.

## SEE ALSO

[getaddrinfo(3)](/getaddrinfo/3.md), [getnameinfo(3)](/getnameinfo/3.md), [realhostname(3)](/realhostname/3.md)
