From 84ea6e70b77090c8a35702b265039d58c2efd6ad Mon Sep 17 00:00:00 2001 From: Theodore Ts'o Date: Fri, 19 Mar 2004 19:29:17 -0500 Subject: [PATCH] Fix Darwin/Mac OS X support to fetch the ethernet address in the uuid library. --- configure | 65 ++++++++++++++++++++++++++++++++++----------- configure.in | 18 ++++++++++++- lib/uuid/gen_uuid.c | 17 ++++++++++-- 3 files changed, 82 insertions(+), 18 deletions(-) diff --git a/configure b/configure index 5315b2c5..9ef11801 100644 --- a/configure +++ b/configure @@ -5272,7 +5272,7 @@ test -n "$BUILD_CC" && break done fi -for ac_hdr in stdlib.h unistd.h stdarg.h errno.h malloc.h mntent.h paths.h dirent.h getopt.h setjmp.h signal.h termios.h linux/fd.h linux/major.h sys/disk.h sys/disklabel.h sys/ioctl.h sys/mkdev.h sys/mount.h sys/sockio.h sys/socket.h sys/sysmacros.h sys/time.h sys/stat.h sys/types.h sys/wait.h sys/resource.h net/if.h netinet/in.h +for ac_hdr in stdlib.h unistd.h stdarg.h errno.h malloc.h mntent.h paths.h dirent.h getopt.h setjmp.h signal.h termios.h linux/fd.h linux/major.h sys/disk.h sys/disklabel.h sys/ioctl.h sys/mkdev.h sys/mount.h sys/sockio.h sys/socket.h sys/sysmacros.h sys/time.h sys/stat.h sys/types.h sys/wait.h sys/resource.h net/if.h net/if_dl.h netinet/in.h do ac_safe=`echo "$ac_hdr" | sed 'y%./+-%__p_%'` echo $ac_n "checking for $ac_hdr""... $ac_c" 1>&6 @@ -5945,16 +5945,51 @@ fi EOF fi +fi +echo $ac_n "checking whether struct sockaddr contains sa_len""... $ac_c" 1>&6 +echo "configure:5951: checking whether struct sockaddr contains sa_len" >&5 +if eval "test \"`echo '$''{'e2fsprogs_cv_sockaddr_sa_len'+set}'`\" = set"; then + echo $ac_n "(cached) $ac_c" 1>&6 +else + cat > conftest.$ac_ext < +#include + +int main() { +struct sockaddr sa; +sa.sa_len; +; return 0; } +EOF +if { (eval echo configure:5966: \"$ac_compile\") 1>&5; (eval $ac_compile) 2>&5; }; then + rm -rf conftest* + e2fsprogs_cv_sockaddr_sa_len=yes +else + echo "configure: failed program was:" >&5 + cat conftest.$ac_ext >&5 + rm -rf conftest* + e2fsprogs_cv_sockaddr_sa_len=no +fi +rm -f conftest* +fi + +echo "$ac_t""$e2fsprogs_cv_sockaddr_sa_len" 1>&6 +if test $e2fsprogs_cv_sockaddr_sa_len = yes; then + cat >> confdefs.h <&6 -echo "configure:5953: checking for $ac_func" >&5 +echo "configure:5988: checking for $ac_func" >&5 if eval "test \"`echo '$''{'ac_cv_func_$ac_func'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:6016: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_func_$ac_func=yes" else @@ -6003,7 +6038,7 @@ done SOCKET_LIB='' echo $ac_n "checking for socket in -lsocket""... $ac_c" 1>&6 -echo "configure:6007: checking for socket in -lsocket" >&5 +echo "configure:6042: checking for socket in -lsocket" >&5 ac_lib_var=`echo socket'_'socket | sed 'y%./+-%__p_%'` if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -6011,7 +6046,7 @@ else ac_save_LIBS="$LIBS" LIBS="-lsocket $LIBS" cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:6061: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=yes" else @@ -6045,7 +6080,7 @@ fi DLOPEN_LIB='' echo $ac_n "checking for dlopen in -ldl""... $ac_c" 1>&6 -echo "configure:6049: checking for dlopen in -ldl" >&5 +echo "configure:6084: checking for dlopen in -ldl" >&5 ac_lib_var=`echo dl'_'dlopen | sed 'y%./+-%__p_%'` if eval "test \"`echo '$''{'ac_cv_lib_$ac_lib_var'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 @@ -6053,7 +6088,7 @@ else ac_save_LIBS="$LIBS" LIBS="-ldl $LIBS" cat > conftest.$ac_ext <&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:6103: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* eval "ac_cv_lib_$ac_lib_var=yes" else @@ -6090,12 +6125,12 @@ fi echo $ac_n "checking for optreset""... $ac_c" 1>&6 -echo "configure:6094: checking for optreset" >&5 +echo "configure:6129: checking for optreset" >&5 if eval "test \"`echo '$''{'ac_cv_have_optreset'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else cat > conftest.$ac_ext < EOF @@ -6186,20 +6221,20 @@ fi echo $ac_n "checking whether linker accepts -static""... $ac_c" 1>&6 -echo "configure:6190: checking whether linker accepts -static" >&5 +echo "configure:6225: checking whether linker accepts -static" >&5 if eval "test \"`echo '$''{'ac_cv_e2fsprogs_use_static'+set}'`\" = set"; then echo $ac_n "(cached) $ac_c" 1>&6 else SAVE_LDFLAGS=$LDFLAGS; LDFLAGS="$LDFLAGS -static" cat > conftest.$ac_ext < int main() { fflush(stdout); ; return 0; } EOF -if { (eval echo configure:6203: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then +if { (eval echo configure:6238: \"$ac_link\") 1>&5; (eval $ac_link) 2>&5; } && test -s conftest${ac_exeext}; then rm -rf conftest* ac_cv_e2fsprogs_use_static=yes else diff --git a/configure.in b/configure.in index 6b2d2e98..4d05a1b7 100644 --- a/configure.in +++ b/configure.in @@ -586,7 +586,7 @@ if test $cross_compiling = no; then else AC_CHECK_PROGS(BUILD_CC, gcc cc) fi -AC_CHECK_HEADERS(stdlib.h unistd.h stdarg.h errno.h malloc.h mntent.h paths.h dirent.h getopt.h setjmp.h signal.h termios.h linux/fd.h linux/major.h sys/disk.h sys/disklabel.h sys/ioctl.h sys/mkdev.h sys/mount.h sys/sockio.h sys/socket.h sys/sysmacros.h sys/time.h sys/stat.h sys/types.h sys/wait.h sys/resource.h net/if.h netinet/in.h) +AC_CHECK_HEADERS(stdlib.h unistd.h stdarg.h errno.h malloc.h mntent.h paths.h dirent.h getopt.h setjmp.h signal.h termios.h linux/fd.h linux/major.h sys/disk.h sys/disklabel.h sys/ioctl.h sys/mkdev.h sys/mount.h sys/sockio.h sys/socket.h sys/sysmacros.h sys/time.h sys/stat.h sys/types.h sys/wait.h sys/resource.h net/if.h net/if_dl.h netinet/in.h) AC_FUNC_VPRINTF dnl Check to see if dirent has member d_reclen. On cygwin those d_reclen dnl is not decleared. @@ -701,6 +701,22 @@ if test "$e2fsprogs_cv_struct_st_flags" = yes; then AC_DEFINE(HAVE_STAT_FLAGS) fi fi +dnl +dnl Check for the presence of SA_LEN +dnl +AC_MSG_CHECKING(whether struct sockaddr contains sa_len) +AC_CACHE_VAL(e2fsprogs_cv_sockaddr_sa_len, +[AC_TRY_COMPILE([#include +#include +], +[struct sockaddr sa; +sa.sa_len;], +e2fsprogs_cv_sockaddr_sa_len=yes,e2fsprogs_cv_sockaddr_sa_len=no)]) +AC_MSG_RESULT([$]e2fsprogs_cv_sockaddr_sa_len) +if test $e2fsprogs_cv_sockaddr_sa_len = yes; then + AC_DEFINE_UNQUOTED(HAVE_SA_LEN,1,[Define if struct sockaddr contains sa_len]) +fi +dnl AC_CHECK_FUNCS(chflags getrusage llseek lseek64 open64 getmntinfo strtoull strcasecmp srandom fchown mallinfo fdatasync strnlen strptime sysconf pathconf posix_memalign memalign valloc) dnl dnl Check to see if -lsocket is required (solaris) to make something diff --git a/lib/uuid/gen_uuid.c b/lib/uuid/gen_uuid.c index c7e62a60..931d7c1b 100644 --- a/lib/uuid/gen_uuid.c +++ b/lib/uuid/gen_uuid.c @@ -43,6 +43,9 @@ #ifdef HAVE_NETINET_IN_H #include #endif +#ifdef HAVE_NET_IF_DL_H +#include +#endif #include "uuidP.h" @@ -117,7 +120,10 @@ static int get_node_id(unsigned char *node_id) char buf[1024]; int n, i; unsigned char *a; - +#if defined(HAVE_NET_IF_DL_H) && defined(AF_LINK) + struct sockaddr_dl *sdlp; +#endif + /* * BSD 4.4 defines the size of an ifreq to be * max(sizeof(ifreq), sizeof(ifreq.ifr_name)+ifreq.ifr_addr.sa_len @@ -146,7 +152,7 @@ static int get_node_id(unsigned char *node_id) return -1; } n = ifc.ifc_len; - for (i = 0; i < n; i+= ifreq_size(*ifr) ) { + for (i = 0; i < n; i+= ifreq_size(*ifrp) ) { ifrp = (struct ifreq *)((char *) ifc.ifc_buf+i); strncpy(ifr.ifr_name, ifrp->ifr_name, IFNAMSIZ); #ifdef SIOCGIFHWADDR @@ -158,6 +164,12 @@ static int get_node_id(unsigned char *node_id) if (ioctl(sd, SIOCGENADDR, &ifr) < 0) continue; a = (unsigned char *) ifr.ifr_enaddr; +#else +#if defined(HAVE_NET_IF_DL_H) && defined(AF_LINK) + sdlp = (struct sockaddr_dl *) &ifrp->ifr_addr; + if ((sdlp->sdl_family != AF_LINK) || (sdlp->sdl_alen < 6)) + continue; + a = (unsigned char *) &sdlp->sdl_data[sdlp->sdl_nlen]; #else /* * XXX we don't have a way of getting the hardware @@ -165,6 +177,7 @@ static int get_node_id(unsigned char *node_id) */ close(sd); return 0; +#endif /* HAVE_NET_IF_DL_H && AF_LINK */ #endif /* SIOCGENADDR */ #endif /* SIOCGIFHWADDR */ if (!a[0] && !a[1] && !a[2] && !a[3] && !a[4] && !a[5])