Fixes for variable length socket addresses.

git-svn-id: svn+ssh://svn.gna.org/svn/gnustep/libs/base/trunk@12215 72102866-910b-0410-8b05-ffd578937521
This commit is contained in:
CaS 2002-01-25 20:26:37 +00:00
parent 7f0e0f9b20
commit d8dc2bc2b4
6 changed files with 363 additions and 266 deletions

View file

@ -1,3 +1,13 @@
2002-01-25 Richard Frith-Macdonald <rfm@gnu.org>
* acconfig.h: Add HAVE_SA_LEN
* configure.in: Check for sa_len in sockaddr in struct ifreq
* configure: regenerate
* Headers/gnustep/base/config.h.in: regenerate
* Tools/gdomap.c: Add patch by Pete French <pete@twisted.org.uk>
to handle variable length socket addresses ... modified to work
with the rest of the world where we don't have such things.
2002-01-24 Richard Frith-Macdonald <rfm@gnu.org> 2002-01-24 Richard Frith-Macdonald <rfm@gnu.org>
* Source/NSRunLoop.m: Correct returns from within exception handler. * Source/NSRunLoop.m: Correct returns from within exception handler.

View file

@ -1,4 +1,4 @@
/* Headers/gnustep/base/config.h.in. Generated automatically from configure.in by autoheader. */ /* Headers/gnustep/base/config.h.in. Generated automatically from configure.in by autoheader 2.13. */
/* Define as __inline if that's what the C compiler calls it. */ /* Define as __inline if that's what the C compiler calls it. */
#undef inline #undef inline
@ -42,6 +42,9 @@
/* Define if your Lib C defines program_invocation_name */ /* Define if your Lib C defines program_invocation_name */
#undef HAVE_PROGRAM_INVOCATION_NAME #undef HAVE_PROGRAM_INVOCATION_NAME
/* Define if your system has variable length network addresses */
#undef HAVE_SA_LEN
/* Define if using the libffi library for invocations */ /* Define if using the libffi library for invocations */
#undef USE_LIBFFI #undef USE_LIBFFI

View file

