---
name: "link_addr"
section: "3"
platform: "freebsd"
package: "base"
version: "16.0-CURRENT-20261027-61c70dc16a79"
release: "FreeBSD 16.0-CURRENT (2026-10-27)"
platforms: ["freebsd"]
url: "https://new.carta.tech/link_addr"
---

# link\_addr(3)

elementary address specification routines for link level access

## 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)](/ifconfig/8.md), 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)](/getnameinfo/3.md)

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