xref: /freebsd/lib/libc/net/ethers.3 (revision 3462b16f2920071a44f7e0161add348f64e951a9)
162ad77f0SRobert Watson.\" Copyright (c) 1995 Bill Paul <wpaul@ctr.columbia.edu>.
262ad77f0SRobert Watson.\" Copyright (c) 2007 Robert N. M. Watson
362ad77f0SRobert Watson.\" All rights reserved.
48b4709faSBill Paul.\"
58b4709faSBill Paul.\" Redistribution and use in source and binary forms, with or without
68b4709faSBill Paul.\" modification, are permitted provided that the following conditions
78b4709faSBill Paul.\" are met:
88b4709faSBill Paul.\" 1. Redistributions of source code must retain the above copyright
98b4709faSBill Paul.\"    notice, this list of conditions and the following disclaimer.
108b4709faSBill Paul.\" 2. Redistributions in binary form must reproduce the above copyright
118b4709faSBill Paul.\"    notice, this list of conditions and the following disclaimer in the
128b4709faSBill Paul.\"    documentation and/or other materials provided with the distribution.
138b4709faSBill Paul.\" 3. All advertising materials mentioning features or use of this software
148b4709faSBill Paul.\"    must display the following acknowledgement:
158b4709faSBill Paul.\"	This product includes software developed by Bill Paul.
168b4709faSBill Paul.\" 4. Neither the name of the author nor the names of any co-contributors
178b4709faSBill Paul.\"    may be used to endorse or promote products derived from this software
188b4709faSBill Paul.\"    without specific prior written permission.
198b4709faSBill Paul.\"
208b4709faSBill Paul.\" THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
218b4709faSBill Paul.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
228b4709faSBill Paul.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
238b4709faSBill Paul.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
248b4709faSBill Paul.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
258b4709faSBill Paul.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
268b4709faSBill Paul.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
278b4709faSBill Paul.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
288b4709faSBill Paul.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
298b4709faSBill Paul.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
308b4709faSBill Paul.\" SUCH DAMAGE.
318b4709faSBill Paul.\"
327f3dea24SPeter Wemm.\" $FreeBSD$
338b4709faSBill Paul.\"
34ef824a43SGiorgos Keramidas.Dd October 30, 2007
358b4709faSBill Paul.Dt ETHERS 3
36a307d598SRuslan Ermilov.Os
378b4709faSBill Paul.Sh NAME
388b4709faSBill Paul.Nm ethers ,
398b4709faSBill Paul.Nm ether_line ,
408b4709faSBill Paul.Nm ether_aton ,
4162ad77f0SRobert Watson.Nm ether_aton_r ,
428b4709faSBill Paul.Nm ether_ntoa ,
4362ad77f0SRobert Watson.Nm ether_ntoa_r ,
448b4709faSBill Paul.Nm ether_ntohost ,
458b4709faSBill Paul.Nm ether_hostton
468b4709faSBill Paul.Nd Ethernet address conversion and lookup routines
4725bb73e0SAlexey Zelkin.Sh LIBRARY
4825bb73e0SAlexey Zelkin.Lb libc
498b4709faSBill Paul.Sh SYNOPSIS
5032eef9aeSRuslan Ermilov.In sys/types.h
5132eef9aeSRuslan Ermilov.In sys/socket.h
5232eef9aeSRuslan Ermilov.In net/ethernet.h
538b4709faSBill Paul.Ft int
546e641683SArchie Cobbs.Fn ether_line "const char *l" "struct ether_addr *e" "char *hostname"
558b4709faSBill Paul.Ft struct ether_addr *
566e641683SArchie Cobbs.Fn ether_aton "const char *a"
5762ad77f0SRobert Watson.Ft struct ether_addr *
5862ad77f0SRobert Watson.Fn ether_aton_r "const char *a" "struct ether_addr *e"
598b4709faSBill Paul.Ft char *
606e641683SArchie Cobbs.Fn ether_ntoa "const struct ether_addr *n"
6162ad77f0SRobert Watson.Ft char *
6262ad77f0SRobert Watson.Fn ether_ntoa_r "const struct ether_addr *n" "char *buf"
638b4709faSBill Paul.Ft int
646e641683SArchie Cobbs.Fn ether_ntohost "char *hostname" "const struct ether_addr *e"
658b4709faSBill Paul.Ft int
666e641683SArchie Cobbs.Fn ether_hostton "const char *hostname" "struct ether_addr *e"
678b4709faSBill Paul.Sh DESCRIPTION
688b4709faSBill PaulThese functions operate on ethernet addresses using an
695c564baeSRuslan Ermilov.Vt ether_addr
708b4709faSBill Paulstructure, which is defined in the header file
71*3462b16fSHiroki Sato.In net/ethernet.h :
728b4709faSBill Paul.Bd -literal -offset indent
738b4709faSBill Paul/*
74453196ebSMike Pritchard * The number of bytes in an ethernet (MAC) address.
75453196ebSMike Pritchard */
76453196ebSMike Pritchard#define ETHER_ADDR_LEN		6
77453196ebSMike Pritchard
78453196ebSMike Pritchard/*
798b4709faSBill Paul * Structure of a 48-bit Ethernet address.
808b4709faSBill Paul */
818b4709faSBill Paulstruct  ether_addr {
82453196ebSMike Pritchard        u_char octet[ETHER_ADDR_LEN];
838b4709faSBill Paul};
848b4709faSBill Paul.Ed
858b4709faSBill Paul.Pp
868b4709faSBill PaulThe function
878b4709faSBill Paul.Fn ether_line
888b4709faSBill Paulscans
895c564baeSRuslan Ermilov.Fa l ,
908b4709faSBill Paulan
918b4709faSBill Paul.Tn ASCII
928b4709faSBill Paulstring in
938b4709faSBill Paul.Xr ethers 5
948b4709faSBill Paulformat and sets
955c564baeSRuslan Ermilov.Fa e
968b4709faSBill Paulto the ethernet address specified in the string and
975c564baeSRuslan Ermilov.Fa h
98c6ff3a1bSSheldon Hearnto the hostname.
99c6ff3a1bSSheldon HearnThis function is used to parse lines from
1008b4709faSBill Paul.Pa /etc/ethers
1018b4709faSBill Paulinto their component parts.
1028b4709faSBill Paul.Pp
1038b4709faSBill PaulThe
1048b4709faSBill Paul.Fn ether_aton
10562ad77f0SRobert Watsonand
10662ad77f0SRobert Watson.Fn ether_aton_r
10762ad77f0SRobert Watsonfunctions convert
1088b4709faSBill Paul.Tn ASCII
10962ad77f0SRobert Watsonrepresentation of ethernet addresses into
1105c564baeSRuslan Ermilov.Vt ether_addr
11162ad77f0SRobert Watsonstructures.
11262ad77f0SRobert WatsonLikewise, the
1138b4709faSBill Paul.Fn ether_ntoa
11462ad77f0SRobert Watsonand
11562ad77f0SRobert Watson.Fn ether_ntoa_r
11662ad77f0SRobert Watsonfunctions
11762ad77f0SRobert Watsonconvert ethernet addresses specified as
1185c564baeSRuslan Ermilov.Vt ether_addr
11962ad77f0SRobert Watsonstructures into
1208b4709faSBill Paul.Tn ASCII
12162ad77f0SRobert Watsonstrings.
1228b4709faSBill Paul.Pp
1238b4709faSBill PaulThe
1248b4709faSBill Paul.Fn ether_ntohost
1258b4709faSBill Pauland
1268b4709faSBill Paul.Fn ether_hostton
1278b4709faSBill Paulfunctions map ethernet addresses to their corresponding hostnames
1288b4709faSBill Paulas specified in the
1298b4709faSBill Paul.Pa /etc/ethers
1308b4709faSBill Pauldatabase.
1311fae73b1SRuslan ErmilovThe
1328b4709faSBill Paul.Fn ether_ntohost
1331fae73b1SRuslan Ermilovfunction
1348b4709faSBill Paulconverts from ethernet address to hostname, and
1358b4709faSBill Paul.Fn ether_hostton
1368b4709faSBill Paulconverts from hostname to ethernet address.
1378b4709faSBill Paul.Sh RETURN VALUES
1381fae73b1SRuslan ErmilovThe
1398b4709faSBill Paul.Fn ether_line
1401fae73b1SRuslan Ermilovfunction
1418b4709faSBill Paulreturns zero on success and non-zero if it was unable to parse
1428b4709faSBill Paulany part of the supplied line
1435c564baeSRuslan Ermilov.Fa l .
1448b4709faSBill PaulIt returns the extracted ethernet address in the supplied
1455c564baeSRuslan Ermilov.Vt ether_addr
1468b4709faSBill Paulstructure
1475c564baeSRuslan Ermilov.Fa e
1488b4709faSBill Pauland the hostname in the supplied string
1495c564baeSRuslan Ermilov.Fa h .
1508b4709faSBill Paul.Pp
1518b4709faSBill PaulOn success,
1528b4709faSBill Paul.Fn ether_ntoa
15362ad77f0SRobert Watsonand
15462ad77f0SRobert Watson.Fn ether_ntoa_r
15562ad77f0SRobert Watsonfunctions return a pointer to a string containing an
1568b4709faSBill Paul.Tn ASCII
157c6ff3a1bSSheldon Hearnrepresentation of an ethernet address.
158c6ff3a1bSSheldon HearnIf it is unable to convert
1598b4709faSBill Paulthe supplied
1605c564baeSRuslan Ermilov.Vt ether_addr
161453196ebSMike Pritchardstructure, it returns a
162453196ebSMike Pritchard.Dv NULL
163c6ff3a1bSSheldon Hearnpointer.
16462ad77f0SRobert Watson.Fn ether_ntoa
16562ad77f0SRobert Watsonstores the result in a static buffer;
16662ad77f0SRobert Watson.Fn ether_ntoa_r
16762ad77f0SRobert Watsonstores the result in a user-passed buffer.
16862ad77f0SRobert Watson.Pp
169c6ff3a1bSSheldon HearnLikewise,
1708b4709faSBill Paul.Fn ether_aton
17162ad77f0SRobert Watsonand
17262ad77f0SRobert Watson.Fn ether_aton_r
17362ad77f0SRobert Watsonreturn a pointer to an
1745c564baeSRuslan Ermilov.Vt ether_addr
175453196ebSMike Pritchardstructure on success and a
176453196ebSMike Pritchard.Dv NULL
177453196ebSMike Pritchardpointer on failure.
17862ad77f0SRobert Watson.Fn ether_aton
17962ad77f0SRobert Watsonstores the result in a static buffer;
18062ad77f0SRobert Watson.Fn ether_aton_r
18162ad77f0SRobert Watsonstores the result in a user-passed buffer.
1828b4709faSBill Paul.Pp
1838b4709faSBill PaulThe
1848b4709faSBill Paul.Fn ether_ntohost
1858b4709faSBill Pauland
1868b4709faSBill Paul.Fn ether_hostton
1878b4709faSBill Paulfunctions both return zero on success or non-zero if they were
1888b4709faSBill Paulunable to find a match in the
1898b4709faSBill Paul.Pa /etc/ethers
1908b4709faSBill Pauldatabase.
1918b4709faSBill Paul.Sh NOTES
192e7f8dd75SRebecca CranThe user must ensure that the hostname strings passed to the
1938b4709faSBill Paul.Fn ether_line ,
1948b4709faSBill Paul.Fn ether_ntohost
1958b4709faSBill Pauland
1968b4709faSBill Paul.Fn ether_hostton
1978b4709faSBill Paulfunctions are large enough to contain the returned hostnames.
1988b4709faSBill Paul.Sh NIS INTERACTION
1998b4709faSBill PaulIf the
2008b4709faSBill Paul.Pa /etc/ethers
2018b4709faSBill Paulcontains a line with a single + in it, the
2028b4709faSBill Paul.Fn ether_ntohost
2038b4709faSBill Pauland
2048b4709faSBill Paul.Fn ether_hostton
2058b4709faSBill Paulfunctions will attempt to consult the NIS
2068b4709faSBill Paul.Pa ethers.byname
2078b4709faSBill Pauland
2088b4709faSBill Paul.Pa ethers.byaddr
2098b4709faSBill Paulmaps in addition to the data in the
2108b4709faSBill Paul.Pa /etc/ethers
2118b4709faSBill Paulfile.
2128b4709faSBill Paul.Sh SEE ALSO
213491a8429SRuslan Ermilov.Xr ethers 5 ,
214491a8429SRuslan Ermilov.Xr yp 8
21524a0682cSRuslan Ermilov.Sh HISTORY
21624a0682cSRuslan ErmilovThis particular implementation of the
21724a0682cSRuslan Ermilov.Nm
21824a0682cSRuslan Ermilovlibrary functions were written for and first appeared in
21924a0682cSRuslan Ermilov.Fx 2.1 .
22062ad77f0SRobert WatsonThread-safe function variants first appeared in
22162ad77f0SRobert Watson.Fx 7.0 .
2228b4709faSBill Paul.Sh BUGS
2238b4709faSBill PaulThe
2248b4709faSBill Paul.Fn ether_aton
2258b4709faSBill Pauland
2268b4709faSBill Paul.Fn ether_ntoa
2278b4709faSBill Paulfunctions returns values that are stored in static memory areas
2288b4709faSBill Paulwhich may be overwritten the next time they are called.
22962ad77f0SRobert Watson.Pp
23062ad77f0SRobert Watson.Fn ether_ntoa_r
23162ad77f0SRobert Watsonaccepts a character buffer pointer, but not a buffer length.
23262ad77f0SRobert WatsonThe caller must ensure adequate space is available in the buffer in order to
23362ad77f0SRobert Watsonavoid a buffer overflow.
234