@ -1082,11 +1082,10 @@ init_iface()
#ifdef SIOCGIFCONF #ifdef SIOCGIFCONF
struct ifconf ifc; struct ifconf ifc;
struct ifreq ifreq; struct ifreq ifreq;
struct ifreq *ifr; void *final;
struct ifreq *final; void *ifr_ptr;
char buf[MAX_IFACE * sizeof(struct ifreq)]; char buf[MAX_IFACE * sizeof(struct ifreq)];
int desc; int desc;
int num_iface;
if ((desc = socket(AF_INET, SOCK_DGRAM, 0)) < 0) if ((desc = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
{ {
@ -1120,8 +1119,7 @@ init_iface()
/* /*
* Find the IP address of each active network interface. * Find the IP address of each active network interface.
*/ */
num_iface = ifc.ifc_len / sizeof(struct ifreq); if (ifc.ifc_len == 0)
if (num_iface == 0)
{ {
int res = errno; int res = errno;
@ -1129,9 +1127,7 @@ init_iface()
if (res == EINVAL) if (res == EINVAL)
{ {
fprintf(stderr, fprintf(stderr,
"Either you have too many network interfaces on your machine (in which case\n" "Your system is buggy, thus you need to use the '-a' command line flag for\n"
"you need to change the 'MAX_IFACE' constant in gdomap.c and rebuild it), or\n"
"your system is buggy, and you need to use the '-a' command line flag for\n"
"gdomap to manually set the interface addresses and masks to be used.\n"); "gdomap to manually set the interface addresses and masks to be used.\n");
} }
#ifdef __MINGW__ #ifdef __MINGW__
@ -1141,19 +1137,29 @@ init_iface()
#endif #endif
exit(1); exit(1);
} }
/*
* We cannot know the number of interfaces in advance, thus we
* need to malloc to MAX_IFACE toensure sufficient space
*/
if (addr != 0) free(addr); if (addr != 0) free(addr);
addr = (struct in_addr*)malloc((num_iface+1)*IASIZE); addr = (struct in_addr*)malloc((MAX_IFACE+1)*IASIZE);
if (bcok != 0) free(bcok); if (bcok != 0) free(bcok);
bcok = (char*)malloc((num_iface+1)*sizeof(char)); bcok = (char*)malloc((MAX_IFACE+1)*sizeof(char));
if (bcst != 0) free(bcst); if (bcst != 0) free(bcst);
bcst = (struct in_addr*)malloc((num_iface+1)*IASIZE); bcst = (struct in_addr*)malloc((MAX_IFACE+1)*IASIZE);
if (mask != 0) free(mask); if (mask != 0) free(mask);
mask = (struct in_addr*)malloc((num_iface+1)*IASIZE); mask = (struct in_addr*)malloc((MAX_IFACE+1)*IASIZE);
final = (struct ifreq*)&ifc.ifc_buf[ifc.ifc_len]; final = &ifc.ifc_buf[ifc.ifc_len];
for (ifr = ifc.ifc_req; ifr < final; ifr++) for (ifr_ptr = ifc.ifc_req; ifr_ptr < final;)
{ {
ifreq = *ifr; ifreq = *(struct ifreq*)ifr_ptr;
#ifdef HAVE_SA_LEN
ifr_ptr += sizeof(ifreq) - sizeof(ifreq.ifr_name) + ifreq.ifr_addr.sa_len;
#else
ifr_ptr += sizeof(ifreq);
#endif
if (ioctl(desc, SIOCGIFFLAGS, (char *)&ifreq) < 0) if (ioctl(desc, SIOCGIFFLAGS, (char *)&ifreq) < 0)
{ {
perror("SIOCGIFFLAGS"); perror("SIOCGIFFLAGS");
@ -1162,6 +1168,7 @@ init_iface()
{ /* interface is up */ { /* interface is up */
int broadcast = 0; int broadcast = 0;
int pointopoint = 0; int pointopoint = 0;
int loopback = 0;
if (ifreq.ifr_flags & IFF_BROADCAST) if (ifreq.ifr_flags & IFF_BROADCAST)
{ {
@ -1172,6 +1179,12 @@ init_iface()
{ {
pointopoint = 1; pointopoint = 1;
} }
#endif
#ifdef IFF_LOOPBACK
if (ifreq.ifr_flags & IFF_LOOPBACK)
{
loopback = 1;
}
#endif #endif
if (ioctl(desc, SIOCGIFADDR, (char *)&ifreq) < 0) if (ioctl(desc, SIOCGIFADDR, (char *)&ifreq) < 0)
{ {
@ -1213,7 +1226,8 @@ init_iface()
else else
#endif #endif
{ {
if (ioctl(desc, SIOCGIFBRDADDR, (char*)&ifreq) < 0) if (!loopback &&
ioctl(desc, SIOCGIFBRDADDR, (char*)&ifreq) < 0)
{ {
perror("SIOCGIFBRDADDR"); perror("SIOCGIFBRDADDR");
bcok[interfaces] = 0; bcok[interfaces] = 0;

View file

@ -27,6 +27,10 @@
/* Define if your Lib C defines program_invocation_name */ /* Define if your Lib C defines program_invocation_name */
#undef HAVE_PROGRAM_INVOCATION_NAME #undef HAVE_PROGRAM_INVOCATION_NAME
/* Define if your system has variable length network addresses */
#undef HAVE_SA_LEN
/* Define if using the libffi library for invocations */ /* Define if using the libffi library for invocations */
#undef USE_LIBFFI #undef USE_LIBFFI

545
configure vendored

File diff suppressed because it is too large Load diff

View file

@ -132,6 +132,25 @@ if test $ac_cv_header_objc_objc_h = no; then
AC_MSG_ERROR(Could not find Objective-C headers) AC_MSG_ERROR(Could not find Objective-C headers)
fi fi
#--------------------------------------------------------------------
# Check for strange network stuff used by gdomap
#--------------------------------------------------------------------
AC_MSG_CHECKING(for gdomap network details)
AC_MSG_CHECKING(for variable length socket addresses)
AC_TRY_COMPILE([#include <net/if.h>],
[struct ifreq s; s.ifr_addr.sa_len = 0;],
sa_len=1, sa_len=0)
if test $sa_len = 1; then
AC_MSG_RESULT([found])
AC_DEFINE(HAVE_SA_LEN)
else
AC_MSG_RESULT([not found])
fi
#
#
AC_MSG_CHECKING(for objc threading flags)
#-------------------------------------------------------------------- #--------------------------------------------------------------------
# Check for thread flags for libobjc. # Check for thread flags for libobjc.
#-------------------------------------------------------------------- #--------------------------------------------------------------------