xref: /illumos-gate/usr/src/man/man3socket/ethers.3socket (revision d1e631af56641f21cde1f1efe3a9623ff9d6ee7c)
te
Copyright 1989 AT&T.
Copyright (C) 2004, Sun Microsystems, Inc. All Rights Reserved.
Copyright (C) 2014, Joyent, Inc. All Rights Reserved.
The contents of this file are subject to the terms of the Common Development and Distribution License (the "License"). You may not use this file except in compliance with the License.
You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE or http://www.opensolaris.org/os/licensing. See the License for the specific language governing permissions and limitations under the License.
When distributing Covered Code, include this CDDL HEADER in each file and include the License file at usr/src/OPENSOLARIS.LICENSE. If applicable, add the following below this CDDL HEADER, with the fields enclosed by brackets "[]" replaced with your own identifying information: Portions Copyright [yyyy] [name of copyright owner]
ETHERS 3SOCKET "Aug 9, 2014"
NAME
ethers, ether_ntoa, ether_ntoa_r, ether_aton, ether_aton_r, ether_ntohost, ether_hostton, ether_line - Ethernet address mapping operations
SYNOPSIS

cc [ flag ... ] file ... -lsocket  -lnsl  [ library ... ]
#include <sys/types.h>
#include <sys/ethernet.h>

char *ether_ntoa(const struct ether_addr *e);

char *ether_ntoa_r(const struct ether_addr *e, char *s);

struct ether_addr *ether_aton(const char *s);

struct ether_addr *ether_aton_r(const char *s, struct ether_addr *e);

int ether_ntohost(char *hostname, const struct ether_addr *e);

int ether_hostton(const char *hostname, struct ether_addr *e);

int ether_line(const char *l, struct ether_addr *e, char *hostname);
DESCRIPTION

These routines are useful for mapping 48 bit Ethernet numbers to their ASCII representations or their corresponding host names, and vice versa.

The function ether_ntoa() converts a 48 bit Ethernet number pointed to by e to its standard ASCII representation; it returns a pointer to the ASCII string. The representation is of the form x\|:\|x\|:\|x\|:\| x\|:\|x\|:\|x where x is a hexadecimal number between 0 and ff. The function ether_aton() converts an ASCII string in the standard representation back to a 48 bit Ethernet number; the function returns NULL if the string cannot be scanned successfully.

The functions ether_ntoa() and ether_aton() return values in per-thread buffers, one for each function. A second call to one of these functions will overwrite the previous value. The functions ether_ntoa_r() and ether_aton_r() behave identically to their non-reentrant versions; however, instead of using a per-thread buffer, they use caller supplied buffers. It is the callers responsibility to ensure that the character buffer passed to ether_ntoa_r() is at least ETHERADDRSTRL bytes large -- the minimum size to hold the ASCII representation of a 48 bit Ethernet number and a null terminator.

The function ether_ntohost() maps an Ethernet number (pointed to by e) to its associated hostname. The string pointed to by hostname must be long enough to hold the hostname and a NULL character. The function returns zero upon success and non-zero upon failure. Inversely, the function ether_hostton() maps a hostname string to its corresponding Ethernet number; the function modifies the Ethernet number pointed to by e. The function also returns zero upon success and non-zero upon failure. In order to do the mapping, both these functions may lookup one or more of the following sources: the ethers file, the NIS maps ethers.byname and ethers.byaddr and the NIS+ table ethers. The sources and their lookup order are specified in the /etc/nsswitch.conf file. See nsswitch.conf(4) for details.

The function ether_line() scans a line, pointed to by l, and sets the hostname and the Ethernet number, pointed to by e. The string pointed to by hostname must be long enough to hold the hostname and a NULL character. The function returns zero upon success and non-zero upon failure. The format of the scanned line is described by ethers(4).

FILES
/etc/ethers

Ethernet address to hostname database or domain

/etc/nsswitch.conf

configuration file for the name service switch

ATTRIBUTES

See attributes(5) for descriptions of the following attributes:

ATTRIBUTE TYPE ATTRIBUTE VALUE
MT-Level MT-Safe
SEE ALSO

ethers(4), nsswitch.conf(4), attributes(5)