xref: /freebsd/lib/libc/net/ethers.3 (revision 069ac184)
1.\" Copyright (c) 1995 Bill Paul <wpaul@ctr.columbia.edu>.
2.\" Copyright (c) 2007 Robert N. M. Watson
3.\" All rights reserved.
4.\"
5.\" Redistribution and use in source and binary forms, with or without
6.\" modification, are permitted provided that the following conditions
7.\" are met:
8.\" 1. Redistributions of source code must retain the above copyright
9.\"    notice, this list of conditions and the following disclaimer.
10.\" 2. Redistributions in binary form must reproduce the above copyright
11.\"    notice, this list of conditions and the following disclaimer in the
12.\"    documentation and/or other materials provided with the distribution.
13.\" 3. All advertising materials mentioning features or use of this software
14.\"    must display the following acknowledgement:
15.\"	This product includes software developed by Bill Paul.
16.\" 4. Neither the name of the author nor the names of any co-contributors
17.\"    may be used to endorse or promote products derived from this software
18.\"    without specific prior written permission.
19.\"
20.\" THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
21.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
22.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
23.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
24.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
25.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
26.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
27.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
28.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
29.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
30.\" SUCH DAMAGE.
31.\"
32.Dd October 30, 2007
33.Dt ETHERS 3
34.Os
35.Sh NAME
36.Nm ethers ,
37.Nm ether_line ,
38.Nm ether_aton ,
39.Nm ether_aton_r ,
40.Nm ether_ntoa ,
41.Nm ether_ntoa_r ,
42.Nm ether_ntohost ,
43.Nm ether_hostton
44.Nd Ethernet address conversion and lookup routines
45.Sh LIBRARY
46.Lb libc
47.Sh SYNOPSIS
48.In sys/types.h
49.In sys/socket.h
50.In net/ethernet.h
51.Ft int
52.Fn ether_line "const char *l" "struct ether_addr *e" "char *hostname"
53.Ft struct ether_addr *
54.Fn ether_aton "const char *a"
55.Ft struct ether_addr *
56.Fn ether_aton_r "const char *a" "struct ether_addr *e"
57.Ft char *
58.Fn ether_ntoa "const struct ether_addr *n"
59.Ft char *
60.Fn ether_ntoa_r "const struct ether_addr *n" "char *buf"
61.Ft int
62.Fn ether_ntohost "char *hostname" "const struct ether_addr *e"
63.Ft int
64.Fn ether_hostton "const char *hostname" "struct ether_addr *e"
65.Sh DESCRIPTION
66These functions operate on ethernet addresses using an
67.Vt ether_addr
68structure, which is defined in the header file
69.In net/ethernet.h :
70.Bd -literal -offset indent
71/*
72 * The number of bytes in an ethernet (MAC) address.
73 */
74#define ETHER_ADDR_LEN		6
75
76/*
77 * Structure of a 48-bit Ethernet address.
78 */
79struct  ether_addr {
80        u_char octet[ETHER_ADDR_LEN];
81};
82.Ed
83.Pp
84The function
85.Fn ether_line
86scans
87.Fa l ,
88an
89.Tn ASCII
90string in
91.Xr ethers 5
92format and sets
93.Fa e
94to the ethernet address specified in the string and
95.Fa h
96to the hostname.
97This function is used to parse lines from
98.Pa /etc/ethers
99into their component parts.
100.Pp
101The
102.Fn ether_aton
103and
104.Fn ether_aton_r
105functions convert
106.Tn ASCII
107representation of ethernet addresses into
108.Vt ether_addr
109structures.
110Likewise, the
111.Fn ether_ntoa
112and
113.Fn ether_ntoa_r
114functions
115convert ethernet addresses specified as
116.Vt ether_addr
117structures into
118.Tn ASCII
119strings.
120.Pp
121The
122.Fn ether_ntohost
123and
124.Fn ether_hostton
125functions map ethernet addresses to their corresponding hostnames
126as specified in the
127.Pa /etc/ethers
128database.
129The
130.Fn ether_ntohost
131function
132converts from ethernet address to hostname, and
133.Fn ether_hostton
134converts from hostname to ethernet address.
135.Sh RETURN VALUES
136The
137.Fn ether_line
138function
139returns zero on success and non-zero if it was unable to parse
140any part of the supplied line
141.Fa l .
142It returns the extracted ethernet address in the supplied
143.Vt ether_addr
144structure
145.Fa e
146and the hostname in the supplied string
147.Fa h .
148.Pp
149On success,
150.Fn ether_ntoa
151and
152.Fn ether_ntoa_r
153functions return a pointer to a string containing an
154.Tn ASCII
155representation of an ethernet address.
156If it is unable to convert
157the supplied
158.Vt ether_addr
159structure, it returns a
160.Dv NULL
161pointer.
162.Fn ether_ntoa
163stores the result in a static buffer;
164.Fn ether_ntoa_r
165stores the result in a user-passed buffer.
166.Pp
167Likewise,
168.Fn ether_aton
169and
170.Fn ether_aton_r
171return a pointer to an
172.Vt ether_addr
173structure on success and a
174.Dv NULL
175pointer on failure.
176.Fn ether_aton
177stores the result in a static buffer;
178.Fn ether_aton_r
179stores the result in a user-passed buffer.
180.Pp
181The
182.Fn ether_ntohost
183and
184.Fn ether_hostton
185functions both return zero on success or non-zero if they were
186unable to find a match in the
187.Pa /etc/ethers
188database.
189.Sh NOTES
190The user must ensure that the hostname strings passed to the
191.Fn ether_line ,
192.Fn ether_ntohost
193and
194.Fn ether_hostton
195functions are large enough to contain the returned hostnames.
196.Sh NIS INTERACTION
197If the
198.Pa /etc/ethers
199contains a line with a single + in it, the
200.Fn ether_ntohost
201and
202.Fn ether_hostton
203functions will attempt to consult the NIS
204.Pa ethers.byname
205and
206.Pa ethers.byaddr
207maps in addition to the data in the
208.Pa /etc/ethers
209file.
210.Sh SEE ALSO
211.Xr ethers 5 ,
212.Xr yp 8
213.Sh HISTORY
214This particular implementation of the
215.Nm
216library functions were written for and first appeared in
217.Fx 2.1 .
218Thread-safe function variants first appeared in
219.Fx 7.0 .
220.Sh BUGS
221The
222.Fn ether_aton
223and
224.Fn ether_ntoa
225functions returns values that are stored in static memory areas
226which may be overwritten the next time they are called.
227.Pp
228.Fn ether_ntoa_r
229accepts a character buffer pointer, but not a buffer length.
230The caller must ensure adequate space is available in the buffer in order to
231avoid a buffer overflow.
232