From: Roy Marples Date: Wed, 30 Jul 2008 11:05:45 +0000 (+0000) Subject: We should bind to the interface if we can - for the case where we renew and there... X-Git-Tag: v4.0.2~112 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=0fc7ff3ed64bdf14440e78acae611ae78ff6dc4d;p=thirdparty%2Fdhcpcd.git We should bind to the interface if we can - for the case where we renew and there are two interfaces on the same subnet and the default subnet route goes via the wrong interface. --- diff --git a/net.c b/net.c index 9f1b7adb..08f10cb4 100644 --- a/net.c +++ b/net.c @@ -483,15 +483,26 @@ open_udp_socket(struct interface *iface) struct sockaddr sa; struct sockaddr_in sin; } su; - int n = 1; + int n; +#ifdef SO_BINDTODEVICE + struct ifreq ifr; +#endif if ((s = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) return -1; + n = 1; if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &n, sizeof(n)) == -1) goto eexit; - /* As we don't actually use this socket for anything, set - * the receiver buffer to 1 */ +#ifdef SO_BINDTODEVICE + memset(&ifr, 0, sizeof(ifr)); + strlcpy(ifr.ifr_name, iface->name, sizeof(ifr.ifr_name)); + if (setsockopt(s, SOL_SOCKET, SO_BINDTODEVICE, &ifr, sizeof(ifr)) == -1) + goto eexit; +#endif + /* As we don't use this socket for receiving, set the + * receive buffer to 1 */ + n = 1; if (setsockopt(s, SOL_SOCKET, SO_RCVBUF, &n, sizeof(n)) == -1) goto eexit; memset(&su, 0, sizeof(su));