xref: /freebsd/lib/libc/net/linkaddr.3 (revision efedac28c7ce4bef9d9b09b7901f1cb35babc2c4)
1.\" Copyright (c) 1993
2.\"	The Regents of the University of California.  All rights reserved.
3.\"
4.\" This code is derived from software contributed to Berkeley by
5.\" Donn Seeley at BSDI.
6.\"
7.\" Redistribution and use in source and binary forms, with or without
8.\" modification, are permitted provided that the following conditions
9.\" are met:
10.\" 1. Redistributions of source code must retain the above copyright
11.\"    notice, this list of conditions and the following disclaimer.
12.\" 2. Redistributions in binary form must reproduce the above copyright
13.\"    notice, this list of conditions and the following disclaimer in the
14.\"    documentation and/or other materials provided with the distribution.
15.\" 3. Neither the name of the University nor the names of its contributors
16.\"    may be used to endorse or promote products derived from this software
17.\"    without specific prior written permission.
18.\"
19.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
20.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
21.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
22.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
23.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
24.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
25.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
26.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
27.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
28.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
29.\" SUCH DAMAGE.
30.\"
31.Dd May 7, 2025
32.Dt LINK_ADDR 3
33.Os
34.Sh NAME
35.Nm link_addr ,
36.Nm link_ntoa ,
37.Nm link_ntoa_r
38.Nd elementary address specification routines for link level access
39.Sh LIBRARY
40.Lb libc
41.Sh SYNOPSIS
42.In sys/types.h
43.In sys/socket.h
44.In net/if_dl.h
45.Ft void
46.Fn link_addr "const char *addr" "struct sockaddr_dl *sdl"
47.Ft char *
48.Fn link_ntoa "const struct sockaddr_dl *sdl"
49.Ft int
50.Fn link_ntoa_r "const struct sockaddr_dl *sdl" "char *obuf" "size_t *buflen"
51.Sh DESCRIPTION
52The routine
53.Fn link_addr
54interprets character strings representing
55link-level addresses, returning binary information suitable
56for use in system calls.
57.Pp
58The routine
59.Fn link_ntoa
60takes
61a link-level
62address and returns an
63.Tn ASCII
64string representing some of the information present,
65including the link level address itself, and the interface name
66or number, if present.
67The returned string is stored in a static buffer.
68This facility is experimental and is
69still subject to change.
70.Pp
71The routine
72.Fn link_ntoa_r
73behaves like
74.Fn link_ntoa ,
75except the string is placed in the provided buffer instead of a static
76buffer.
77The caller should initialize
78.Fa buflen
79to the number of bytes available in
80.Fa obuf .
81On return,
82.Fa buflen
83is set to the actual number of bytes required for the output buffer,
84including the NUL terminator.
85If
86.Fa obuf
87is NULL, then
88.Fa buflen
89is set as described, but nothing is written.
90This may be used to determine the required length of the buffer before
91calling
92.Fn link_ntoa_r
93a second time.
94.Pp
95For
96.Fn link_addr ,
97the string
98.Fa addr
99may contain
100an optional network interface identifier of the form
101.Dq "name unit-number" ,
102suitable for the first argument to
103.Xr ifconfig 8 ,
104followed in all cases by a colon and
105an interface address in the form of
106groups of hexadecimal digits
107separated by periods.
108Each group represents a byte of address;
109address bytes are filled left to right from
110low order bytes through high order bytes.
111.Pp
112.\" A regular expression may make this format clearer:
113.\" .Bd -literal -offset indent
114.\" ([a-z]+[0-9]+:)?[0-9a-f]+(\e.[0-9a-f]+)*
115.\" .Ed
116.\" .Pp
117Thus
118.Li le0:8.0.9.13.d.30
119represents an ethernet address
120to be transmitted on the first Lance ethernet interface.
121.Sh RETURN VALUES
122The
123.Fn link_ntoa
124function
125always returns a null terminated string.
126.Pp
127The
128.Fn link_ntoa_r
129function returns 0 on success, or -1 if the provided buffer was not
130large enough; in the latter case, the contents of the buffer are
131indeterminate, but a trailing NUL will always be written if the buffer
132was at least one byte in size.
133.Pp
134The
135.Fn link_addr
136function
137has no return value.
138(See
139.Sx BUGS . )
140.Sh SEE ALSO
141.Xr getnameinfo 3
142.Sh HISTORY
143The
144.Fn link_addr
145and
146.Fn link_ntoa
147functions appeared in
148.Bx 4.3 Reno .
149The
150.Fn link_ntoa_r
151function appeared in
152.Fx 15.0 .
153.Sh BUGS
154The returned values for link_ntoa
155reside in a static memory area.
156.Pp
157The function
158.Fn link_addr
159should diagnose improperly formed input, and there should be an unambiguous
160way to recognize this.
161.Pp
162If the
163.Va sdl_len
164field of the link socket address
165.Fa sdl
166is 0,
167.Fn link_ntoa
168will not insert a colon before the interface address bytes.
169If this translated address is given to
170.Fn link_addr
171without inserting an initial colon,
172the latter will not interpret it correctly.
173