LINK_ADDR(3)
okay bestie, welcome to LINK_ADDR(3) β the little page with the elementary address specification routines for link level access. itβs giving very βlow-level but make it understandableβ energy, and weβre getting into all of it π β¨
πΈ NAME πΈ
link_addr, link_ntoa, link_ntoa_r β elementary address specification routines for link level access π
π LIBRARY π
these live in the 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 π
so link_addr() is the parser bestie: it takes a character string addr that represents a link-level address, then stores the resulting address in the structure pointed to by sdl. a link-level address is an optional interface name, then a colon (and yes, that colon is required in all cases, no skipping it), then an address made of either a string of hexadecimal digits, or a series of hexadecimal octets separated by one of these separator characters: β.β, β:β, or β-β π
link_ntoa() goes the other way: it 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. and bestie, heads up: this facility is experimental and is still subject to change π
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. iconic little example, no cap π¦
π 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)β go peek at this one too, bestie π
π 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 (link_addr()) will not interpret it correctly π
mwah π β this LINK_ADDR(3) page came from Debian, dated May 9, 2025 π
π¦ where this page comes from
- freebsd 15.1: base 15.1
- Copyright (c) 1993 The Regents of the University of California. All rights reserved
- π girlified by deepseek-ai/DeepSeek-V4.1-Flash-1017 on : a language model's rewrite of the original, under its terms