mirror of https://github.com/aria2/aria2
Try all found address set to bind sockets with --multiple-interface
Fixes GH-523pull/538/head
parent
e92027b9f0
commit
d2d06395d9
|
@ -306,7 +306,7 @@ void SocketCore::bind(const char* addr, uint16_t port, int family, int flags)
|
||||||
else {
|
else {
|
||||||
addrp = nullptr;
|
addrp = nullptr;
|
||||||
}
|
}
|
||||||
if (!(flags & AI_PASSIVE) || bindAddrs_.empty()) {
|
if (addrp || !(flags & AI_PASSIVE) || bindAddrsList_.empty()) {
|
||||||
sock_t fd = bindTo(addrp, port, family, sockType_, flags, error);
|
sock_t fd = bindTo(addrp, port, family, sockType_, flags, error);
|
||||||
if (fd == (sock_t)-1) {
|
if (fd == (sock_t)-1) {
|
||||||
throw DL_ABORT_EX(fmt(EX_SOCKET_BIND, error.c_str()));
|
throw DL_ABORT_EX(fmt(EX_SOCKET_BIND, error.c_str()));
|
||||||
|
@ -315,25 +315,30 @@ void SocketCore::bind(const char* addr, uint16_t port, int family, int flags)
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
for (const auto& a : bindAddrs_) {
|
std::array<char, NI_MAXHOST> host;
|
||||||
char host[NI_MAXHOST];
|
for (const auto& bindAddrs : bindAddrsList_) {
|
||||||
int s;
|
for (const auto& a : bindAddrs) {
|
||||||
s = getnameinfo(&a.first.sa, a.second, host, NI_MAXHOST, nullptr, 0,
|
if (family != AF_UNSPEC && family != a.first.storage.ss_family) {
|
||||||
NI_NUMERICHOST);
|
continue;
|
||||||
|
}
|
||||||
|
auto s = getnameinfo(&a.first.sa, a.second, host.data(), NI_MAXHOST,
|
||||||
|
nullptr, 0, NI_NUMERICHOST);
|
||||||
if (s) {
|
if (s) {
|
||||||
error = gai_strerror(s);
|
error = gai_strerror(s);
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
if (addrp && strcmp(host, addrp) != 0) {
|
if (addrp && strcmp(host.data(), addrp) != 0) {
|
||||||
error = "Given address and resolved address do not match.";
|
error = "Given address and resolved address do not match.";
|
||||||
continue;
|
continue;
|
||||||
}
|
}
|
||||||
sock_t fd = bindTo(host, port, family, sockType_, flags, error);
|
auto fd = bindTo(host.data(), port, family, sockType_, flags, error);
|
||||||
if (fd != (sock_t)-1) {
|
if (fd != (sock_t)-1) {
|
||||||
sockfd_ = fd;
|
sockfd_ = fd;
|
||||||
break;
|
return;
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
}
|
||||||
|
|
||||||
if (sockfd_ == (sock_t)-1) {
|
if (sockfd_ == (sock_t)-1) {
|
||||||
throw DL_ABORT_EX(fmt(EX_SOCKET_BIND, error.c_str()));
|
throw DL_ABORT_EX(fmt(EX_SOCKET_BIND, error.c_str()));
|
||||||
}
|
}
|
||||||
|
@ -1287,6 +1292,8 @@ void SocketCore::bindAddress(const std::string& iface)
|
||||||
A2_LOG_DEBUG(fmt("Sockets will bind to %s", host));
|
A2_LOG_DEBUG(fmt("Sockets will bind to %s", host));
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
bindAddrsList_.push_back(bindAddrs_);
|
||||||
|
bindAddrsListIt_ = std::begin(bindAddrsList_);
|
||||||
}
|
}
|
||||||
|
|
||||||
void SocketCore::bindAllAddress(const std::string& ifaces)
|
void SocketCore::bindAllAddress(const std::string& ifaces)
|
||||||
|
|
Loading…
Reference in New Issue