LINK_ADDR(3) FreeBSD Library Functions Manual LINK_ADDR(3)
NAME
link_addr, link_ntoa, link_ntoa_r - elementary address specification
routines for link level access
LIBRARY
Standard C Library (libc, -lc)
SYNOPSIS
#include <sys/types.h>
#include <sys/socket.h>
#include <net/if_dl.h>
int
link_addr(const char *addr, struct sockaddr_dl *sdl);
char *
link_ntoa(const struct sockaddr_dl *sdl);
int
link_ntoa_r(const struct sockaddr_dl *sdl, char *obuf, size_t *buflen);
DESCRIPTION
The routine link_addr() parses a character string addr representing a
link-level address, and stores the resulting address in the structure
pointed to by sdl. A link-level address consists of an optional
interface name, followed by a colon (which is required in all cases),
followed by an address consisting of either a string of hexadecimal
digits, or a series of hexadecimal octets separated by one of the
characters `.', `:', or `-'.
The routine link_ntoa() takes a link-level address and returns an ASCII
string representing some of the information present, including the link
level address itself, and the interface name or number, if present. The
returned string is stored in a static buffer. This facility is
experimental and is still subject to change.
The routine link_ntoa_r() behaves like link_ntoa(), except the string is
placed in the provided buffer instead of a static buffer. The caller
should initialize buflen to the number of bytes available in obuf. On
return, buflen is set to the actual number of bytes required for the
output buffer, including the NUL terminator. If obuf is NULL, then
buflen is set as described, but nothing is written. This may be used to
determine the required length of the buffer before calling link_ntoa_r()
a second time.
For link_addr(), the string addr may contain an optional network
interface identifier of the form "name unit-number", suitable for the
first argument to ifconfig(8), followed in all cases by a colon and an
interface address in the form of groups of hexadecimal digits separated
by periods. Each group represents a byte of address; address bytes are
filled left to right from low order bytes through high order bytes.
Thus le0:8.0.9.13.d.30 represents an ethernet address to be transmitted
on the first Lance ethernet interface.
RETURN VALUES
The link_ntoa() function always returns a null terminated string.
The link_ntoa_r() function returns 0 on success, or -1 if the provided
buffer was not large enough; in the latter case, the contents of the
buffer are indeterminate, but a trailing NUL will always be written if
the buffer was at least one byte in size.
The link_addr() function returns 0 on success. If the address did not
appear to be a valid link-level address, -1 is returned and errno is set
to indicate the error.
SEE ALSO
getnameinfo(3)
HISTORY
The link_addr() and link_ntoa() functions appeared in 4.3BSD-Reno. The
link_ntoa_r() function appeared in FreeBSD 15.0.
BUGS
The returned values for link_ntoa reside in a static memory area.
If the sdl_len field of the link socket address sdl is 0, link_ntoa()
will not insert a colon before the interface address bytes. If this
translated address is given to link_addr() without inserting an initial
colon, the latter will not interpret it correctly.
FreeBSD 15.1-STABLE-HBSD May 9, 2025 LINK_ADDR(3)