From fa6fd758afc1dea263a43c3e21ed7b1b8ad0773c Mon Sep 17 00:00:00 2001 From: Tatsuhiro Tsujikawa Date: Tue, 23 Feb 2010 13:50:35 +0000 Subject: [PATCH] 2010-02-23 Tatsuhiro Tsujikawa Added aiFlags argument to getInterfaceAddress(). Use AI_NUMERICHOST to find interface specified using --bt-lpd-interface option to avoid time-consuming address lookup. * src/BtSetup.cc * src/SocketCore.cc * src/SocketCore.h --- ChangeLog | 9 +++++++++ src/BtSetup.cc | 2 +- src/SocketCore.cc | 8 +++----- src/SocketCore.h | 7 ++++--- 4 files changed, 17 insertions(+), 9 deletions(-) diff --git a/ChangeLog b/ChangeLog index 68f04304..9a5eddeb 100644 --- a/ChangeLog +++ b/ChangeLog @@ -1,3 +1,12 @@ +2010-02-23 Tatsuhiro Tsujikawa + + Added aiFlags argument to getInterfaceAddress(). Use + AI_NUMERICHOST to find interface specified using + --bt-lpd-interface option to avoid time-consuming address lookup. + * src/BtSetup.cc + * src/SocketCore.cc + * src/SocketCore.h + 2010-02-23 Tatsuhiro Tsujikawa Return SharedHandle(new LpdMessage()) if received data diff --git a/src/BtSetup.cc b/src/BtSetup.cc index d94148bc..b6799b73 100644 --- a/src/BtSetup.cc +++ b/src/BtSetup.cc @@ -188,7 +188,7 @@ void BtSetup::setup(std::deque& commands, } } else { std::vector > ifAddrs; - getInterfaceAddress(ifAddrs, lpdInterface, AF_INET); + getInterfaceAddress(ifAddrs, lpdInterface, AF_INET, AI_NUMERICHOST); for(std::vector >::const_iterator i = ifAddrs.begin(); i != ifAddrs.end(); ++i) { sockaddr_in addr; diff --git a/src/SocketCore.cc b/src/SocketCore.cc index 68cfd33f..3857922d 100644 --- a/src/SocketCore.cc +++ b/src/SocketCore.cc @@ -1267,7 +1267,7 @@ void SocketCore::bindAddress(const std::string& iface) void getInterfaceAddress (std::vector >& ifAddrs, - const std::string& iface, int family) + const std::string& iface, int family, int aiFlags) { Logger* logger = LogFactory::getInstance(); if(logger->debug()) { @@ -1314,11 +1314,9 @@ void getInterfaceAddress if(ifAddrs.empty()) { struct addrinfo* res; int s; - s = callGetaddrinfo(&res, iface.c_str(), 0, family, - SOCK_STREAM, 0, 0); + s = callGetaddrinfo(&res, iface.c_str(), 0, family, SOCK_STREAM, aiFlags,0); if(s) { - logger->info(MSG_INTERFACE_NOT_FOUND, - iface.c_str(), gai_strerror(s)); + logger->info(MSG_INTERFACE_NOT_FOUND, iface.c_str(), gai_strerror(s)); } else { WSAAPI_AUTO_DELETE resDeleter(res, freeaddrinfo); struct addrinfo* rp; diff --git a/src/SocketCore.h b/src/SocketCore.h index b1949cb4..e306a43d 100644 --- a/src/SocketCore.h +++ b/src/SocketCore.h @@ -381,7 +381,7 @@ public: friend void getInterfaceAddress (std::vector >& ifAddrs, - const std::string& iface, int family); + const std::string& iface, int family, int aiFlags); }; // Set default ai_flags. hints.ai_flags is initialized with this @@ -399,10 +399,11 @@ int callGetaddrinfo // Collects IP addresses of given inteface iface and stores in // ifAddres. iface may be specified as a hostname, IP address or // interface name like eth0. You can limit the family of IP addresses -// to collect using family argument. No throw. +// to collect using family argument. aiFlags is passed to +// getaddrinfo() as hints.ai_flags. No throw. void getInterfaceAddress (std::vector >& ifAddrs, - const std::string& iface, int family = AF_UNSPEC); + const std::string& iface, int family = AF_UNSPEC, int aiFlags = 0); } // namespace aria2