4 * The contents of this file are subject to the terms of the
5 * Common Development and Distribution License, Version 1.0 only
6 * (the "License"). You may not use this file except in compliance
9 * You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
10 * or http://www.opensolaris.org/os/licensing.
11 * See the License for the specific language governing permissions
12 * and limitations under the License.
14 * When distributing Covered Code, include this CDDL HEADER in each
15 * file and include the License file at usr/src/OPENSOLARIS.LICENSE.
16 * If applicable, add the following below this CDDL HEADER, with the
17 * fields enclosed by brackets "[]" replaced with your own identifying
18 * information: Portions Copyright [yyyy] [name of copyright owner]
23 * Copyright 1990 Sun Microsystems, Inc. All rights reserved.
24 * Use is subject to license terms.
27 #pragma ident "%Z%%M% %I% %E% SMI"
30 * All routines necessary to deal with the file /etc/ethers. The file
31 * contains mappings from 48 bit ethernet addresses to their corresponding
32 * hosts name. The addresses have an ascii representation of the form
33 * "x:x:x:x:x:x" where x is a hex number between 0x00 and 0xff; the
34 * bytes are always in network order.
38 #include <sys/types.h>
39 #include <sys/socket.h>
41 #include <netinet/in.h>
42 #include <net/if_arp.h>
43 #include <netinet/if_ether.h>
45 static char *domain
; /* NIS domain name */
46 static int usingyellow
;
47 static char *ethers
= "/etc/ethers";
50 * Parses a line from /etc/ethers into its components. The line has the form
51 * 8:0:20:1:17:c8 krypton
52 * where the first part is a 48 bit ethernet addrerss and the second is
53 * the corresponding hosts name.
54 * Returns zero if successful, non-zero otherwise.
57 * s: the string to be parsed
58 * e: ethernet address struct to be filled in
59 * hostname: hosts name to be set
62 ether_line(char *s
, struct ether_addr
*e
, char *hostname
)
67 i
= sscanf(s
, " %x:%x:%x:%x:%x:%x %s",
68 &t
[0], &t
[1], &t
[2], &t
[3], &t
[4], &t
[5], hostname
);
72 for (i
= 0; i
< 6; i
++)
73 e
->ether_addr_octet
[i
] = t
[i
];
78 * Converts a 48 bit ethernet number to its string representation.
80 #define EI(i) (unsigned int)(e->ether_addr_octet[(i)])
82 ether_ntoa(struct ether_addr
*e
)
87 s
= (char *)malloc(18);
92 sprintf(s
, "%x:%x:%x:%x:%x:%x",
93 EI(0), EI(1), EI(2), EI(3), EI(4), EI(5));
98 * Converts a ethernet address representation back into its 48 bits.
103 static struct ether_addr
*ep
;
108 ep
= (struct ether_addr
*)calloc(1, sizeof (struct ether_addr
));
112 i
= sscanf(s
, " %x:%x:%x:%x:%x:%x",
113 &t
[0], &t
[1], &t
[2], &t
[3], &t
[4], &t
[5]);
115 return ((struct ether_addr
*)NULL
);
116 for (i
= 0; i
< 6; i
++)
117 ep
->ether_addr_octet
[i
] = t
[i
];