xref: /freebsd/lib/libc/net/ethers.3 (revision 8b4709fa9389fcf00bfccdb11fb39792e584fc14)
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.\"
318b4709faSBill Paul.\"     $Id$
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>
478b4709faSBill Paul.Fd #include <net/if.h>
488b4709faSBill Paul.Fd #include <netinet/in.h>
498b4709faSBill Paul.Fd #include <netinet/if_ether.h>
508b4709faSBill Paul.Ft int
518b4709faSBill Paul.Fn ether_line "char *l" "struct ether_addr *e" "char *hostname"
528b4709faSBill Paul.Ft struct ether_addr *
538b4709faSBill Paul.Fn ether_aton "char *a"
548b4709faSBill Paul.Ft char *
558b4709faSBill Paul.Fn ether_ntoa "struct ether_addr *n"
568b4709faSBill Paul.Ft int
578b4709faSBill Paul.Fn ether_ntohost "char *hostname" "struct ether_addr *e"
588b4709faSBill Paul.Ft int
598b4709faSBill Paul.Fn ether_hostton "char *hostname" "struct ether_addr *e"
608b4709faSBill Paul.Sh DESCRIPTION
618b4709faSBill PaulThese functions operate on ethernet addresses using an
628b4709faSBill Paul.Ar ether_addr
638b4709faSBill Paulstructure, which is defined in the header file
648b4709faSBill Paul.Aq Pa netinet/if_ether.h :
658b4709faSBill Paul.Bd -literal -offset indent
668b4709faSBill Paul/*
678b4709faSBill Paul * Structure of a 48-bit Ethernet address.
688b4709faSBill Paul */
698b4709faSBill Paulstruct  ether_addr {
708b4709faSBill Paul        u_char octet[6];
718b4709faSBill Paul};
728b4709faSBill Paul.Ed
738b4709faSBill Paul.Pp
748b4709faSBill PaulThe function
758b4709faSBill Paul.Fn ether_line
768b4709faSBill Paulscans
778b4709faSBill Paul.Ar l ,
788b4709faSBill Paulan
798b4709faSBill Paul.Tn ASCII
808b4709faSBill Paulstring in
818b4709faSBill Paul.Xr ethers 5
828b4709faSBill Paulformat and sets
838b4709faSBill Paul.Ar e
848b4709faSBill Paulto the ethernet address specified in the string and
858b4709faSBill Paul.Ar h
868b4709faSBill Paulto the hostname. This function is used to parse lines from
878b4709faSBill Paul.Pa /etc/ethers
888b4709faSBill Paulinto their component parts.
898b4709faSBill Paul.Pp
908b4709faSBill PaulThe
918b4709faSBill Paul.Fn ether_aton
928b4709faSBill Paulfunction converts an
938b4709faSBill Paul.Tn ASCII
948b4709faSBill Paulrepresentation of an ethernet address into an
958b4709faSBill Paul.Ar ether_addr
968b4709faSBill Paulstructure. Likewise,
978b4709faSBill Paul.Fn ether_ntoa
988b4709faSBill Paulconverts an ethernet address specified as an
998b4709faSBill Paul.Ar ether_addr
1008b4709faSBill Paulstructure into an
1018b4709faSBill Paul.Tn ASCII
1028b4709faSBill Paulstring.
1038b4709faSBill Paul.Pp
1048b4709faSBill PaulThe
1058b4709faSBill Paul.Fn ether_ntohost
1068b4709faSBill Pauland
1078b4709faSBill Paul.Fn ether_hostton
1088b4709faSBill Paulfunctions map ethernet addresses to their corresponding hostnames
1098b4709faSBill Paulas specified in the
1108b4709faSBill Paul.Pa /etc/ethers
1118b4709faSBill Pauldatabase.
1128b4709faSBill Paul.Fn ether_ntohost
1138b4709faSBill Paulconverts from ethernet address to hostname, and
1148b4709faSBill Paul.Fn ether_hostton
1158b4709faSBill Paulconverts from hostname to ethernet address.
1168b4709faSBill Paul.Sh RETURN VALUES
1178b4709faSBill Paul.Fn ether_line
1188b4709faSBill Paulreturns zero on success and non-zero if it was unable to parse
1198b4709faSBill Paulany part of the supplied line
1208b4709faSBill Paul.Ar l .
1218b4709faSBill PaulIt returns the extracted ethernet address in the supplied
1228b4709faSBill Paul.Ar ether_addr
1238b4709faSBill Paulstructure
1248b4709faSBill Paul.Ar e
1258b4709faSBill Pauland the hostname in the supplied string
1268b4709faSBill Paul.Ar h .
1278b4709faSBill Paul.Pp
1288b4709faSBill PaulOn success,
1298b4709faSBill Paul.Fn ether_ntoa
1308b4709faSBill Paulreturns a pointer to a string containing an
1318b4709faSBill Paul.Tn ASCII
1328b4709faSBill Paulrepresentation of an ethernet address. If it is unable to convert
1338b4709faSBill Paulthe supplied
1348b4709faSBill Paul.Ar ether_addr
1358b4709faSBill Paulstructure, it returns a NULL pointer. Likewise,
1368b4709faSBill Paul.Fn ether_aton
1378b4709faSBill Paulreturns a pointer to an
1388b4709faSBill Paul.Ar ether_addr
1398b4709faSBill Paulstructure on success and a NULL pointer on failure.
1408b4709faSBill Paul.Pp
1418b4709faSBill PaulThe
1428b4709faSBill Paul.Fn ether_ntohost
1438b4709faSBill Pauland
1448b4709faSBill Paul.Fn ether_hostton
1458b4709faSBill Paulfunctions both return zero on success or non-zero if they were
1468b4709faSBill Paulunable to find a match in the
1478b4709faSBill Paul.Pa /etc/ethers
1488b4709faSBill Pauldatabase.
1498b4709faSBill Paul.Sh NOTES
1508b4709faSBill PaulThe user must insure that the hostname strings passed to the
1518b4709faSBill Paulthe
1528b4709faSBill Paul.Fn ether_line ,
1538b4709faSBill Paul.Fn ether_ntohost
1548b4709faSBill Pauland
1558b4709faSBill Paul.Fn ether_hostton
1568b4709faSBill Paulfunctions are large enough to contain the returned hostnames.
1578b4709faSBill Paul.Sh NIS INTERACTION
1588b4709faSBill PaulIf the
1598b4709faSBill Paul.Pa /etc/ethers
1608b4709faSBill Paulcontains a line with a single + in it, the
1618b4709faSBill Paul.Fn ether_ntohost
1628b4709faSBill Pauland
1638b4709faSBill Paul.Fn ether_hostton
1648b4709faSBill Paulfunctions will attempt to consult the NIS
1658b4709faSBill Paul.Pa ethers.byname
1668b4709faSBill Pauland
1678b4709faSBill Paul.Pa ethers.byaddr
1688b4709faSBill Paulmaps in addition to the data in the
1698b4709faSBill Paul.Pa /etc/ethers
1708b4709faSBill Paulfile.
1718b4709faSBill Paul.Sh SEE ALSO
1728b4709faSBill Paul.Xr ethers 5 ,
1738b4709faSBill Paul.Xr yp 8
1748b4709faSBill Paul.Sh BUGS
1758b4709faSBill Paul.Pp
1768b4709faSBill PaulThe
1778b4709faSBill Paul.Fn ether_aton
1788b4709faSBill Pauland
1798b4709faSBill Paul.Fn ether_ntoa
1808b4709faSBill Paulfunctions returns values that are stored in static memory areas
1818b4709faSBill Paulwhich may be overwritten the next time they are called.
1828b4709faSBill Paul.Sh HISTORY
1838b4709faSBill PaulThis particular implementation of the
1848b4709faSBill Paul.Nm ethers
1858b4709faSBill Paullibrary functions was written for and first appeared in FreeBSD 2.1.
186