xref: /netbsd/lib/libc/net/ethers.3 (revision bf9ec67e)
1.\"	$NetBSD: ethers.3,v 1.10 2002/02/07 07:00:20 ross Exp $
2.\"
3.\" Written by roland@frob.com.  Public domain.
4.\"
5.Dd November 2, 1997
6.Dt ETHERS 3
7.Os
8.Sh NAME
9.Nm ether_ntoa ,
10.Nm ether_aton ,
11.Nm ether_ntohost ,
12.Nm ether_hostton ,
13.Nm ether_line ,
14.Nd get ethers entry
15.Sh LIBRARY
16.Lb libc
17.Sh SYNOPSIS
18.Fd #include \*[Lt]net/if_ether.h\*[Gt]
19.Ft char *
20.Fn ether_ntoa "struct ether_addr *e"
21.Ft struct ether_addr *
22.Fn ether_aton "const char *s"
23.Ft int
24.Fn ether_ntohost "char *hostname" "struct ether_addr *e"
25.Ft int
26.Fn ether_hostton "const char *hostname" "struct ether_addr *e"
27.Ft int
28.Fn ether_line "const char *line" "struct ether_addr *e" "char *hostname"
29.Sh DESCRIPTION
30Ethernet addresses are represented by the
31following structure:
32.Bd -literal -offset indent
33struct ether_addr {
34        u_char  ether_addr_octet[6];
35};
36.Ed
37.Pp
38The
39.Fn ether_ntoa
40function converts this structure into an ASCII string of the form
41``xx:xx:xx:xx:xx:xx'', consisting of 6 hexadecimal numbers separated
42by colons.  It returns a pointer to a static buffer that is reused for
43each call.
44The
45.Fn ether_aton
46converts an ASCII string of the same form and to a structure
47containing the 6 octets of the address.  It returns a pointer to a
48static structure that is reused for each call.
49.Pp
50The
51.Fn ether_ntohost
52and
53.Fn ether_hostton
54functions interrogate the data base mapping host names to Ethernet
55addresses,
56.Pa /etc/ethers .
57The
58.Fn ether_ntohost
59function looks up the given Ethernet address and writes the associated
60host name into the character buffer passed.
61The
62.Fn ether_hostton
63function looks up the given host name and writes the associated
64Ethernet address into the structure passed.  Both functions return
65zero if they find the requested host name or address, and -1 if not.
66Each call reads
67.Pa /etc/ethers
68from the beginning; if a + appears alone on a line in the file, then
69.Fn ether_hostton
70will consult the
71.Pa ethers.byname
72YP map, and
73.Fn ether_ntohost
74will consult the
75.Pa ethers.byaddr
76YP map.
77.Pp
78The
79.Fn ether_line
80function parses a line from the
81.Pa /etc/ethers
82file and fills in the passed ``struct ether_addr'' and character
83buffer with the Ethernet address and host name on the line.  It
84returns zero if the line was successfully parsed and -1 if not.
85.Pp
86The
87.Fa hostname
88buffer for
89.Fn ether_line
90and
91.Fn ether_ntohost
92should be at least
93.Dv MAXHOSTNAMELEN
94+ 1
95characters long, to prevent a buffer overflow during parsing.
96.Sh FILES
97.Bl -tag -width /etc/ethers -compact
98.It Pa /etc/ethers
99.El
100.Sh SEE ALSO
101.Xr ethers 5
102.Sh HISTORY
103The
104.Fn ether_ntoa ,
105.Fn ether_aton ,
106.Fn ether_ntohost ,
107.Fn ether_hostton ,
108and
109.Fn ether_line
110functions were adopted from
111.Tn SunOS
112and appeared in
113.Nx 1.0 .
114.Sh BUGS
115The data space used by these functions is static; if future use
116requires the data, it should be copied before any subsequent calls to
117these functions overwrite it.
118