1.\" $OpenBSD: link_addr.3,v 1.11 2005/07/22 04:50:51 jaredy 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. Neither the name of the University nor the names of its contributors 18.\" may be used to endorse or promote products derived from this software 19.\" without specific prior written permission. 20.\" 21.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND 22.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 23.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 24.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 25.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 26.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 27.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 28.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 29.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 30.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 31.\" SUCH DAMAGE. 32.\" 33.Dd July 28, 1993 34.Dt LINK_ADDR 3 35.Os 36.Sh NAME 37.Nm link_addr , 38.Nm link_ntoa 39.Nd elementary address specification routines for link level access 40.Sh SYNOPSIS 41.Fd #include <sys/types.h> 42.Fd #include <sys/socket.h> 43.Fd #include <net/if_dl.h> 44.Ft void 45.Fn link_addr "const char *addr" "struct sockaddr_dl *sdl" 46.Ft char * 47.Fn link_ntoa "const struct sockaddr_dl *sdl" 48.Sh DESCRIPTION 49The 50.Fn link_addr 51function interprets character strings representing 52link-level addresses, returning binary information suitable 53for use in system calls. 54.Fn link_ntoa 55takes 56a link-level 57address and returns an 58.Tn ASCII 59string representing some of the information present, 60including the link level address itself, and the interface name 61or number, if present. 62This facility is experimental and is 63still subject to change. 64.Pp 65For 66.Fn link_addr , 67the string 68.Fa addr 69may contain 70an optional network interface identifier of the form 71.Dq name unit-number , 72suitable for the first argument to 73.Xr ifconfig 8 , 74followed in all cases by a colon and 75an interface address in the form of 76groups of hexadecimal digits 77separated by periods. 78Each group represents a byte of address; 79address bytes are filled left to right from 80low order bytes through high order bytes. 81.Pp 82.\" A regular expression may make this format clearer: 83.\" .Bd -literal -offset indent 84.\" ([a-z]+[0-9]+:)?[0-9a-f]+(\e.[0-9a-f]+)* 85.\" .Ed 86.\" .Pp 87Thus 88.Li le0:8.0.9.13.d.30 89represents an Ethernet address 90to be transmitted on the first Lance Ethernet interface. 91.Sh RETURN VALUES 92.Fn link_ntoa 93always returns a NUL-terminated string. 94.Fn link_addr 95has no return value. 96(See 97.Sx BUGS . ) 98.Sh SEE ALSO 99.Xr ifconfig 8 100.Sh HISTORY 101The 102.Fn link_addr 103and 104.Fn link_ntoa 105functions appeared in 106.Bx 4.3 Reno . 107.Sh BUGS 108The returned values for 109.Fn link_ntoa 110reside in a static memory area. 111.Pp 112The function 113.Fn link_addr 114should diagnose improperly formed input, and there should be an unambiguous 115way to recognize this. 116.Pp 117If the 118.Fa sdl_len 119field of the link socket address 120.Fa sdl 121is 0, 122.Fn link_ntoa 123will not insert a colon before the interface address bytes. 124If this translated address is given to 125.Fn link_addr 126without inserting an initial colon, 127the latter will not interpret it correctly. 128