]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
We should bind to the interface if we can - for the case where we renew and there...
authorRoy Marples <roy@marples.name>
Wed, 30 Jul 2008 11:05:45 +0000 (11:05 +0000)
committerRoy Marples <roy@marples.name>
Wed, 30 Jul 2008 11:05:45 +0000 (11:05 +0000)
net.c

diff --git a/net.c b/net.c
index 9f1b7adb08a48b45402ab95d30a3c1808021b35f..08f10cb404d018a6820937c5ed449191ffd11840 100644 (file)
--- 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));