From 47a646314de36e325ca294113c88cbecd1c402cc Mon Sep 17 00:00:00 2001 From: Hidetoshi Shimokawa Date: Thu, 23 Sep 2004 06:33:04 +0000 Subject: [PATCH] Add support for eui64(5) to libc. This is required for upcoming dconschat(8). Obtained from: FreeBSD --- lib/libc/net/Makefile.inc | 7 +- lib/libc/net/eui64.3 | 231 ++++++++++++++++++++++++++++ lib/libc/net/eui64.c | 315 ++++++++++++++++++++++++++++++++++++++ share/man/man5/eui64.5 | 111 ++++++++++++++ sys/sys/eui64.h | 58 +++++++ 5 files changed, 719 insertions(+), 3 deletions(-) create mode 100644 lib/libc/net/eui64.3 create mode 100644 lib/libc/net/eui64.c create mode 100644 share/man/man5/eui64.5 create mode 100644 sys/sys/eui64.h diff --git a/lib/libc/net/Makefile.inc b/lib/libc/net/Makefile.inc index 021dd1bfdd..df0be13ad2 100644 --- a/lib/libc/net/Makefile.inc +++ b/lib/libc/net/Makefile.inc @@ -1,11 +1,11 @@ # from @(#)Makefile.inc 8.2 (Berkeley) 9/5/93 # $FreeBSD: src/lib/libc/net/Makefile.inc,v 1.36.2.5 2002/07/29 18:33:18 ume Exp $ -# $DragonFly: src/lib/libc/net/Makefile.inc,v 1.2 2003/06/17 04:26:44 dillon Exp $ +# $DragonFly: src/lib/libc/net/Makefile.inc,v 1.3 2004/09/23 06:33:04 simokawa Exp $ # machine-independent net sources .PATH: ${.CURDIR}/../libc/${MACHINE_ARCH}/net ${.CURDIR}/../libc/net -SRCS+= addr2ascii.c ascii2addr.c base64.c ether_addr.c getaddrinfo.c \ +SRCS+= addr2ascii.c ascii2addr.c base64.c ether_addr.c eui64.c getaddrinfo.c \ gethostbydns.c gethostbyht.c gethostbynis.c gethostnamadr.c \ getifaddrs.c getnameinfo.c \ getnetbydns.c getnetbyht.c getnetbynis.c getnetnamadr.c \ @@ -28,7 +28,8 @@ CFLAGS+=-DINET6 .include "${.CURDIR}/../libc/${MACHINE_ARCH}/net/Makefile.inc" .if ${LIB} == "c" -MAN+= addr2ascii.3 byteorder.3 ethers.3 getaddrinfo.3 gethostbyname.3 \ +MAN+= addr2ascii.3 byteorder.3 ethers.3 eui64.3 \ + getaddrinfo.3 gethostbyname.3 \ getifaddrs.3 getipnodebyname.3 \ getnameinfo.3 getnetent.3 getprotoent.3 getservent.3 if_indextoname.3 \ inet.3 inet_net.3 \ diff --git a/lib/libc/net/eui64.3 b/lib/libc/net/eui64.3 new file mode 100644 index 0000000000..ad7ca1894d --- /dev/null +++ b/lib/libc/net/eui64.3 @@ -0,0 +1,231 @@ +.\" Copyright 2004 The Aerospace Corporation. All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions, and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions, and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. The name of The Aerospace Corporation may not be used to endorse or +.\" promote products derived from this software. +.\" +.\" THIS SOFTWARE IS PROVIDED BY THE AEROSPACE CORPORATION "AS IS" AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE AEROSPACE CORPORATION BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" Copyright (c) 1995 +.\" Bill Paul . All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by Bill Paul. +.\" 4. Neither the name of the author nor the names of any co-contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD: src/lib/libc/net/eui64.3,v 1.3 2004/07/07 20:15:31 ru Exp $ +.\" $DragonFly: src/lib/libc/net/eui64.3,v 1.1 2004/09/23 06:33:04 simokawa Exp $ +.\" +.Dd March 4, 2004 +.Dt EUI64 3 +.Os +.Sh NAME +.Nm eui64 , +.\" .Nm eui64_line , +.Nm eui64_aton , +.Nm eui64_ntoa , +.Nm eui64_ntohost , +.Nm eui64_hostton +.Nd IEEE EUI-64 conversion and lookup routines +.Sh LIBRARY +.Lb libc +.Sh SYNOPSIS +.In sys/types.h +.In sys/eui64.h +.\" .Ft int +.\" .Fn eui64_line "const char *l" "struct eui64 *e" "char *hostname" "size_t len" +.Ft int +.Fn eui64_aton "const char *a" "struct eui64 *e" +.Ft int +.Fn eui64_ntoa "const struct eui64 *id" "char *a" "size_t len" +.Ft int +.Fn eui64_ntohost "char *hostname" "size_t len" "const struct eui64 *id" +.Ft int +.Fn eui64_hostton "const char *hostname" "struct eui64 *id" +.Sh DESCRIPTION +These functions operate on IEEE EUI-64s using an +.Vt eui64 +structure, which is defined in the header file +.In sys/eui64.h : +.Bd -literal -offset indent +/* + * The number of bytes in an EUI-64. + */ +#define EUI64_LEN 8 + +/* + * Structure of an IEEE EUI-64. + */ +struct eui64 { + u_char octet[EUI64_LEN]; +}; +.Ed +.\" .Pp +.\" The function +.\" .Fn eui64_line +.\" scans +.\" .Fa l , +.\" an +.\" .Tn ASCII +.\" string in +.\" .Xr eui64 5 +.\" format and sets +.\" .Fa e +.\" to the EUI-64 specified in the string and +.\" .Fa h +.\" to the hostname. +.\" This function is used to parse lines from +.\" .Pa /etc/eui64 +.\" into their component parts. +.Pp +The +.Fn eui64_aton +function converts an +.Tn ASCII +representation of an EUI-64 into an +.Vt eui64 +structure. +Likewise, +.Fn eui64_ntoa +converts an EUI-64 specified as an +.Vt eui64 +structure into an +.Tn ASCII +string. +.Pp +The +.Fn eui64_ntohost +and +.Fn eui64_hostton +functions map EUI-64s to their corresponding hostnames +as specified in the +.Pa /etc/eui64 +database. +The +.Fn eui64_ntohost +function +converts from EUI-64 to hostname, and +.Fn eui64_hostton +converts from hostname to EUI-64. +.Sh RETURN VALUES +.\" The +.\" .Fn eui64_line +.\" function +.\" returns zero on success and non-zero if it was unable to parse +.\" any part of the supplied line +.\" .Fa l . +.\" It returns the extracted EUI-64 in the supplied +.\" .Vt eui64 +.\" structure +.\" .Fa e +.\" and the hostname in the supplied string +.\" .Fa h . +.\" .Pp +On success, +.Fn eui64_ntoa +returns a pointer to a string containing an +.Tn ASCII +representation of an EUI-64. +If it is unable to convert +the supplied +.Vt eui64 +structure, it returns a +.Dv NULL +pointer. +Likewise, +.Fn eui64_aton +returns a pointer to an +.Vt eui64 +structure on success and a +.Dv NULL +pointer on failure. +.Pp +The +.Fn eui64_ntohost +and +.Fn eui64_hostton +functions both return zero on success or non-zero if they were +unable to find a match in the +.Pa /etc/eui64 +database. +.Sh NOTES +The user must insure that the hostname strings passed to the +.\" .Fn eui64_line , +.Fn eui64_ntohost +and +.Fn eui64_hostton +functions are large enough to contain the returned hostnames. +.Sh NIS INTERACTION +If the +.Pa /etc/eui64 +contains a line with a single +.Ql + +in it, the +.Fn eui64_ntohost +and +.Fn eui64_hostton +functions will attempt to consult the NIS +.Pa eui64.byname +and +.Pa eui64.byid +maps in addition to the data in the +.Pa /etc/eui64 +file. +.Sh SEE ALSO +.Xr firewire 4 , +.Xr eui64 5 , +.Xr yp 8 +.Sh BUGS +The +.Fn eui64_aton +and +.Fn eui64_ntoa +functions returns values that are stored in static memory areas +which may be overwritten the next time they are called. +.Sh HISTORY +These functions first appears in +.Fx 5.3 . +They are derived from the +.Xr ethers 3 +family of functions. diff --git a/lib/libc/net/eui64.c b/lib/libc/net/eui64.c new file mode 100644 index 0000000000..7bca07f074 --- /dev/null +++ b/lib/libc/net/eui64.c @@ -0,0 +1,315 @@ +/* + * Copyright 2004 The Aerospace Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions, and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of The Aerospace Corporation may not be used to endorse or + * promote products derived from this software. + * + * THIS SOFTWARE IS PROVIDED BY THE AEROSPACE CORPORATION "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AEROSPACE CORPORATION BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * Copyright (c) 1995 + * Bill Paul . All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. All advertising materials mentioning features or use of this software + * must display the following acknowledgement: + * This product includes software developed by Bill Paul. + * 4. Neither the name of the author nor the names of any co-contributors + * may be used to endorse or promote products derived from this software + * without specific prior written permission. + * + * THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * EUI-64 conversion and lookup routines + * + * + * Converted from ether_addr.c rev + * FreeBSD: src/lib/libc/net/eui64.c,v 1.15 2002/04/08 07:51:10 ru Exp + * by Brooks Davis + * + * Written by Bill Paul + * Center for Telecommunications Research + * Columbia University, New York City + * + * $DragonFly: src/lib/libc/net/eui64.c,v 1.1 2004/09/23 06:33:04 simokawa Exp $ + */ + +#include +#ifdef __FBSDID__ +__FBSDID("$FreeBSD: src/lib/libc/net/eui64.c,v 1.2 2004/06/01 19:30:13 brooks Exp $"); +#endif + +#include +#include +#include +#include +#include +#include +#include +#ifdef YP +#include +#include +#include +#endif + +#ifndef _PATH_EUI64 +#define _PATH_EUI64 "/etc/eui64" +#endif + +static int eui64_line(const char *l, struct eui64 *e, char *hostname, + size_t len); + +/* + * Parse a string of text containing an EUI-64 and hostname + * and separate it into its component parts. + */ +static int +eui64_line(const char *l, struct eui64 *e, char *hostname, size_t len) +{ + char *line, *linehead, *cur; + + linehead = strdup(l); + if (linehead == NULL) + return (-1); + line = linehead; + + /* Find and parse the EUI64 */ + while ((cur = strsep(&line, " \t\r\n")) != NULL) { + if (*cur != '\0') { + if (eui64_aton(cur, e) == 0) + break; + else + goto bad; + } + } + + /* Find the hostname */ + while ((cur = strsep(&line, " \t\r\n")) != NULL) { + if (*cur != '\0') { + if (strlcpy(hostname, cur, len) <= len) + break; + else + goto bad; + } + } + + /* Make sure what remains is either whitespace or a comment */ + while ((cur = strsep(&line, " \t\r\n")) != NULL) { + if (*cur == '#') + break; + if (*cur != '\0') + goto bad; + } + + return (0); + +bad: + free(linehead); + return (-1); +} + +/* + * Convert an ASCII representation of an EUI-64 to binary form. + */ +int +eui64_aton(const char *a, struct eui64 *e) +{ + int i; + unsigned int o0, o1, o2, o3, o4, o5, o6, o7; + + /* canonical form */ + i = sscanf(a, "%x-%x-%x-%x-%x-%x-%x-%x", + &o0, &o1, &o2, &o3, &o4, &o5, &o6, &o7); + if (i == EUI64_LEN) + goto good; + /* ethernet form */ + i = sscanf(a, "%x:%x:%x:%x:%x:%x:%x:%x", + &o0, &o1, &o2, &o3, &o4, &o5, &o6, &o7); + if (i == EUI64_LEN) + goto good; + /* classic fwcontrol/dconschat form */ + i = sscanf(a, "0x%2x%2x%2x%2x%2x%2x%2x%2x", + &o0, &o1, &o2, &o3, &o4, &o5, &o6, &o7); + if (i == EUI64_LEN) + goto good; + /* MAC format (-) */ + i = sscanf(a, "%x-%x-%x-%x-%x-%x", + &o0, &o1, &o2, &o5, &o6, &o7); + if (i == 6) { + o3 = 0xff; + o4 = 0xfe; + goto good; + } + /* MAC format (:) */ + i = sscanf(a, "%x:%x:%x:%x:%x:%x", + &o0, &o1, &o2, &o5, &o6, &o7); + if (i == 6) { + o3 = 0xff; + o4 = 0xfe; + goto good; + } + + return (-1); + +good: + e->octet[0]=o0; + e->octet[1]=o1; + e->octet[2]=o2; + e->octet[3]=o3; + e->octet[4]=o4; + e->octet[5]=o5; + e->octet[6]=o6; + e->octet[7]=o7; + + return (0); +} + +/* + * Convert a binary representation of an EUI-64 to an ASCII string. + */ +int +eui64_ntoa(const struct eui64 *id, char *a, size_t len) +{ + int i; + + i = snprintf(a, len, "%02x-%02x-%02x-%02x-%02x-%02x-%02x-%02x", + id->octet[0], id->octet[1], id->octet[2], id->octet[3], + id->octet[4], id->octet[5], id->octet[6], id->octet[7]); + if (i < 23 || i >= len) + return (-1); + return (0); +} + +/* + * Map an EUI-64 to a hostname. Use either /etc/eui64 or NIS/YP. + */ +int +eui64_ntohost(char *hostname, size_t len, const struct eui64 *id) +{ + FILE *fp; + char buf[BUFSIZ + 2]; + struct eui64 local_eui64; + char local_host[MAXHOSTNAMELEN]; +#ifdef YP + char *result; + int resultlen; + char eui64_a[24]; + char *yp_domain; +#endif + if ((fp = fopen(_PATH_EUI64, "r")) == NULL) + return (1); + + while (fgets(buf,BUFSIZ,fp)) { + if (buf[0] == '#') + continue; +#ifdef YP + if (buf[0] == '+') { + if (yp_get_default_domain(&yp_domain)) + continue; + eui64_ntoa(id, eui64_a, sizeof(eui64_a)); + if (yp_match(yp_domain, "eui64.byid", eui64_a, + strlen(eui64_a), &result, &resultlen)) { + continue; + } + strncpy(buf, result, resultlen); + buf[resultlen] = '\0'; + free(result); + } +#endif + if (eui64_line(buf, &local_eui64, local_host, + sizeof(local_host)) == 0) { + if (bcmp(&local_eui64.octet[0], + &id->octet[0], EUI64_LEN) == 0) { + /* We have a match */ + strcpy(hostname, local_host); + fclose(fp); + return(0); + } + } + } + fclose(fp); + return (1); +} + +/* + * Map a hostname to an EUI-64 using /etc/eui64 or NIS/YP. + */ +int +eui64_hostton(const char *hostname, struct eui64 *id) +{ + FILE *fp; + char buf[BUFSIZ + 2]; + struct eui64 local_eui64; + char local_host[MAXHOSTNAMELEN]; +#ifdef YP + char *result; + int resultlen; + char *yp_domain; +#endif + if ((fp = fopen(_PATH_EUI64, "r")) == NULL) + return (1); + + while (fgets(buf,BUFSIZ,fp)) { + if (buf[0] == '#') + continue; +#ifdef YP + if (buf[0] == '+') { + if (yp_get_default_domain(&yp_domain)) + continue; + if (yp_match(yp_domain, "eui64.byname", hostname, + strlen(hostname), &result, &resultlen)) { + continue; + } + strncpy(buf, result, resultlen); + buf[resultlen] = '\0'; + free(result); + } +#endif + if (eui64_line(buf, &local_eui64, local_host, + sizeof(local_host)) == 0) { + if (strcmp(hostname, local_host) == 0) { + /* We have a match */ + bcopy(&local_eui64, id, sizeof(struct eui64)); + fclose(fp); + return(0); + } + } + } + fclose(fp); + return (1); +} diff --git a/share/man/man5/eui64.5 b/share/man/man5/eui64.5 new file mode 100644 index 0000000000..ceb3d248fb --- /dev/null +++ b/share/man/man5/eui64.5 @@ -0,0 +1,111 @@ +.\" Copyright (c) 1995 +.\" Bill Paul . All rights reserved. +.\" +.\" Redistribution and use in source and binary forms, with or without +.\" modification, are permitted provided that the following conditions +.\" are met: +.\" 1. Redistributions of source code must retain the above copyright +.\" notice, this list of conditions and the following disclaimer. +.\" 2. Redistributions in binary form must reproduce the above copyright +.\" notice, this list of conditions and the following disclaimer in the +.\" documentation and/or other materials provided with the distribution. +.\" 3. All advertising materials mentioning features or use of this software +.\" must display the following acknowledgement: +.\" This product includes software developed by Bill Paul. +.\" 4. Neither the name of the author nor the names of any co-contributors +.\" may be used to endorse or promote products derived from this software +.\" without specific prior written permission. +.\" +.\" THIS SOFTWARE IS PROVIDED BY Bill Paul AND CONTRIBUTORS ``AS IS'' AND +.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE +.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE +.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE +.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL +.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS +.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) +.\" HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT +.\" LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY +.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF +.\" SUCH DAMAGE. +.\" +.\" $FreeBSD: src/share/man/man5/eui64.5,v 1.2 2004/07/07 20:32:33 ru Exp $ +.\" $DragonFly: src/share/man/man5/eui64.5,v 1.1 2004/09/23 06:33:04 simokawa Exp $ +.\" +.Dd May 11, 2004 +.Dt EUI64 5 +.Os +.Sh NAME +.Nm eui64 +.Nd IEEE EUI-64 address database +.Sh DESCRIPTION +The +.Nm +database contains information regarding known IEEE EUI-64s of hosts. +The data is stored in a file called +.Pa /etc/eui64 +in the following format: +.Bd -ragged -offset indent +.Em EUI-64 host-name +.Ed +.Pp +Items are separated by any number of blanks and/or +tab characters. +A +.Ql # +at the start of a line indicates the +beginning of a comment that extends to the end of the line. +Valid lines may also contain comments. +A +.Ql + +at the start of a line will cause the +.Xr eui64 3 +library functions to use data stored in the +NIS +.Pa eui64.byname +and +.Pa eui64.byid +maps in addition to the data in the +.Pa /etc/eui64 +file. +.Pp +An EUI-64 is expressed in +.Tn ASCII +form as +.Qq x-x-x-x-x-x-x-x +where +.Ar x +is a hexadecimal value between 0x00 and 0xFF. +The address values +should be in network order. +Hostnames specified in the +.Pa /etc/eui64 +database should correspond to entries in the +.Xr hosts 5 +file. +.\" .Pp +.\" The +.\" .Fn eui64_line +.\" function in the standard C library can be used to break individual +.\" lines in the +.\" .Pa /etc/eui64 +.\" database into their individual components: a binary EUI-64 is +.\" stored as an +.\" .Pa eui64_addr +.\" structure, and a hostname stored as a character string. +.Sh FILES +.Bl -tag -width ".Pa /etc/eui64" -compact +.It Pa /etc/eui64 +The +.Nm +file resides in +.Pa /etc . +.El +.Sh SEE ALSO +.Xr eui64 3 , +.Xr yp 8 +.Sh HISTORY +The +.Nm +format is based on the +.Xr ethers 5 +format. diff --git a/sys/sys/eui64.h b/sys/sys/eui64.h new file mode 100644 index 0000000000..138f526de8 --- /dev/null +++ b/sys/sys/eui64.h @@ -0,0 +1,58 @@ +/* + * Copyright 2004 The Aerospace Corporation. All rights reserved. + * + * Redistribution and use in source and binary forms, with or without + * modification, are permitted provided that the following conditions + * are met: + * + * 1. Redistributions of source code must retain the above copyright + * notice, this list of conditions, and the following disclaimer. + * 2. Redistributions in binary form must reproduce the above copyright + * notice, this list of conditions, and the following disclaimer in the + * documentation and/or other materials provided with the distribution. + * 3. The name of The Aerospace Corporation may not be used to endorse or + * promote products derived from this software. + * + * THIS SOFTWARE IS PROVIDED BY THE AEROSPACE CORPORATION "AS IS" AND + * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE + * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE + * ARE DISCLAIMED. IN NO EVENT SHALL THE AEROSPACE CORPORATION BE LIABLE + * FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL + * DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS + * OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) + * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT + * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY + * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF + * SUCH DAMAGE. + * + * $FreeBSD: src/sys/sys/eui64.h,v 1.1 2004/05/26 22:58:06 brooks Exp $ + * $DragonFly: src/sys/sys/eui64.h,v 1.1 2004/09/23 06:33:04 simokawa Exp $ + */ +#ifndef _SYS_EUI64_H +#define _SYS_EUI64_H + +/* + * Size of the ASCII representation of an EUI-64. + */ +#define EUI64_SIZ 24 + +/* + * The number of bytes in an EUI-64. + */ +#define EUI64_LEN 8 + +/* + * Structure of an IEEE EUI-64. + */ +struct eui64 { + u_char octet[EUI64_LEN]; +}; + +#ifndef _KERNEL +int eui64_aton(const char *, struct eui64 *); +int eui64_ntoa(const struct eui64 *, char *, size_t); +int eui64_ntohost(char *, size_t, const struct eui64 *); +int eui64_hostton(const char *, struct eui64 *); +#endif /* !_KERNEL */ + +#endif /* !_SYS_EUI64_H */ -- 2.41.0