realhostname(3)

realhostname3

Convert an ip number to the real host name

Usage

#include <sys/types.h>

#include <netinet/in.h>

#include <libutil.h>

int

realhostname(char *host, size_t hsize, const struct in_addr *ip);

Library

System Utilities Library (libutil, -lutil)

Overview

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) 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.

Releases

Unchanged in 115 releases since Mac OS X 10.5.

  1. 10.5–26.5

From libutil 73 in macOS 26.5. Parsed by carta from the page's mdoc source.