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