carta
ether_ntohost(3)

ether_ntohost3

Ethernet address conversion and lookup routines

Part of ether_aton(3).

Usage

int

struct ether_addr *

struct ether_addr *

char *

char *

int

int

Library

Standard C Library (libc, -lc)

Overview

These functions operate on ethernet addresses using an ether_addr structure, which is defined in the header file ⟨net/ethernet.h⟩:

/*
 * The number of bytes in an ethernet (MAC) address.
 */
#define ETHER_ADDR_LEN		6
/*
 * Structure of a 48-bit Ethernet address.
 */
struct  ether_addr {
        u_char octet[ETHER_ADDR_LEN];
};

The function ether_line() scans l, an ASCII string in ethers(5) format and sets e to the ethernet address specified in the string and h to the hostname. This function is used to parse lines from /etc/ethers into their component parts.

The ether_aton() and ether_aton_r() functions convert ASCII representation of ethernet addresses into ether_addr structures. Likewise, the ether_ntoa() and ether_ntoa_r() functions convert ethernet addresses specified as ether_addr structures into ASCII strings.

The ether_ntohost() and ether_hostton() functions map ethernet addresses to their corresponding hostnames as specified in the /etc/ethers database. The ether_ntohost() function converts from ethernet address to hostname, and ether_hostton() converts from hostname to ethernet address.

Return values

The ether_line() function returns zero on success and non-zero if it was unable to parse any part of the supplied line l. It returns the extracted ethernet address in the supplied ether_addr structure e and the hostname in the supplied string h.

On success, ether_ntoa() and ether_ntoa_r() functions return a pointer to a string containing an ASCII representation of an ethernet address. If it is unable to convert the supplied ether_addr structure, it returns a NULL pointer. ether_ntoa() stores the result in a static buffer; ether_ntoa_r() stores the result in a user-passed buffer.

Likewise, ether_aton() and ether_aton_r() return a pointer to an ether_addr structure on success and a NULL pointer on failure. ether_aton() stores the result in a static buffer; ether_aton_r() stores the result in a user-passed buffer.

The ether_ntohost() and ether_hostton() functions both return zero on success or non-zero if they were unable to find a match in the /etc/ethers database.

Notes

The user must ensure that the hostname strings passed to the ether_line(), ether_ntohost() and ether_hostton() functions are large enough to contain the returned hostnames.

Nis interaction

If the /etc/ethers contains a line with a single + in it, the ether_ntohost() and ether_hostton() functions will attempt to consult the NIS ethers.byname and ethers.byaddr maps in addition to the data in the /etc/ethers file.

History

  • FreeBSD 16.0-CURRENT (2026-10-27) to FreeBSD 13.3-RELEASE: the text shown here
  • FreeBSD 13.2-RELEASE to FreeBSD 13.0-RELEASE
  • FreeBSD 12.4-RELEASE
  • FreeBSD 12.3-RELEASE
  • FreeBSD 12.2-RELEASE
  • FreeBSD 12.1-RELEASE
  • FreeBSD 12.0-RELEASE
  • FreeBSD 11.4-RELEASE
  • FreeBSD 11.3-RELEASE
  • FreeBSD 11.2-RELEASE
  • FreeBSD 11.1-RELEASE
  • FreeBSD 11.0-RELEASE
  • FreeBSD 10.4-RELEASE
  • FreeBSD 10.3-RELEASE
  • FreeBSD 10.2-RELEASE
  • FreeBSD 10.1-RELEASE
  • FreeBSD 10.0-RELEASE
  • FreeBSD 9.3-RELEASE
  • FreeBSD 9.2-RELEASE
  • FreeBSD 9.1-RELEASE
  • FreeBSD 9.0-RELEASE
  • FreeBSD 8.4-RELEASE
  • FreeBSD 8.3-RELEASE
  • FreeBSD 8.2-RELEASE
  • FreeBSD 8.1-RELEASE
  • FreeBSD 8.0-RELEASE
  • FreeBSD 7.4-RELEASE
  • FreeBSD 7.3-RELEASE
  • FreeBSD 7.2-RELEASE
  • FreeBSD 7.1-RELEASE
  • FreeBSD 7.0-RELEASE
  • FreeBSD 6.4-RELEASE
  • FreeBSD 6.3-RELEASE to FreeBSD 6.0-RELEASE
  • FreeBSD 5.5-RELEASE to FreeBSD 5.2-RELEASE
  • FreeBSD 5.1-RELEASE
  • FreeBSD 5.0-RELEASE
  • FreeBSD 4.11-RELEASE to FreeBSD 4.6-RELEASE
  • FreeBSD 4.5-RELEASE
  • FreeBSD 4.4-RELEASE
  • FreeBSD 4.3-RELEASE
  • FreeBSD 4.2-RELEASE to FreeBSD 4.1-RELEASE
  • FreeBSD 4.0-RELEASE
  • FreeBSD 3.5.1-RELEASE to FreeBSD 3.5-RELEASE
  • FreeBSD 3.4-RELEASE to FreeBSD 3.3-RELEASE
  • FreeBSD 3.2-RELEASE to FreeBSD 3.0-RELEASE
  • FreeBSD 2.2.9-RELEASE
  • FreeBSD 2.2.8-RELEASE to FreeBSD 2.2.2-RELEASE
  • FreeBSD 2.1.7.1-RELEASE to FreeBSD 2.1.5-RELEASE
  • FreeBSD 2.0.5-RELEASE

History

This particular implementation of the ethers library functions were written for and first appeared in FreeBSD 2.1. Thread-safe function variants first appeared in FreeBSD 7.0.

Bugs

The ether_aton() and ether_ntoa() functions returns values that are stored in static memory areas which may be overwritten the next time they are called.

ether_ntoa_r() accepts a character buffer pointer, but not a buffer length. The caller must ensure adequate space is available in the buffer in order to avoid a buffer overflow.

From base 16.0-CURRENT-20261027-61c70dc16a79 in FreeBSD 16.0-CURRENT (2026-10-27). Parsed by carta from the page's mdoc source.