---
name: "realhostname"
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"
---

# realhostname(3)

convert an IP number to the real host name

## NAME

**realhostname** – convert an IP number to the real host name

## LIBRARY

System Utilities Library (libutil, -lutil)

## SYNOPSIS

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

*int*\

**realhostname**(*char \*host*, *size\_t hsize*, *const struct in\_addr \*ip*);

## DESCRIPTION

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

*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, [inet\_ntoa(3)](/inet_ntoa/3.md) is used to convert *ip* to an ASCII form.

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

## RETURN VALUES

The **realhostname**() 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

[gethostbyaddr(3)](/gethostbyaddr/3.md), [gethostbyname(3)](/gethostbyname/3.md), [inet\_ntoa(3)](/inet_ntoa/3.md), [realhostname\_sa(3)](/realhostname_sa/3.md)

## HISTORY

The **realhostname**() function first appeared in FreeBSD 3.2.
