OSSP CVS Repository

ossp - Check-in [3725]
Not logged in
[Honeypot]  [Browse]  [Home]  [Login]  [Reports
[Search]  [Ticket]  [Timeline
  [Patchset]  [Tagging/Branching

Check-in Number: 3725
Date: 2004-Jan-10 18:01:22 (local)
2004-Jan-10 17:01:22 (UTC)
User:rse
Branch:
Comment: add MAC address framework part of UUID v1 generation and implement the MAC address resolving for BSD style platforms with getifaddrs(3)
Tickets:
Inspections:
Files:
ossp-pkg/uuid/Makefile.in      1.5 -> 1.6     1 inserted, 1 deleted
ossp-pkg/uuid/uuid.ac      1.1 -> 1.2     4 inserted, 3 deleted
ossp-pkg/uuid/uuid.c      1.15 -> 1.16     23 inserted, 6 deleted
ossp-pkg/uuid/uuid_mac.c      added-> 1.1
ossp-pkg/uuid/uuid_mac.h      added-> 1.1

ossp-pkg/uuid/Makefile.in 1.5 -> 1.6

--- 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


ossp-pkg/uuid/uuid.ac 1.1 -> 1.2

--- 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)


ossp-pkg/uuid/uuid.c 1.15 -> 1.16

--- 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 <string.h>
 #include <unistd.h>
 #include <ctype.h>
-#include <time.h>
-#include <sys/time.h>
 #include <unistd.h>
 #include <fcntl.h>
+#include <time.h>
+#include <sys/time.h>
+#include <sys/types.h>
 
 #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;
 }
 


ossp-pkg/uuid/uuid_mac.c -> 1.1

*** /dev/null    Wed May  1 11:45:38 2024
--- -    Wed May  1 11:46:40 2024
***************
*** 0 ****
--- 1,110 ----
+ /*
+ **  OSSP uuid - Universally Unique Identifier
+ **  Copyright (c) 2004 Ralf S. Engelschall <rse@engelschall.com>
+ **  Copyright (c) 2004 The OSSP Project <http://www.ossp.org/>
+ **
+ **  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 <stdlib.h>
+ #include <string.h>
+ #include <unistd.h>
+ #include <time.h>
+ #include <sys/time.h>
+ #include <fcntl.h>
+ #include <time.h>
+ #include <sys/time.h>
+ #include <sys/types.h>
+ 
+ #ifdef HAVE_IFADDRS_H
+ #include <ifaddrs.h>
+ #endif
+ #ifdef HAVE_NET_IF_DL_H
+ #include <net/if_dl.h>
+ #endif
+ 
+ #ifdef HAVE_SYS_IOCTL_H
+ #include <sys/ioctl.h>
+ #endif
+ #ifdef HAVE_SYS_SOCKET_H
+ #include <sys/socket.h>
+ #endif
+ #ifdef HAVE_SYS_SOCKIO_H
+ #include <sys/sockio.h>
+ #endif
+ #ifdef HAVE_NET_IF_H
+ #include <net/if.h>
+ #endif
+ #ifdef HAVE_NETINET_IN_H
+ #include <netinet/in.h>
+ #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;
+ }
+ 


ossp-pkg/uuid/uuid_mac.h -> 1.1

*** /dev/null    Wed May  1 11:45:38 2024
--- -    Wed May  1 11:46:40 2024
***************
*** 0 ****
--- 1,40 ----
+ /*
+ **  OSSP uuid - Universally Unique Identifier
+ **  Copyright (c) 2004 Ralf S. Engelschall <rse@engelschall.com>
+ **  Copyright (c) 2004 The OSSP Project <http://www.ossp.org/>
+ **
+ **  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 <string.h> /* size_t */
+ 
+ #define MAC_LEN 6
+ 
+ extern int mac_address(unsigned char *data_ptr, size_t data_len);
+ 
+ #endif /* __UUID_MAC_H__ */
+ 

CVSTrac 2.0.1