head 1.14; access; symbols UUID_1_6_2:1.13 UUID_1_6_1:1.13 UUID_1_6_0:1.12 UUID_1_5_1:1.10 UUID_1_5_0:1.10 UUID_1_4_2:1.9 UUID_1_4_1:1.9 UUID_1_4_0:1.9 UUID_1_3_2:1.8 UUID_1_3_1:1.8 UUID_1_3_0:1.8 UUID_1_2_1:1.8 UUID_1_2_0:1.6 UUID_1_1_2:1.6 UUID_1_1_1:1.4 UUID_1_1_0:1.4 UUID_1_0_4:1.4 UUID_1_0_3:1.4 UUID_1_0_2:1.4 UUID_1_0_1:1.4 UUID_1_0_0:1.4 UUID_0_9_7:1.4 UUID_0_9_6:1.4 UUID_0_9_5:1.4 UUID_0_9_4:1.4 UUID_0_9_3:1.4 UUID_0_9_2:1.4 UUID_0_9_1:1.4 UUID_0_9_0:1.4; locks; strict; comment @ * @; 1.14 date 2008.07.05.12.58.16; author rse; state dead; branches; next 1.13; commitid XLXN7vUmABwPcC9t; 1.13 date 2008.01.10.14.18.47; author rse; state Exp; branches; next 1.12; commitid LqMgFGBgTR7clSMs; 1.12 date 2007.01.01.18.14.55; author rse; state Exp; branches; next 1.11; commitid jOXiIO8S8v7xFP0s; 1.11 date 2006.08.02.13.11.09; author rse; state Exp; branches; next 1.10; commitid fwUmuuaIDS3gSgHr; 1.10 date 2006.07.28.19.04.32; author rse; state Exp; branches; next 1.9; commitid 6qZlcn3KsEQtZEGr; 1.9 date 2006.01.13.06.44.31; author rse; state Exp; branches; next 1.8; commitid hYfQc9JIMh4bcphr; 1.8 date 2005.06.15.18.34.04; author rse; state Exp; branches; next 1.7; 1.7 date 2005.03.29.19.01.41; author rse; state Exp; branches; next 1.6; 1.6 date 2005.01.13.08.50.11; author rse; state Exp; branches; next 1.5; 1.5 date 2004.12.31.19.20.34; author rse; state Exp; branches; next 1.4; 1.4 date 2004.01.11.08.27.18; author rse; state Exp; branches; next 1.3; 1.3 date 2004.01.10.19.17.39; author rse; state Exp; branches; next 1.2; 1.2 date 2004.01.10.18.50.24; author rse; state Exp; branches; next 1.1; 1.1 date 2004.01.10.17.01.22; author rse; state Exp; branches; next ; desc @@ 1.14 log @remove OSSP uuid from CVS -- it is now versioned controlled in a Monotone repository @ text @/* ** OSSP uuid - Universally Unique Identifier ** Copyright (c) 2004-2008 Ralf S. Engelschall ** Copyright (c) 2004-2008 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 */ /* own headers (part (1/2) */ #include "uuid_ac.h" /* system headers */ #include #include #include #include #include #include #ifdef HAVE_SYS_TIME_H #include #endif #ifdef HAVE_SYS_TYPES_H #include #endif #ifdef HAVE_SYS_PARAM_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_NETDB_H #include #endif #ifdef HAVE_NET_IF_H #include #endif #ifdef HAVE_NET_IF_DL_H #include #endif #ifdef HAVE_NET_IF_ARP_H #include #endif #ifdef HAVE_NETINET_IN_H #include #endif #ifdef HAVE_ARPA_INET_H #include #endif #ifdef HAVE_IFADDRS_H #include #endif /* own headers (part (1/2) */ #include "uuid_mac.h" #ifndef FALSE #define FALSE 0 #endif #ifndef TRUE #define TRUE (/*lint -save -e506*/ !FALSE /*lint -restore*/) #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 (xxxBSD, MacOS X, etc) */ { 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 *)(void *)ifap->ifa_addr; ucp = (unsigned char *)(sdl->sdl_data + sdl->sdl_nlen); if (sdl->sdl_alen > 0) { for (i = 0; i < MAC_LEN && i < sdl->sdl_alen; i++, ucp++) data_ptr[i] = (unsigned char)(*ucp & 0xff); freeifaddrs(ifap_head); return TRUE; } } } freeifaddrs(ifap_head); } #endif #if defined(HAVE_NET_IF_H) && defined(SIOCGIFHWADDR) /* use SIOCGIFHWADDR ioctl(2) on Linux class platforms */ { struct ifreq ifr; struct sockaddr *sa; int s; int i; if ((s = socket(PF_INET, SOCK_DGRAM, 0)) < 0) return FALSE; sprintf(ifr.ifr_name, "eth0"); if (ioctl(s, SIOCGIFHWADDR, &ifr) < 0) { close(s); return FALSE; } sa = (struct sockaddr *)&ifr.ifr_addr; for (i = 0; i < MAC_LEN; i++) data_ptr[i] = (unsigned char)(sa->sa_data[i] & 0xff); close(s); return TRUE; } #endif #if defined(SIOCGARP) /* use SIOCGARP ioctl(2) on SVR4 class platforms (Solaris, etc) */ { char hostname[MAXHOSTNAMELEN]; struct hostent *he; struct arpreq ar; struct sockaddr_in *sa; int s; int i; if (gethostname(hostname, sizeof(hostname)) < 0) return FALSE; if ((he = gethostbyname(hostname)) == NULL) return FALSE; if ((s = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) return FALSE; memset(&ar, 0, sizeof(ar)); sa = (struct sockaddr_in *)((void *)&(ar.arp_pa)); sa->sin_family = AF_INET; memcpy(&(sa->sin_addr), *(he->h_addr_list), sizeof(struct in_addr)); if (ioctl(s, SIOCGARP, &ar) < 0) { close(s); return FALSE; } close(s); if (!(ar.arp_flags & ATF_COM)) return FALSE; for (i = 0; i < MAC_LEN; i++) data_ptr[i] = (unsigned char)(ar.arp_ha.sa_data[i] & 0xff); return TRUE; } #endif return FALSE; } @ 1.13 log @adjust copyright messages for 2008 and bump version in advance @ text @@ 1.12 log @Adjust copyright messages for new year 2007. @ text @d3 2 a4 2 ** Copyright (c) 2004-2007 Ralf S. Engelschall ** Copyright (c) 2004-2007 The OSSP Project @ 1.11 log @Optional DMALLOC based memory debugging support. @ text @d3 2 a4 2 ** Copyright (c) 2004-2006 Ralf S. Engelschall ** Copyright (c) 2004-2006 The OSSP Project @ 1.10 log @Even more pendantic code cleanups according to complains by SPLINT @ text @d30 2 a31 2 #include "config.h" #include "uuid_mac.h" d33 1 a39 1 d80 3 @ 1.9 log @Adjust copyright messages for new year 2006. @ text @d161 1 a161 1 memset(&ar, '\0', sizeof(ar)); @ 1.8 log @Fix MAC address determination under Solaris by using the result of ioctl(...,SIOCGARP,...) only if arp_flags had ATF_COM set. @ text @d3 2 a4 2 ** Copyright (c) 2004-2005 Ralf S. Engelschall ** Copyright (c) 2004-2005 The OSSP Project @ 1.7 log @Cleanup the source code even more by following a large set of FlexeLint's suggestions. @ text @d169 3 a173 1 close(s); @ 1.6 log @use a double-cast to get rid of GCC warnings on 64-bit platforms about 'cast increases alignment restrictions' because although true it cannot be done differently here because of the way the old Unix socket API is designed @ text @d84 1 a84 1 #define TRUE !FALSE d110 1 a110 1 if (ucp != NULL && sdl->sdl_alen > 0) { @ 1.5 log @Adjust copyright messages for new year 2005. @ text @d108 1 a108 1 sdl = (const struct sockaddr_dl *)ifap->ifa_addr; @ 1.4 log @cleanup and fix header checks @ text @d3 2 a4 2 ** Copyright (c) 2004 Ralf S. Engelschall ** Copyright (c) 2004 The OSSP Project @ 1.3 log @apply fixed after run-time testing under Linux and Solaris @ text @a36 3 #include #include #include d39 2 d42 2 d45 4 a48 1 @ 1.2 log @add blind Linux and Solaris MAC address support @ text @d33 1 d37 1 d54 3 d63 1 a63 1 #ifdef HAVE_IF_ARP_H d124 1 d148 2 d153 1 a153 1 if ((he = gethostbyname(hostname)) < 0) d158 1 a158 1 sa = (struct sockaddr_in *)&(ar.arp_pa); @ 1.1 log @add MAC address framework part of UUID v1 generation and implement the MAC address resolving for BSD style platforms with getifaddrs(3) @ text @a42 7 #ifdef HAVE_IFADDRS_H #include #endif #ifdef HAVE_NET_IF_DL_H #include #endif d55 6 d64 6 d87 1 a87 1 /* use getifaddrs(3) on BSD class platforms */ d95 1 a95 1 if (getifaddrs(&ifap_head) != 0) d103 1 a103 1 data_ptr[i] = (*ucp & 0xff); d110 51 @