Simplify and correct bindtodevice().

This commit is contained in:
Kurt H Maier
2018-01-26 15:10:59 +00:00
committed by Simon Kelley
parent be9a74d2f8
commit 486bcd5a7b

View File

@@ -485,11 +485,8 @@ char *whichdevice(void)
void bindtodevice(char *device, int fd) void bindtodevice(char *device, int fd)
{ {
struct ifreq ifr;
strcpy(ifr.ifr_name, device);
/* only allowed by root. */ /* 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) errno != EPERM)
die(_("failed to set SO_BINDTODEVICE on DHCP socket: %s"), NULL, EC_BADNET); die(_("failed to set SO_BINDTODEVICE on DHCP socket: %s"), NULL, EC_BADNET);
} }