Index: ossp-pkg/uuid/uuid.ac RCS File: /v/ossp/cvs/ossp-pkg/uuid/Attic/uuid.ac,v rcsdiff -q -kk '-r1.2' '-r1.3' -u '/v/ossp/cvs/ossp-pkg/uuid/Attic/uuid.ac,v' 2>/dev/null --- uuid.ac 2004/01/10 17:01:22 1.2 +++ uuid.ac 2004/01/10 18:50:24 1.3 @@ -68,10 +68,9 @@ 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 net/if.h) - - dnl # check for MAC determination on BSD class platforms - AC_CHECK_HEADERS(ifaddrs.h net/if_dl.h) + AC_CHECK_HEADERS(string.h sys/types.h sys/socket.h netdb.h netinet/in.h dnl + ifaddrs.h net/if_dl.h net/if_arp.h net/if.h sys/ioctl.h dnl + sys/sockio.h arpa/inet.h) AC_CHECK_FUNCS(getifaddrs) dnl # check size of built-in types Index: ossp-pkg/uuid/uuid_mac.c RCS File: /v/ossp/cvs/ossp-pkg/uuid/Attic/uuid_mac.c,v rcsdiff -q -kk '-r1.1' '-r1.2' -u '/v/ossp/cvs/ossp-pkg/uuid/Attic/uuid_mac.c,v' 2>/dev/null --- uuid_mac.c 2004/01/10 17:01:22 1.1 +++ uuid_mac.c 2004/01/10 18:50:24 1.2 @@ -40,13 +40,6 @@ #include #include -#ifdef HAVE_IFADDRS_H -#include -#endif -#ifdef HAVE_NET_IF_DL_H -#include -#endif - #ifdef HAVE_SYS_IOCTL_H #include #endif @@ -59,9 +52,21 @@ #ifdef HAVE_NET_IF_H #include #endif +#ifdef HAVE_NET_IF_DL_H +#include +#endif +#ifdef HAVE_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 #ifndef FALSE #define FALSE 0 @@ -79,7 +84,7 @@ return FALSE; #if defined(HAVE_IFADDRS_H) && defined(HAVE_NET_IF_DL_H) && defined(HAVE_GETIFADDRS) - /* use getifaddrs(3) on BSD class platforms */ + /* use getifaddrs(3) on BSD class platforms (xxxBSD, MacOS X, etc) */ { struct ifaddrs *ifap; struct ifaddrs *ifap_head; @@ -87,7 +92,7 @@ unsigned char *ucp; int i; - if (getifaddrs(&ifap_head) != 0) + 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) { @@ -95,7 +100,7 @@ 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); + data_ptr[i] = (unsigned char)(*ucp & 0xff); freeifaddrs(ifap_head); return TRUE; } @@ -105,6 +110,57 @@ } #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; + + 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; + + if (gethostname(hostname, sizeof(hostname)) < 0) + return FALSE; + if ((he = gethostbyname(hostname)) < 0) + return FALSE; + if ((s = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) < 0) + return FALSE; + memset(&ar, '\0', sizeof(ar)); + sa = (struct sockaddr_in *)&(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; + } + for (i = 0; i < MAC_LEN; i++) + data_ptr[i] = (unsigned char)(ar.arp_ha.sa_data[i] & 0xff); + close(s); + return TRUE; + } +#endif + return FALSE; }