2006-08-11 12:29:55 +00:00
|
|
|
/* <!-- copyright */
|
|
|
|
/*
|
2006-09-21 15:31:24 +00:00
|
|
|
* aria2 - The high speed download utility
|
2006-08-11 12:29:55 +00:00
|
|
|
*
|
|
|
|
* Copyright (C) 2006 Tatsuhiro Tsujikawa
|
|
|
|
*
|
|
|
|
* This program is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; either version 2 of the License, or
|
|
|
|
* (at your option) any later version.
|
|
|
|
*
|
|
|
|
* This program is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program; if not, write to the Free Software
|
2006-09-21 15:31:24 +00:00
|
|
|
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
|
|
|
|
*
|
|
|
|
* In addition, as a special exception, the copyright holders give
|
|
|
|
* permission to link the code of portions of this program with the
|
|
|
|
* OpenSSL library under certain conditions as described in each
|
|
|
|
* individual source file, and distribute linked combinations
|
|
|
|
* including the two.
|
|
|
|
* You must obey the GNU General Public License in all respects
|
|
|
|
* for all of the code used other than OpenSSL. If you modify
|
|
|
|
* file(s) with this exception, you may extend this exception to your
|
|
|
|
* version of the file(s), but you are not obligated to do so. If you
|
|
|
|
* do not wish to do so, delete this exception statement from your
|
|
|
|
* version. If you delete this exception statement from all source
|
|
|
|
* files in the program, then also delete it here.
|
2006-08-11 12:29:55 +00:00
|
|
|
*/
|
|
|
|
/* copyright --> */
|
|
|
|
#include "NameResolver.h"
|
2009-12-05 07:10:23 +00:00
|
|
|
|
|
|
|
#include <cstring>
|
|
|
|
|
2008-03-01 09:31:54 +00:00
|
|
|
#include "DlAbortEx.h"
|
2008-03-03 10:47:16 +00:00
|
|
|
#include "message.h"
|
2008-04-27 02:22:14 +00:00
|
|
|
#include "StringFormat.h"
|
2009-10-22 15:35:33 +00:00
|
|
|
#include "util.h"
|
2009-12-24 14:59:47 +00:00
|
|
|
#include "SocketCore.h"
|
2008-02-08 15:53:45 +00:00
|
|
|
|
|
|
|
namespace aria2 {
|
2006-08-11 12:29:55 +00:00
|
|
|
|
2009-12-05 07:10:23 +00:00
|
|
|
NameResolver::NameResolver():_socktype(0), _family(AF_UNSPEC) {}
|
2007-03-28 15:08:22 +00:00
|
|
|
|
2008-05-11 11:59:56 +00:00
|
|
|
void NameResolver::resolve(std::deque<std::string>& resolvedAddresses,
|
|
|
|
const std::string& hostname)
|
2008-02-08 15:53:45 +00:00
|
|
|
{
|
2007-03-28 15:08:22 +00:00
|
|
|
struct addrinfo* res;
|
2008-05-08 11:18:36 +00:00
|
|
|
int s;
|
2009-12-24 14:59:47 +00:00
|
|
|
s = callGetaddrinfo(&res, hostname.c_str(), 0, _family, _socktype, 0, 0);
|
2008-05-08 11:18:36 +00:00
|
|
|
if(s) {
|
2009-05-18 15:07:15 +00:00
|
|
|
throw DL_ABORT_EX(StringFormat(EX_RESOLVE_HOSTNAME,
|
2008-05-08 11:18:36 +00:00
|
|
|
hostname.c_str(), gai_strerror(s)).str());
|
|
|
|
}
|
2009-12-24 14:59:47 +00:00
|
|
|
auto_delete<struct addrinfo*> resDeleter(res, freeaddrinfo);
|
2008-05-08 11:18:36 +00:00
|
|
|
struct addrinfo* rp;
|
|
|
|
for(rp = res; rp; rp = rp->ai_next) {
|
|
|
|
std::pair<std::string, uint16_t> addressPort
|
2009-10-22 15:09:00 +00:00
|
|
|
= util::getNumericNameInfo(rp->ai_addr, rp->ai_addrlen);
|
2008-05-11 11:59:56 +00:00
|
|
|
resolvedAddresses.push_back(addressPort.first);
|
2007-03-28 15:08:22 +00:00
|
|
|
}
|
2008-02-08 15:53:45 +00:00
|
|
|
}
|
|
|
|
|
2008-05-08 11:18:36 +00:00
|
|
|
void NameResolver::setSocktype(int socktype)
|
2008-02-08 15:53:45 +00:00
|
|
|
{
|
2008-05-08 11:18:36 +00:00
|
|
|
_socktype = socktype;
|
2008-02-08 15:53:45 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
} // namespace aria2
|