Right now bindtodevice() declares an ifreq, copies the device name into
it, and passes a pointer to the entire structure as the optval for
setsockopt.  This only works because ifr_name happens to be the first
element in the ifreq data structure.  What actually gets passed to
setsockopt looks like 
and is 40 bytes long.

We could change it so we pass ifr.ifr_name, but this is wasteful too,
since device is already in the format we want.

Attached is a patch that uses device directly, and passes IFNAMSIZ as


diff --git a/src/dhcp-common.c b/src/dhcp-common.c
index eae9ae3..8e128fa 100644
--- a/src/dhcp-common.c
+++ b/src/dhcp-common.c
@@ -485,11 +485,8 @@ char *whichdevice(void)
 void  bindtodevice(char *device, int fd)
-  struct ifreq ifr;
-  strcpy(ifr.ifr_name, device);
   /* only allowed by root. */
-  if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, (void *)&ifr, sizeof(ifr)) 
== -1 &&
+  if (setsockopt(fd, SOL_SOCKET, SO_BINDTODEVICE, device, IFNAMSIZ) == -1 &&
       errno != EPERM)
     die(_("failed to set SO_BINDTODEVICE on DHCP socket: %s"), NULL, 

Dnsmasq-discuss mailing list

Reply via email to