ether_addr.c revision 2
2N/A * The contents of this file are subject to the terms of the 2N/A * Common Development and Distribution License (the "License"). 2N/A * You may not use this file except in compliance with the License. 2N/A * See the License for the specific language governing permissions 2N/A * and limitations under the License. 2N/A * When distributing Covered Code, include this CDDL HEADER in each 2N/A * If applicable, add the following below this CDDL HEADER, with the 2N/A * fields enclosed by brackets "[]" replaced with your own identifying 2N/A * information: Portions Copyright [yyyy] [name of copyright owner] 2N/A * Copyright (c) 1990, 2011, Oracle and/or its affiliates. All rights reserved. 2N/A/* Copyright (c) 1984, 1986, 1987, 1988, 1989 AT&T */ 2N/A/* All Rights Reserved */ 2N/A * University Copyright- Copyright (c) 1982, 1986, 1988 2N/A * The Regents of the University of California 2N/A * All Rights Reserved 2N/A * University Acknowledgment- Portions of this document are derived from 2N/A * software developed by the University of California, Berkeley, and its 2N/A * All routines necessary to deal the "ethers" database. The sources 2N/A * contain mappings between 48 bit ethernet addresses and corresponding 2N/A * hosts names. The addresses have an ascii representation of the form 2N/A * "x:x:x:x:x:x" where x is a hex number between 0x00 and 0xff; the 2N/A * bytes are always in network order. 2N/A * Given a host's name, this routine finds the corresponding 48 bit 2N/A * Returns zero if successful, non-zero otherwise. 2N/A const char *
host,
/* function input */ 2N/A * let the backend do the allocation to store stuff for parsing. 2N/A * Given a 48 bit ethernet address, it finds the corresponding hostname 2N/A * Returns zero if successful, non-zero otherwise. 2N/A * let the backend do the allocation to store stuff for parsing. 2N/A * Parses a line from "ethers" database into its components. The line has 2N/A * the form 8:0:20:1:17:c8 krypton 2N/A * where the first part is a 48 bit ethernet address and the second is 2N/A * the corresponding hosts name. 2N/A * Returns zero if successful, non-zero otherwise. 2N/A const char *s,
/* the string to be parsed */ 2N/A struct ether_addr *e,
/* ethernet address struct to be filled in */ 2N/A /* LINTED unbounded string specifier */ 2N/A for (i = 0; i <
6; i++)
2N/A * Parses a line from "ethers" database into its components. 2N/A * Useful for the vile purposes of the backends that 2N/A * expect a str2ether() format. 2N/A * This function, after parsing the instr line, will 2N/A * place the resulting struct ether_addr in b->buf.result only if 2N/A * b->buf.result is initialized (not NULL). I.e. it always happens 2N/A * for "files" backend (that needs to parse input line and 2N/A * then do a match for the ether key) and happens for "nis" 2N/A * backend only if the call was ether_hostton. 2N/A * Also, it will place the resulting hostname into b->buf.buffer 2N/A * only if b->buf.buffer is initialized. I.e. it always happens 2N/A * for "files" backend (that needs to parse input line and 2N/A * then do a match for the host key) and happens for "nis" 2N/A * backend only if the call was ether_ntohost. 2N/A * Cannot use the sscanf() technique for parsing because instr 2N/A * is a read-only, not necessarily null-terminated, buffer. 2N/A * Return values: 0 = success, 1 = parse error, 2 = erange ... 2N/A * The structure pointer passed in is a structure in the caller's space 2N/A * wherein the field pointers would be set to areas in the buffer if 2N/A * need be. instring and buffer should be separate areas. 2N/A ((x) >=
'a' && (x) <=
'z') || ((x) >=
'A' && (x) <=
'Z'))
2N/A /* skip beginning whitespace, if any */ 2N/A for (i = 0; i <
6; i++) {
2N/A /* don't worry about overflow here */ 2N/A if (*p !=
':' && i <
5) {
2N/A }
else {
/* skip ether */ 2N/A * Converts a 48 bit ethernet number to its string representation. 2N/A * Converts an ethernet address representation back into its 48 bits. 2N/A &t[0], &t[
1], &t[
2], &t[
3], &t[
4], &t[
5]);
2N/A for (i = 0; i <
6; i++)