Updated error messages to reflect host/ip
[ntk/apt.git] / methods / http.cc
index 0c0acf6..4e659cc 100644 (file)
@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description                                                         /*{{{*/
-// $Id: http.cc,v 1.31 1999/05/25 05:56:24 jgg Exp $
+// $Id: http.cc,v 1.33 1999/05/28 07:04:45 jgg Exp $
 /* ######################################################################
 
    HTTP Aquire Method - This is the HTTP aquire method for APT.
@@ -338,28 +338,35 @@ bool ServerState::Open()
       LastHost = Host;
       LastPort = Port;
    }
-      
-   // Connect to the server
+
+   // Get the printable IP address
+   char Name[NI_MAXHOST];
+   Name[0] = 0;
+   getnameinfo(LastHostAddr->ai_addr,LastHostAddr->ai_addrlen,
+              Name,sizeof(Name),0,0,NI_NUMERICHOST);
+   Owner->Status("Connecting to %s (%s)",Host.c_str(),Name);
+   
    // Get a socket
-//   Owner->Status("Connecting to %s (%s)",Host.c_str(),inet_ntoa(LastHostA));
    if ((ServerFd = socket(LastHostAddr->ai_family,LastHostAddr->ai_socktype,
                          LastHostAddr->ai_protocol)) < 0)
       return _error->Errno("socket","Could not create a socket");
    SetNonBlock(ServerFd,true);
    if (connect(ServerFd,LastHostAddr->ai_addr,LastHostAddr->ai_addrlen) < 0 &&
        errno != EINPROGRESS)
-      return _error->Errno("connect","Connect initiate the connection");
+      return _error->Errno("connect","Cannot initiate the connection "
+                          "to %s (%s).",Host.c_str(),Name);
 
    /* This implements a timeout for connect by opening the connection
       nonblocking */
    if (WaitFd(ServerFd,true,TimeOut) == false)
-      return _error->Error("Could not connect, connection timed out");
+      return _error->Error("Could not connect to %s (%s), "
+                          "connection timed out",Host.c_str(),Name);
    unsigned int Err;
    unsigned int Len = sizeof(Err);
    if (getsockopt(ServerFd,SOL_SOCKET,SO_ERROR,&Err,&Len) != 0)
       return _error->Errno("getsockopt","Failed");
    if (Err != 0)
-      return _error->Error("Could not connect.");
+      return _error->Error("Could not connect to %s (%s).",Host.c_str(),Name);
    
    return true;
 }