xref: /freebsd/lib/libc/net/ethers.3 (revision 453196eb04d88ed1bc05b91f47e08e81facc7c35)
18b4709faSBill Paul.\" Copyright (c) 1995
28b4709faSBill Paul.\"	Bill Paul <wpaul@ctr.columbia.edu>.  All rights reserved.
38b4709faSBill Paul.\"
48b4709faSBill Paul.\" Redistribution and use in source and binary forms, with or without
58b4709faSBill Paul.\" modification, are permitted provided that the following conditions
68b4709faSBill Paul.\" are met:
78b4709faSBill Paul.\" 1. Redistributions of source code must retain the above copyright
88b4709faSBill Paul.\"    notice, this list of conditions and the following disclaimer.
98b4709faSBill Paul.\" 2. Redistributions in binary form must reproduce the above copyright
108b4709faSBill Paul.\"    notice, this list of conditions and the following disclaimer in the
118b4709faSBill Paul.\"    documentation and/or other materials provided with the distribution.
128b4709faSBill Paul.\" 3. All advertising materials mentioning features or use of this software
138b4709faSBill Paul.\"    must display the following acknowledgement:
148b4709faSBill Paul.\"	This product includes software developed by Bill Paul.
158b4709faSBill Paul.\" 4. Neither the name of the author nor the names of any co-contributors
168b4709faSBill Paul.\"    may be used to endorse or promote products derived from this software
178b4709faSBill Paul.\"    without specific prior written permission.
188b4709faSBill Paul.\"
198b4709faSBill Paul.\" THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND
208b4709faSBill Paul.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
218b4709faSBill Paul.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
228b4709faSBill Paul.\" ARE DISCLAIMED.  IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
238b4709faSBill Paul.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
248b4709faSBill Paul.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
258b4709faSBill Paul.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
268b4709faSBill Paul.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
278b4709faSBill Paul.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
288b4709faSBill Paul.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
298b4709faSBill Paul.\" SUCH DAMAGE.
308b4709faSBill Paul.\"
311130b656SJordan K. Hubbard.\"     $FreeBSD$
328b4709faSBill Paul.\"
338b4709faSBill Paul.Dd April 12, 1995
348b4709faSBill Paul.Dt ETHERS 3
358b4709faSBill Paul.Os FreeBSD 2.1
368b4709faSBill Paul.Sh NAME
378b4709faSBill Paul.Nm ethers ,
388b4709faSBill Paul.Nm ether_line ,
398b4709faSBill Paul.Nm ether_aton ,
408b4709faSBill Paul.Nm ether_ntoa ,
418b4709faSBill Paul.Nm ether_ntohost ,
428b4709faSBill Paul.Nm ether_hostton
438b4709faSBill Paul.Nd Ethernet address conversion and lookup routines
448b4709faSBill Paul.Sh SYNOPSIS
458b4709faSBill Paul.Fd #include <sys/types.h>
468b4709faSBill Paul.Fd #include <sys/socket.h>
4713629194SGarrett Wollman.Fd #include <net/ethernet.h>
488b4709faSBill Paul.Ft int
498b4709faSBill Paul.Fn ether_line "char *l" "struct ether_addr *e" "char *hostname"
508b4709faSBill Paul.Ft struct ether_addr *
518b4709faSBill Paul.Fn ether_aton "char *a"
528b4709faSBill Paul.Ft char *
538b4709faSBill Paul.Fn ether_ntoa "struct ether_addr *n"
548b4709faSBill Paul.Ft int
558b4709faSBill Paul.Fn ether_ntohost "char *hostname" "struct ether_addr *e"
568b4709faSBill Paul.Ft int
578b4709faSBill Paul.Fn ether_hostton "char *hostname" "struct ether_addr *e"
588b4709faSBill Paul.Sh DESCRIPTION
598b4709faSBill PaulThese functions operate on ethernet addresses using an
608b4709faSBill Paul.Ar ether_addr
618b4709faSBill Paulstructure, which is defined in the header file
628b4709faSBill Paul.Aq Pa netinet/if_ether.h :
638b4709faSBill Paul.Bd -literal -offset indent
648b4709faSBill Paul/*
65453196ebSMike Pritchard * The number of bytes in an ethernet (MAC) address.
66453196ebSMike Pritchard */
67453196ebSMike Pritchard#define ETHER_ADDR_LEN		6
68453196ebSMike Pritchard
69453196ebSMike Pritchard/*
708b4709faSBill Paul * Structure of a 48-bit Ethernet address.
718b4709faSBill Paul */
728b4709faSBill Paulstruct  ether_addr {
73453196ebSMike Pritchard        u_char octet[ETHER_ADDR_LEN];
748b4709faSBill Paul};
758b4709faSBill Paul.Ed
768b4709faSBill Paul.Pp
778b4709faSBill PaulThe function
788b4709faSBill Paul.Fn ether_line
798b4709faSBill Paulscans
808b4709faSBill Paul.Ar l ,
818b4709faSBill Paulan
828b4709faSBill Paul.Tn ASCII
838b4709faSBill Paulstring in
848b4709faSBill Paul.Xr ethers 5
858b4709faSBill Paulformat and sets
868b4709faSBill Paul.Ar e
878b4709faSBill Paulto the ethernet address specified in the string and
888b4709faSBill Paul.Ar h
898b4709faSBill Paulto the hostname. This function is used to parse lines from
908b4709faSBill Paul.Pa /etc/ethers
918b4709faSBill Paulinto their component parts.
928b4709faSBill Paul.Pp
938b4709faSBill PaulThe
948b4709faSBill Paul.Fn ether_aton
958b4709faSBill Paulfunction converts an
968b4709faSBill Paul.Tn ASCII
978b4709faSBill Paulrepresentation of an ethernet address into an
988b4709faSBill Paul.Ar ether_addr
998b4709faSBill Paulstructure. Likewise,
1008b4709faSBill Paul.Fn ether_ntoa
1018b4709faSBill Paulconverts an ethernet address specified as an
1028b4709faSBill Paul.Ar ether_addr
1038b4709faSBill Paulstructure into an
1048b4709faSBill Paul.Tn ASCII
1058b4709faSBill Paulstring.
1068b4709faSBill Paul.Pp
1078b4709faSBill PaulThe
1088b4709faSBill Paul.Fn ether_ntohost
1098b4709faSBill Pauland
1108b4709faSBill Paul.Fn ether_hostton
1118b4709faSBill Paulfunctions map ethernet addresses to their corresponding hostnames
1128b4709faSBill Paulas specified in the
1138b4709faSBill Paul.Pa /etc/ethers
1148b4709faSBill Pauldatabase.
1158b4709faSBill Paul.Fn ether_ntohost
1168b4709faSBill Paulconverts from ethernet address to hostname, and
1178b4709faSBill Paul.Fn ether_hostton
1188b4709faSBill Paulconverts from hostname to ethernet address.
1198b4709faSBill Paul.Sh RETURN VALUES
1208b4709faSBill Paul.Fn ether_line
1218b4709faSBill Paulreturns zero on success and non-zero if it was unable to parse
1228b4709faSBill Paulany part of the supplied line
1238b4709faSBill Paul.Ar l .
1248b4709faSBill PaulIt returns the extracted ethernet address in the supplied
1258b4709faSBill Paul.Ar ether_addr
1268b4709faSBill Paulstructure
1278b4709faSBill Paul.Ar e
1288b4709faSBill Pauland the hostname in the supplied string
1298b4709faSBill Paul.Ar h .
1308b4709faSBill Paul.Pp
1318b4709faSBill PaulOn success,
1328b4709faSBill Paul.Fn ether_ntoa
1338b4709faSBill Paulreturns a pointer to a string containing an
1348b4709faSBill Paul.Tn ASCII
1358b4709faSBill Paulrepresentation of an ethernet address. If it is unable to convert
1368b4709faSBill Paulthe supplied
1378b4709faSBill Paul.Ar ether_addr
138453196ebSMike Pritchardstructure, it returns a
139453196ebSMike Pritchard.Dv NULL
140453196ebSMike Pritchardpointer. Likewise,
1418b4709faSBill Paul.Fn ether_aton
1428b4709faSBill Paulreturns a pointer to an
1438b4709faSBill Paul.Ar ether_addr
144453196ebSMike Pritchardstructure on success and a
145453196ebSMike Pritchard.Dv NULL
146453196ebSMike Pritchardpointer on failure.
1478b4709faSBill Paul.Pp
1488b4709faSBill PaulThe
1498b4709faSBill Paul.Fn ether_ntohost
1508b4709faSBill Pauland
1518b4709faSBill Paul.Fn ether_hostton
1528b4709faSBill Paulfunctions both return zero on success or non-zero if they were
1538b4709faSBill Paulunable to find a match in the
1548b4709faSBill Paul.Pa /etc/ethers
1558b4709faSBill Pauldatabase.
1568b4709faSBill Paul.Sh NOTES
1578b4709faSBill PaulThe user must insure that the hostname strings passed to the
1588b4709faSBill Paulthe
1598b4709faSBill Paul.Fn ether_line ,
1608b4709faSBill Paul.Fn ether_ntohost
1618b4709faSBill Pauland
1628b4709faSBill Paul.Fn ether_hostton
1638b4709faSBill Paulfunctions are large enough to contain the returned hostnames.
1648b4709faSBill Paul.Sh NIS INTERACTION
1658b4709faSBill PaulIf the
1668b4709faSBill Paul.Pa /etc/ethers
1678b4709faSBill Paulcontains a line with a single + in it, the
1688b4709faSBill Paul.Fn ether_ntohost
1698b4709faSBill Pauland
1708b4709faSBill Paul.Fn ether_hostton
1718b4709faSBill Paulfunctions will attempt to consult the NIS
1728b4709faSBill Paul.Pa ethers.byname
1738b4709faSBill Pauland
1748b4709faSBill Paul.Pa ethers.byaddr
1758b4709faSBill Paulmaps in addition to the data in the
1768b4709faSBill Paul.Pa /etc/ethers
1778b4709faSBill Paulfile.
1788b4709faSBill Paul.Sh SEE ALSO
17978b0b234SMike Pritchard.Xr yp 4 ,
18078b0b234SMike Pritchard.Xr ethers 5
1818b4709faSBill Paul.Sh BUGS
1828b4709faSBill Paul.Pp
1838b4709faSBill PaulThe
1848b4709faSBill Paul.Fn ether_aton
1858b4709faSBill Pauland
1868b4709faSBill Paul.Fn ether_ntoa
1878b4709faSBill Paulfunctions returns values that are stored in static memory areas
1888b4709faSBill Paulwhich may be overwritten the next time they are called.
1898b4709faSBill Paul.Sh HISTORY
1908b4709faSBill PaulThis particular implementation of the
1918b4709faSBill Paul.Nm ethers
192a2d402aaSMike Pritchardlibrary functions were written for and first appeared in
193a2d402aaSMike Pritchard.Fx 2.1 .
194