Subject: Re: dhcpd
To: Greg Troxel <gdt@ir.bbn.com>
From: Patrick Welche <prlw1@newn.cam.ac.uk>
List: tech-net
Date: 09/13/2007 12:00:44
On Wed, Sep 12, 2007 at 08:09:09PM -0400, Greg Troxel wrote:
> If anyone wants to try this change, I think it will fix dhcp, but I
> haven't even compiled it.  (The code looks like it has more problems -
> lending weight to the 'all users of SIOCGIFCONF shoudl be converted to
> getifaddrs.)  The if being changed will never be taken in -current.
> 
> Index: dist/dhcp/common/discover.c
> ===================================================================
> RCS file: /cvsroot/src/dist/dhcp/common/discover.c,v
> retrieving revision 1.9
> diff -u -p -r1.9 discover.c
> --- dist/dhcp/common/discover.c	31 May 2007 02:58:10 -0000	1.9
> +++ dist/dhcp/common/discover.c	13 Sep 2007 00:07:07 -0000
> @@ -235,7 +235,7 @@ void discover_interfaces (state)
>  
>  		memcpy(&ifcpy, (caddr_t)ic.ifc_req + i, sizeof(struct ifreq));
>  #ifdef HAVE_SA_LEN
> -		if (ifp -> ifr_addr.sa_len > sizeof (struct sockaddr)) {
> +		if (ifp -> ifr_addr.sa_len > sizeof (ifp.ifr_ifru)) {
>  			if (sizeof(struct ifreq) + ifp->ifr_addr.sa_len >
>  			    sizeof(ifcpy))
>  				break;
> 

Last night my coach journey ended too soon ;-) dhpcd's use of the results
of SIOCGIFCONF was the right place to look, because the first time
through the loop, all is OK, but the second time around, the size matters

                        i += offsetof(struct ifreq, ifr_ifru) +
                            ifp -> ifr_addr.sa_len;
or
                        i += sizeof *ifp;
and the next use of (ic.ifc_req + i) - the SIOCGIFFLAGS ioctl - fails.

I tried

                if (ifp -> ifr_addr.sa_len > sizeof (ifp -> ifr_ifru)) {       

as you suggest, and all is well!

Thank you,

Patrick