diff options
| author | Roy Marples <roy@marples.name> | 2008-07-30 11:05:45 +0000 |
|---|---|---|
| committer | Roy Marples <roy@marples.name> | 2008-07-30 11:05:45 +0000 |
| commit | 0fc7ff3ed64bdf14440e78acae611ae78ff6dc4d (patch) | |
| tree | 2d32aafc2b82c83cc1da3238a335e292ee50fe65 /net.c | |
| parent | 1e3374e9841aab38b557b7f7f835bb775446028e (diff) | |
| download | dhcpcd-0fc7ff3ed64bdf14440e78acae611ae78ff6dc4d.tar.xz | |
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.
Diffstat (limited to 'net.c')
| -rw-r--r-- | net.c | 17 |
1 files changed, 14 insertions, 3 deletions
@@ -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)); |
