don't make bogus assumptions about struct alignment.

This commit is contained in:
christos 2007-05-31 02:58:10 +00:00
parent f6ca3502bf
commit f84135414c

View File

@ -34,11 +34,12 @@
#ifndef lint #ifndef lint
static char copyright[] = static char copyright[] =
"$Id: discover.c,v 1.8 2006/11/23 13:07:17 martin Exp $ Copyright (c) 2004-2005 Internet Systems Consortium. All rights reserved.\n"; "$Id: discover.c,v 1.9 2007/05/31 02:58:10 christos Exp $ Copyright (c) 2004-2005 Internet Systems Consortium. All rights reserved.\n";
#endif /* not lint */ #endif /* not lint */
#include "dhcpd.h" #include "dhcpd.h"
#include <sys/ioctl.h> #include <sys/ioctl.h>
#include <stddef.h>
struct interface_info *interfaces, *dummy_interfaces, *fallback_interface; struct interface_info *interfaces, *dummy_interfaces, *fallback_interface;
int interfaces_invalidated; int interfaces_invalidated;
@ -240,7 +241,8 @@ void discover_interfaces (state)
break; break;
memcpy(&ifcpy, (caddr_t)ic.ifc_req + i, memcpy(&ifcpy, (caddr_t)ic.ifc_req + i,
sizeof(struct ifreq) + ifp->ifr_addr.sa_len); sizeof(struct ifreq) + ifp->ifr_addr.sa_len);
i += (sizeof ifp -> ifr_name) + ifp -> ifr_addr.sa_len; i += offsetof(struct ifreq, ifr_ifru) +
ifp -> ifr_addr.sa_len;
} else } else
#endif #endif
i += sizeof *ifp; i += sizeof *ifp;
@ -344,8 +346,8 @@ void discover_interfaces (state)
which we found it. */ which we found it. */
if (!tmp -> ifp) { if (!tmp -> ifp) {
#ifdef HAVE_SA_LEN #ifdef HAVE_SA_LEN
unsigned len = ((sizeof ifp -> ifr_name) + unsigned len = offsetof(struct ifreq, ifr_ifru)
ifp -> ifr_addr.sa_len); + ifp -> ifr_addr.sa_len;
#else #else
unsigned len = sizeof *ifp; unsigned len = sizeof *ifp;
#endif #endif