186d7f5d3SJohn Marino.\" Copyright (c) 1995 Bill Paul <wpaul@ctr.columbia.edu>. 286d7f5d3SJohn Marino.\" Copyright (c) 2007 Robert N. M. Watson 386d7f5d3SJohn Marino.\" All rights reserved. 486d7f5d3SJohn Marino.\" 586d7f5d3SJohn Marino.\" Redistribution and use in source and binary forms, with or without 686d7f5d3SJohn Marino.\" modification, are permitted provided that the following conditions 786d7f5d3SJohn Marino.\" are met: 886d7f5d3SJohn Marino.\" 1. Redistributions of source code must retain the above copyright 986d7f5d3SJohn Marino.\" notice, this list of conditions and the following disclaimer. 1086d7f5d3SJohn Marino.\" 2. Redistributions in binary form must reproduce the above copyright 1186d7f5d3SJohn Marino.\" notice, this list of conditions and the following disclaimer in the 1286d7f5d3SJohn Marino.\" documentation and/or other materials provided with the distribution. 1386d7f5d3SJohn Marino.\" 3. All advertising materials mentioning features or use of this software 1486d7f5d3SJohn Marino.\" must display the following acknowledgement: 1586d7f5d3SJohn Marino.\" This product includes software developed by Bill Paul. 1686d7f5d3SJohn Marino.\" 4. Neither the name of the author nor the names of any co-contributors 1786d7f5d3SJohn Marino.\" may be used to endorse or promote products derived from this software 1886d7f5d3SJohn Marino.\" without specific prior written permission. 1986d7f5d3SJohn Marino.\" 2086d7f5d3SJohn Marino.\" THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND 2186d7f5d3SJohn Marino.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE 2286d7f5d3SJohn Marino.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE 2386d7f5d3SJohn Marino.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE 2486d7f5d3SJohn Marino.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL 2586d7f5d3SJohn Marino.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS 2686d7f5d3SJohn Marino.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) 2786d7f5d3SJohn Marino.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT 2886d7f5d3SJohn Marino.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY 2986d7f5d3SJohn Marino.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF 3086d7f5d3SJohn Marino.\" SUCH DAMAGE. 3186d7f5d3SJohn Marino.\" 3286d7f5d3SJohn Marino.\" $FreeBSD: src/lib/libc/net/ethers.3,v 1.25 2007/10/30 15:31:41 keramida Exp $ 3386d7f5d3SJohn Marino.\" $DragonFly: src/lib/libc/net/ethers.3,v 1.4 2006/05/26 19:39:37 swildner Exp $ 3486d7f5d3SJohn Marino.\" 3586d7f5d3SJohn Marino.Dd October 30, 2007 3686d7f5d3SJohn Marino.Dt ETHERS 3 3786d7f5d3SJohn Marino.Os 3886d7f5d3SJohn Marino.Sh NAME 3986d7f5d3SJohn Marino.Nm ethers , 4086d7f5d3SJohn Marino.Nm ether_line , 4186d7f5d3SJohn Marino.Nm ether_aton , 4286d7f5d3SJohn Marino.Nm ether_aton_r , 4386d7f5d3SJohn Marino.Nm ether_ntoa , 4486d7f5d3SJohn Marino.Nm ether_ntoa_r , 4586d7f5d3SJohn Marino.Nm ether_ntohost , 4686d7f5d3SJohn Marino.Nm ether_hostton 4786d7f5d3SJohn Marino.Nd Ethernet address conversion and lookup routines 4886d7f5d3SJohn Marino.Sh LIBRARY 4986d7f5d3SJohn Marino.Lb libc 5086d7f5d3SJohn Marino.Sh SYNOPSIS 5186d7f5d3SJohn Marino.In sys/types.h 5286d7f5d3SJohn Marino.In sys/socket.h 5386d7f5d3SJohn Marino.In net/ethernet.h 5486d7f5d3SJohn Marino.Ft int 5586d7f5d3SJohn Marino.Fn ether_line "const char *l" "struct ether_addr *e" "char *hostname" 5686d7f5d3SJohn Marino.Ft struct ether_addr * 5786d7f5d3SJohn Marino.Fn ether_aton "const char *a" 5886d7f5d3SJohn Marino.Ft struct ether_addr * 5986d7f5d3SJohn Marino.Fn ether_aton_r "const char *a" "struct ether_addr *e" 6086d7f5d3SJohn Marino.Ft char * 6186d7f5d3SJohn Marino.Fn ether_ntoa "const struct ether_addr *n" 6286d7f5d3SJohn Marino.Ft char * 6386d7f5d3SJohn Marino.Fn ether_ntoa_r "const struct ether_addr *n" "char *buf" 6486d7f5d3SJohn Marino.Ft int 6586d7f5d3SJohn Marino.Fn ether_ntohost "char *hostname" "const struct ether_addr *e" 6686d7f5d3SJohn Marino.Ft int 6786d7f5d3SJohn Marino.Fn ether_hostton "const char *hostname" "struct ether_addr *e" 6886d7f5d3SJohn Marino.Sh DESCRIPTION 6986d7f5d3SJohn MarinoThese functions operate on ethernet addresses using an 7086d7f5d3SJohn Marino.Vt ether_addr 7186d7f5d3SJohn Marinostructure, which is defined in the header file 7286d7f5d3SJohn Marino.In netinet/if_ether.h : 7386d7f5d3SJohn Marino.Bd -literal -offset indent 7486d7f5d3SJohn Marino/* 7586d7f5d3SJohn Marino * The number of bytes in an ethernet (MAC) address. 7686d7f5d3SJohn Marino */ 7786d7f5d3SJohn Marino#define ETHER_ADDR_LEN 6 7886d7f5d3SJohn Marino 7986d7f5d3SJohn Marino/* 8086d7f5d3SJohn Marino * Structure of a 48-bit Ethernet address. 8186d7f5d3SJohn Marino */ 8286d7f5d3SJohn Marinostruct ether_addr { 8386d7f5d3SJohn Marino u_char octet[ETHER_ADDR_LEN]; 8486d7f5d3SJohn Marino}; 8586d7f5d3SJohn Marino.Ed 8686d7f5d3SJohn Marino.Pp 8786d7f5d3SJohn MarinoThe function 8886d7f5d3SJohn Marino.Fn ether_line 8986d7f5d3SJohn Marinoscans 9086d7f5d3SJohn Marino.Fa l , 9186d7f5d3SJohn Marinoan 9286d7f5d3SJohn Marino.Tn ASCII 9386d7f5d3SJohn Marinostring in 9486d7f5d3SJohn Marino.Xr ethers 5 9586d7f5d3SJohn Marinoformat and sets 9686d7f5d3SJohn Marino.Fa e 9786d7f5d3SJohn Marinoto the ethernet address specified in the string and 9886d7f5d3SJohn Marino.Fa h 9986d7f5d3SJohn Marinoto the hostname. 10086d7f5d3SJohn MarinoThis function is used to parse lines from 10186d7f5d3SJohn Marino.Pa /etc/ethers 10286d7f5d3SJohn Marinointo their component parts. 10386d7f5d3SJohn Marino.Pp 10486d7f5d3SJohn MarinoThe 10586d7f5d3SJohn Marino.Fn ether_aton 10686d7f5d3SJohn Marinoand 10786d7f5d3SJohn Marino.Fn ether_aton_r 10886d7f5d3SJohn Marinofunctions convert 10986d7f5d3SJohn Marino.Tn ASCII 11086d7f5d3SJohn Marinorepresentation of ethernet addresses into 11186d7f5d3SJohn Marino.Vt ether_addr 11286d7f5d3SJohn Marinostructures. 11386d7f5d3SJohn MarinoLikewise, the 11486d7f5d3SJohn Marino.Fn ether_ntoa 11586d7f5d3SJohn Marinoand 11686d7f5d3SJohn Marino.Fn ether_ntoa_r 11786d7f5d3SJohn Marinofunctions 11886d7f5d3SJohn Marinoconvert ethernet addresses specified as 11986d7f5d3SJohn Marino.Vt ether_addr 12086d7f5d3SJohn Marinostructures into 12186d7f5d3SJohn Marino.Tn ASCII 12286d7f5d3SJohn Marinostrings. 12386d7f5d3SJohn Marino.Pp 12486d7f5d3SJohn MarinoThe 12586d7f5d3SJohn Marino.Fn ether_ntohost 12686d7f5d3SJohn Marinoand 12786d7f5d3SJohn Marino.Fn ether_hostton 12886d7f5d3SJohn Marinofunctions map ethernet addresses to their corresponding hostnames 12986d7f5d3SJohn Marinoas specified in the 13086d7f5d3SJohn Marino.Pa /etc/ethers 13186d7f5d3SJohn Marinodatabase. 13286d7f5d3SJohn MarinoThe 13386d7f5d3SJohn Marino.Fn ether_ntohost 13486d7f5d3SJohn Marinofunction 13586d7f5d3SJohn Marinoconverts from ethernet address to hostname, and 13686d7f5d3SJohn Marino.Fn ether_hostton 13786d7f5d3SJohn Marinoconverts from hostname to ethernet address. 13886d7f5d3SJohn Marino.Sh RETURN VALUES 13986d7f5d3SJohn MarinoThe 14086d7f5d3SJohn Marino.Fn ether_line 14186d7f5d3SJohn Marinofunction 14286d7f5d3SJohn Marinoreturns zero on success and non-zero if it was unable to parse 14386d7f5d3SJohn Marinoany part of the supplied line 14486d7f5d3SJohn Marino.Fa l . 14586d7f5d3SJohn MarinoIt returns the extracted ethernet address in the supplied 14686d7f5d3SJohn Marino.Vt ether_addr 14786d7f5d3SJohn Marinostructure 14886d7f5d3SJohn Marino.Fa e 14986d7f5d3SJohn Marinoand the hostname in the supplied string 15086d7f5d3SJohn Marino.Fa h . 15186d7f5d3SJohn Marino.Pp 15286d7f5d3SJohn MarinoOn success, 15386d7f5d3SJohn Marino.Fn ether_ntoa 15486d7f5d3SJohn Marinoand 15586d7f5d3SJohn Marino.Fn ether_ntoa_r 15686d7f5d3SJohn Marinofunctions return a pointer to a string containing an 15786d7f5d3SJohn Marino.Tn ASCII 15886d7f5d3SJohn Marinorepresentation of an ethernet address. 15986d7f5d3SJohn MarinoIf it is unable to convert 16086d7f5d3SJohn Marinothe supplied 16186d7f5d3SJohn Marino.Vt ether_addr 16286d7f5d3SJohn Marinostructure, it returns a 16386d7f5d3SJohn Marino.Dv NULL 16486d7f5d3SJohn Marinopointer. 16586d7f5d3SJohn Marino.Fn ether_ntoa 16686d7f5d3SJohn Marinostores the result in a static buffer; 16786d7f5d3SJohn Marino.Fn ether_ntoa_r 16886d7f5d3SJohn Marinostores the result in a user-passed buffer. 16986d7f5d3SJohn Marino.Pp 17086d7f5d3SJohn MarinoLikewise, 17186d7f5d3SJohn Marino.Fn ether_aton 17286d7f5d3SJohn Marinoand 17386d7f5d3SJohn Marino.Fn ether_aton_r 17486d7f5d3SJohn Marinoreturn a pointer to an 17586d7f5d3SJohn Marino.Vt ether_addr 17686d7f5d3SJohn Marinostructure on success and a 17786d7f5d3SJohn Marino.Dv NULL 17886d7f5d3SJohn Marinopointer on failure. 17986d7f5d3SJohn Marino.Fn ether_aton 18086d7f5d3SJohn Marinostores the result in a static buffer; 18186d7f5d3SJohn Marino.Fn ether_aton_r 18286d7f5d3SJohn Marinostores the result in a user-passed buffer. 18386d7f5d3SJohn Marino.Pp 18486d7f5d3SJohn MarinoThe 18586d7f5d3SJohn Marino.Fn ether_ntohost 18686d7f5d3SJohn Marinoand 18786d7f5d3SJohn Marino.Fn ether_hostton 18886d7f5d3SJohn Marinofunctions both return zero on success or non-zero if they were 18986d7f5d3SJohn Marinounable to find a match in the 19086d7f5d3SJohn Marino.Pa /etc/ethers 19186d7f5d3SJohn Marinodatabase. 19286d7f5d3SJohn Marino.Sh NOTES 19386d7f5d3SJohn MarinoThe user must insure that the hostname strings passed to the 19486d7f5d3SJohn Marino.Fn ether_line , 19586d7f5d3SJohn Marino.Fn ether_ntohost 19686d7f5d3SJohn Marinoand 19786d7f5d3SJohn Marino.Fn ether_hostton 19886d7f5d3SJohn Marinofunctions are large enough to contain the returned hostnames. 19986d7f5d3SJohn Marino.Sh NIS INTERACTION 20086d7f5d3SJohn MarinoIf the 20186d7f5d3SJohn Marino.Pa /etc/ethers 20286d7f5d3SJohn Marinocontains a line with a single + in it, the 20386d7f5d3SJohn Marino.Fn ether_ntohost 20486d7f5d3SJohn Marinoand 20586d7f5d3SJohn Marino.Fn ether_hostton 20686d7f5d3SJohn Marinofunctions will attempt to consult the NIS 20786d7f5d3SJohn Marino.Pa ethers.byname 20886d7f5d3SJohn Marinoand 20986d7f5d3SJohn Marino.Pa ethers.byaddr 21086d7f5d3SJohn Marinomaps in addition to the data in the 21186d7f5d3SJohn Marino.Pa /etc/ethers 21286d7f5d3SJohn Marinofile. 21386d7f5d3SJohn Marino.Sh SEE ALSO 21486d7f5d3SJohn Marino.Xr ethers 5 , 21586d7f5d3SJohn Marino.Xr yp 8 21686d7f5d3SJohn Marino.Sh HISTORY 21786d7f5d3SJohn MarinoThis particular implementation of the 21886d7f5d3SJohn Marino.Nm 21986d7f5d3SJohn Marinolibrary functions were written for and first appeared in 22086d7f5d3SJohn Marino.Fx 2.1 . 22186d7f5d3SJohn MarinoThread-safe function variants first appeared in 22286d7f5d3SJohn Marino.Fx 7.0 . 22386d7f5d3SJohn Marino.Sh BUGS 22486d7f5d3SJohn MarinoThe 22586d7f5d3SJohn Marino.Fn ether_aton 22686d7f5d3SJohn Marinoand 22786d7f5d3SJohn Marino.Fn ether_ntoa 22886d7f5d3SJohn Marinofunctions returns values that are stored in static memory areas 22986d7f5d3SJohn Marinowhich may be overwritten the next time they are called. 23086d7f5d3SJohn Marino.Pp 23186d7f5d3SJohn Marino.Fn ether_ntoa_r 23286d7f5d3SJohn Marinoaccepts a character buffer pointer, but not a buffer length. 23386d7f5d3SJohn MarinoThe caller must ensure adequate space is available in the buffer in order to 23486d7f5d3SJohn Marinoavoid a buffer overflow. 235