Index: ossp-pkg/uuid/Makefile.in RCS File: /v/ossp/cvs/ossp-pkg/uuid/Attic/Makefile.in,v rcsdiff -q -kk '-r1.5' '-r1.6' -u '/v/ossp/cvs/ossp-pkg/uuid/Attic/Makefile.in,v' 2>/dev/null --- Makefile.in 2004/01/10 12:16:03 1.5 +++ Makefile.in 2004/01/10 17:01:22 1.6 @@ -50,7 +50,7 @@ POD2MAN = pod2man LIB_NAME = libuuid.la -LIB_OBJS = uuid.lo uuid_md5.lo uuid_prng.lo uuid_ui64.lo +LIB_OBJS = uuid.lo uuid_md5.lo uuid_prng.lo uuid_mac.lo uuid_ui64.lo PRG_NAME = uuid PRG_OBJS = uuid_cli.o Index: ossp-pkg/uuid/uuid.ac RCS File: /v/ossp/cvs/ossp-pkg/uuid/Attic/uuid.ac,v rcsdiff -q -kk '-r1.1' '-r1.2' -u '/v/ossp/cvs/ossp-pkg/uuid/Attic/uuid.ac,v' 2>/dev/null --- uuid.ac 2004/01/06 20:14:28 1.1 +++ uuid.ac 2004/01/10 17:01:22 1.2 @@ -68,10 +68,11 @@ AC_CHECK_LIB(inet6, getaddrinfo) dnl # check for system headers - AC_CHECK_HEADERS(string.h sys/types.h sys/socket.h netdb.h netinet/in.h) + AC_CHECK_HEADERS(string.h sys/types.h sys/socket.h netdb.h netinet/in.h net/if.h) - dnl # check for system functions - AC_CHECK_FUNCS(getaddrinfo) + dnl # check for MAC determination on BSD class platforms + AC_CHECK_HEADERS(ifaddrs.h net/if_dl.h) + AC_CHECK_FUNCS(getifaddrs) dnl # check size of built-in types AC_CHECK_SIZEOF(char, 1) Index: ossp-pkg/uuid/uuid.c RCS File: /v/ossp/cvs/ossp-pkg/uuid/Attic/uuid.c,v rcsdiff -q -kk '-r1.15' '-r1.16' -u '/v/ossp/cvs/ossp-pkg/uuid/Attic/uuid.c,v' 2>/dev/null --- uuid.c 2004/01/10 15:19:21 1.15 +++ uuid.c 2004/01/10 17:01:22 1.16 @@ -33,15 +33,17 @@ #include #include #include -#include -#include #include #include +#include +#include +#include #include "config.h" #include "uuid.h" #include "uuid_md5.h" #include "uuid_prng.h" +#include "uuid_mac.h" #include "uuid_ui64.h" /* determine types of 8-bit size */ @@ -119,9 +121,10 @@ /* abstract data type (ADT) of API */ struct uuid_st { - uuid_obj_t obj; /* inlined UUID object */ - prng_t *prng; /* RPNG sub-object */ - md5_t *md5; /* MD5 sub-object */ + uuid_obj_t obj; /* inlined UUID object */ + prng_t *prng; /* RPNG sub-object */ + md5_t *md5; /* MD5 sub-object */ + uuid_uint8_t mac[6]; /* pre-determined MAC address */ }; /* create UUID object */ @@ -144,6 +147,12 @@ if (md5_create(&(*uuid)->md5) != MD5_RC_OK) return UUID_RC_INT; + /* resolve MAC address for insertion into node field of UUIDs */ + if (!mac_address((unsigned char *)((*uuid)->mac), sizeof((*uuid)->mac))) { + memset((*uuid)->mac, '\0', sizeof((*uuid)->mac)); + (*uuid)->mac[0] = 0x80; + } + return UUID_RC_OK; } @@ -507,7 +516,15 @@ /* INTERNAL: generate UUID version 1, node part */ static uuid_rc_t uuid_generate_v1_node(uuid_t *uuid, unsigned int mode, va_list ap) { - /* FIXME */ + if ((mode & UUID_MCASTRND) || (uuid->mac[0] & 0x80)) { + /* use random multi-cast MAC address */ + prng_data(uuid->prng, (void *)&(uuid->obj.node), sizeof(uuid->obj.node)); + uuid->obj.node[0] |= 0x80; + } + else { + /* use real regular MAC address */ + memcpy(uuid->obj.node, uuid->mac, sizeof(uuid->mac)); + } return UUID_RC_OK; } Index: ossp-pkg/uuid/uuid_mac.c RCS File: /v/ossp/cvs/ossp-pkg/uuid/Attic/uuid_mac.c,v co -q -kk -p'1.1' '/v/ossp/cvs/ossp-pkg/uuid/Attic/uuid_mac.c,v' | diff -u /dev/null - -L'ossp-pkg/uuid/uuid_mac.c' 2>/dev/null --- ossp-pkg/uuid/uuid_mac.c +++ - 2024-05-21 23:22:51.556652063 +0200 @@ -0,0 +1,110 @@ +/* +** OSSP uuid - Universally Unique Identifier +** Copyright (c) 2004 Ralf S. Engelschall +** Copyright (c) 2004 The OSSP Project +** +** This file is part of OSSP uuid, a library for the generation +** of UUIDs which can found at http://www.ossp.org/pkg/lib/uuid/ +** +** Permission to use, copy, modify, and distribute this software for +** any purpose with or without fee is hereby granted, provided that +** the above copyright notice and this permission notice appear in all +** copies. +** +** THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 AUTHORS AND COPYRIGHT HOLDERS AND THEIR +** 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. +** +** uuid_mac.c: Media Access Control (MAC) resolver implementation +*/ + +#include "config.h" +#include "uuid_mac.h" + +#include +#include +#include +#include +#include +#include +#include +#include +#include + +#ifdef HAVE_IFADDRS_H +#include +#endif +#ifdef HAVE_NET_IF_DL_H +#include +#endif + +#ifdef HAVE_SYS_IOCTL_H +#include +#endif +#ifdef HAVE_SYS_SOCKET_H +#include +#endif +#ifdef HAVE_SYS_SOCKIO_H +#include +#endif +#ifdef HAVE_NET_IF_H +#include +#endif +#ifdef HAVE_NETINET_IN_H +#include +#endif + +#ifndef FALSE +#define FALSE 0 +#endif +#ifndef TRUE +#define TRUE !FALSE +#endif + +/* return the Media Access Control (MAC) address of + the FIRST network interface card (NIC) */ +int mac_address(unsigned char *data_ptr, size_t data_len) +{ + /* sanity check arguments */ + if (data_ptr == NULL || data_len < MAC_LEN) + return FALSE; + +#if defined(HAVE_IFADDRS_H) && defined(HAVE_NET_IF_DL_H) && defined(HAVE_GETIFADDRS) + /* use getifaddrs(3) on BSD class platforms */ + { + struct ifaddrs *ifap; + struct ifaddrs *ifap_head; + const struct sockaddr_dl *sdl; + unsigned char *ucp; + int i; + + if (getifaddrs(&ifap_head) != 0) + return FALSE; + for (ifap = ifap_head; ifap != NULL; ifap = ifap->ifa_next) { + if (ifap->ifa_addr != NULL && ifap->ifa_addr->sa_family == AF_LINK) { + sdl = (const struct sockaddr_dl *)ifap->ifa_addr; + ucp = (unsigned char *)(sdl->sdl_data + sdl->sdl_nlen); + if (ucp != NULL && sdl->sdl_alen > 0) { + for (i = 0; i < MAC_LEN && i < sdl->sdl_alen; i++, ucp++) + data_ptr[i] = (*ucp & 0xff); + freeifaddrs(ifap_head); + return TRUE; + } + } + } + freeifaddrs(ifap_head); + } +#endif + + return FALSE; +} + Index: ossp-pkg/uuid/uuid_mac.h RCS File: /v/ossp/cvs/ossp-pkg/uuid/Attic/uuid_mac.h,v co -q -kk -p'1.1' '/v/ossp/cvs/ossp-pkg/uuid/Attic/uuid_mac.h,v' | diff -u /dev/null - -L'ossp-pkg/uuid/uuid_mac.h' 2>/dev/null --- ossp-pkg/uuid/uuid_mac.h +++ - 2024-05-21 23:22:51.559338483 +0200 @@ -0,0 +1,40 @@ +/* +** OSSP uuid - Universally Unique Identifier +** Copyright (c) 2004 Ralf S. Engelschall +** Copyright (c) 2004 The OSSP Project +** +** This file is part of OSSP uuid, a library for the generation +** of UUIDs which can found at http://www.ossp.org/pkg/lib/uuid/ +** +** Permission to use, copy, modify, and distribute this software for +** any purpose with or without fee is hereby granted, provided that +** the above copyright notice and this permission notice appear in all +** copies. +** +** THIS SOFTWARE IS PROVIDED ``AS IS'' AND ANY EXPRESSED 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 AUTHORS AND COPYRIGHT HOLDERS AND THEIR +** 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. +** +** uuid_mac.h: Media Access Control (MAC) resolver API definition +*/ + +#ifndef __UUID_MAC_H__ +#define __UUID_MAC_H__ + +#include /* size_t */ + +#define MAC_LEN 6 + +extern int mac_address(unsigned char *data_ptr, size_t data_len); + +#endif /* __UUID_MAC_H__ */ +