projects
/
apt.git
/ blobdiff
commit
grep
author
committer
pickaxe
?
search:
re
summary
|
shortlog
|
log
|
commit
|
commitdiff
|
tree
raw
|
inline
| side by side
correct some style/performance/warnings from cppcheck
[apt.git]
/
methods
/
connect.cc
diff --git
a/methods/connect.cc
b/methods/connect.cc
index 9a092a43c20298ea47034ca157e76e7e64a9d5d6..d9c9a1dd4bc41da0798dcd5987222d949ab89e92 100644
(file)
--- a/
methods/connect.cc
+++ b/
methods/connect.cc
@@
-17,6
+17,7
@@
#include <apt-pkg/fileutl.h>
#include <apt-pkg/strutl.h>
#include <apt-pkg/acquire-method.h>
#include <apt-pkg/fileutl.h>
#include <apt-pkg/strutl.h>
#include <apt-pkg/acquire-method.h>
+#include <apt-pkg/configuration.h>
#include <stdio.h>
#include <errno.h>
#include <stdio.h>
#include <errno.h>
@@
-141,9
+142,9
@@
bool Connect(std::string Host,int Port,const char *Service,int DefPort,int &Fd,
// Convert the port name/number
char ServStr[300];
if (Port != 0)
// Convert the port name/number
char ServStr[300];
if (Port != 0)
- snprintf(ServStr,sizeof(ServStr),"%
u",
Port);
+ snprintf(ServStr,sizeof(ServStr),"%
i",
Port);
else
else
- snprintf(ServStr,sizeof(ServStr),"%s",Service);
+ snprintf(ServStr,sizeof(ServStr),"%s",
Service);
/* We used a cached address record.. Yes this is against the spec but
the way we have setup our rotating dns suggests that this is more
/* We used a cached address record.. Yes this is against the spec but
the way we have setup our rotating dns suggests that this is more
@@
-167,6
+168,13
@@
bool Connect(std::string Host,int Port,const char *Service,int DefPort,int &Fd,
Hints.ai_flags = AI_ADDRCONFIG;
Hints.ai_protocol = 0;
Hints.ai_flags = AI_ADDRCONFIG;
Hints.ai_protocol = 0;
+ if(_config->FindB("Acquire::ForceIPv4", false) == true)
+ Hints.ai_family = AF_INET;
+ else if(_config->FindB("Acquire::ForceIPv6", false) == true)
+ Hints.ai_family = AF_INET6;
+ else
+ Hints.ai_family = AF_UNSPEC;
+
// if we couldn't resolve the host before, we don't try now
if(bad_addr.find(Host) != bad_addr.end())
return _error->Error(_("Could not resolve '%s'"),Host.c_str());
// if we couldn't resolve the host before, we don't try now
if(bad_addr.find(Host) != bad_addr.end())
return _error->Error(_("Could not resolve '%s'"),Host.c_str());
@@
-182,7
+190,7
@@
bool Connect(std::string Host,int Port,const char *Service,int DefPort,int &Fd,
{
if (DefPort != 0)
{
{
if (DefPort != 0)
{
- snprintf(ServStr,
sizeof(ServStr),"%u",
DefPort);
+ snprintf(ServStr,
sizeof(ServStr), "%i",
DefPort);
DefPort = 0;
continue;
}
DefPort = 0;
continue;
}
@@
-197,6
+205,9
@@
bool Connect(std::string Host,int Port,const char *Service,int DefPort,int &Fd,
return _error->Error(_("Temporary failure resolving '%s'"),
Host.c_str());
}
return _error->Error(_("Temporary failure resolving '%s'"),
Host.c_str());
}
+ if (Res == EAI_SYSTEM)
+ return _error->Errno("getaddrinfo", _("System error resolving '%s:%s'"),
+ Host.c_str(),ServStr);
return _error->Error(_("Something wicked happened resolving '%s:%s' (%i - %s)"),
Host.c_str(),ServStr,Res,gai_strerror(Res));
}
return _error->Error(_("Something wicked happened resolving '%s:%s' (%i - %s)"),
Host.c_str(),ServStr,Res,gai_strerror(Res));
}