merged from lp:~donkult/apt/experimental
[ntk/apt.git] / methods / connect.cc
index c5d57a9..16fb6e7 100644 (file)
@@ -11,7 +11,8 @@
    ##################################################################### */
                                                                        /*}}}*/
 // Include Files                                                       /*{{{*/
-#include "connect.h"
+#include <config.h>
+
 #include <apt-pkg/error.h>
 #include <apt-pkg/fileutl.h>
 
@@ -29,6 +30,7 @@
 #include <arpa/inet.h>
 #include <netdb.h>
 
+#include "connect.h"
 #include "rfc2553emu.h"
 #include <apti18n.h>
                                                                        /*}}}*/
@@ -115,6 +117,9 @@ static bool DoConnect(struct addrinfo *Addr,string Host,
       errno = Err;
       if(errno == ECONNREFUSED)
          Owner->SetFailReason("ConnectionRefused");
+      else if (errno == ETIMEDOUT)
+        Owner->SetFailReason("ConnectionTimedOut");
+      bad_addr.insert(bad_addr.begin(), string(Name));
       return _error->Errno("connect",_("Could not connect to %s:%s (%s)."),Host.c_str(),
                           Service,Name);
    }
@@ -157,6 +162,7 @@ bool Connect(string Host,int Port,const char *Service,int DefPort,int &Fd,
       struct addrinfo Hints;
       memset(&Hints,0,sizeof(Hints));
       Hints.ai_socktype = SOCK_STREAM;
+      Hints.ai_flags = AI_ADDRCONFIG;
       Hints.ai_protocol = 0;
       
       // if we couldn't resolve the host before, we don't try now
@@ -189,8 +195,8 @@ bool Connect(string Host,int Port,const char *Service,int DefPort,int &Fd,
               return _error->Error(_("Temporary failure resolving '%s'"),
                                    Host.c_str());
            }
-           return _error->Error(_("Something wicked happened resolving '%s:%s' (%i)"),
-                                Host.c_str(),ServStr,Res);
+           return _error->Error(_("Something wicked happened resolving '%s:%s' (%i - %s)"),
+                                Host.c_str(),ServStr,Res,gai_strerror(Res));
         }
         break;
       }
@@ -236,6 +242,6 @@ bool Connect(string Host,int Port,const char *Service,int DefPort,int &Fd,
 
    if (_error->PendingError() == true)
       return false;   
-   return _error->Error(_("Unable to connect to %s %s:"),Host.c_str(),ServStr);
+   return _error->Error(_("Unable to connect to %s:%s:"),Host.c_str(),ServStr);
 }
                                                                        /*}}}*/