From: Sam Hartman Date: Tue, 18 Jul 1995 22:00:47 +0000 (+0000) Subject: Bsd 4.4 has a field sa_len in struct sockaddr which is the X-Git-Tag: krb5-1.0-beta6~1508 X-Git-Url: http://git.tremily.us/?a=commitdiff_plain;h=d4091516be57fb8f76f0880c808a8281f06f1869;p=krb5.git Bsd 4.4 has a field sa_len in struct sockaddr which is the length of the struct. Often, sizeof(struct sockaddr) is not equal to sockaddr.sa_len. Unfortunately, this effects the side of structures containing sockaddrs, like struct ifreq. The size of an ifreq is, under BSD 4.4, max(sizeof(struct ifreq), sizeof(ifreq.ifr_name)+ifreq.ifr_caddr.sa_len). To get krb5_xcrypto_os_localaddr to work under NetBSD and other 4.4-based systems, the following changes were made: * aclocal.m4: Ad KRB5_SOCKADDR_SA_LEN to determine if there appears to be a sa_len element of struct sockaddr. * lib/crypto/os/configure.in: use this test * lib/crypto/os/localaddr.c: Deal with size changes if appropriate. git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@6310 dc483132-0cff-0310-8789-dd5450dbe970 --- diff --git a/src/ChangeLog b/src/ChangeLog index 4a712f1d7..722df1ab9 100644 --- a/src/ChangeLog +++ b/src/ChangeLog @@ -1,3 +1,7 @@ +Sun Jul 16 05:02:41 1995 Sam Hartman + + * aclocal.m4 : Defined KRB5_SOCKADDR_SA_LEN, a test to determine + if sockaddr has the sa_len field. Wed Jul 12 11:47:43 EDT 1995 Paul Park (pjpark@mit.edu) * aclocal.m4 - Add LDFLAGS setting to KRB5_LIBRARIES. This allows diff --git a/src/aclocal.m4 b/src/aclocal.m4 index 57c991859..44b1e768c 100644 --- a/src/aclocal.m4 +++ b/src/aclocal.m4 @@ -628,6 +628,25 @@ rm pre.out Makefile.out post.out ], CONF_FRAGDIR=$srcdir/${ac_config_fragdir} )])dnl dnl +dnl KRB5_SOCKADDR_SA_LEN: define HAVE_SA_LEN if sockaddr contains the sa_len +dnl component +dnl +AC_DEFUN([KRB5_SOCKADDR_SA_LEN],[ dnl +AC_MSG_CHECKING(Whether struct sockaddr contains sa_len) +AC_CACHE_VAL(krb5_cv_sockaddr_sa_len, +[AC_TRY_COMPILE([#include +#include +], +[struct sockaddr sa; +sa.sa_len;], +krb5_cv_sockaddr_sa_len=yes,krb5_cv_sockaddr_sa_len=no)]) +AC_MSG_RESULT([$]krb5_cv_sockaddr_sa_len) +if $krb5_cv_sockaddr_sa_len= yes; then + AC_DEFINE_UNQUOTED(HAVE_SA_LEN) + fi +]) +dnl +dnl dnl CHECK_UTMP: check utmp structure and functions dnl define(CHECK_UTMP,[ diff --git a/src/lib/crypto/os/ChangeLog b/src/lib/crypto/os/ChangeLog index c2708b7b1..5dcc23044 100644 --- a/src/lib/crypto/os/ChangeLog +++ b/src/lib/crypto/os/ChangeLog @@ -1,3 +1,10 @@ +Mon Jul 17 16:04:00 1995 Sam Hartman + + * localaddr.c (krb5_crypto_os_localaddr): Deal with variable sized + ifreq structures if sockaddr contains sa_len field. + + * configure.in: Check to see if struct sockaddr has sa_len. + Thu Jul 6 17:13:11 1995 Tom Yu * localaddr.c: migrated from lib/krb5/os diff --git a/src/lib/crypto/os/configure.in b/src/lib/crypto/os/configure.in index 4943ed770..ed9eedf4c 100644 --- a/src/lib/crypto/os/configure.in +++ b/src/lib/crypto/os/configure.in @@ -5,4 +5,5 @@ SubdirLibraryRule([${OBJS}]) AC_LN_S AC_REPLACE_FUNCS(memmove) AC_HAVE_FUNCS(srand48 srand srandom getpid) +KRB5_SOCKADDR_SA_LEN V5_AC_OUTPUT_MAKEFILE diff --git a/src/lib/crypto/os/localaddr.c b/src/lib/crypto/os/localaddr.c index 35e370a4a..ddf58181e 100644 --- a/src/lib/crypto/os/localaddr.c +++ b/src/lib/crypto/os/localaddr.c @@ -74,6 +74,20 @@ * Add more address families here. */ +/* + * BSD 4.4 defines the size of an ifreq to be max(sizeof(ifreq), sizeof(ifr.ifr_name)+ifreq.ifr_ifr_addr.sa_len + * However, under earlier systems, sa_len isn't present, so the size is + * just sizeof(struct ifreq) + */ +#ifdef HAVE_SA_LEN +#define ifreq_size(i) max(sizeof(struct ifreq),\ + sizeof(i.ifr_name)+i.ifr_addr.sa_len) +#else +#define ifreq_size(i) sizeof(struct ifreq) +#endif /* HAVE_SA_LEN*/ + + + extern int errno; /* @@ -112,11 +126,12 @@ krb5_crypto_os_localaddr(addr) closesocket (s); return retval; } - n = ifc.ifc_len / sizeof (struct ifreq); + n = ifc.ifc_len; - for (n_found=0, i=0; i