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