Просмотр исходного кода

Better handling of missing services
Author: jgg
Date: 1999-07-18 23:06:56 GMT
Better handling of missing services

Arch Librarian лет назад: 22
Родитель
Сommit
9505213b4c
4 измененных файлов с 36 добавлено и 20 удалено
  1. 29 13
      methods/connect.cc
  2. 3 3
      methods/connect.h
  3. 2 2
      methods/ftp.cc
  4. 2 2
      methods/http.cc

+ 29 - 13
methods/connect.cc

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
-// $Id: connect.cc,v 1.2 1999/07/10 05:39:29 jgg Exp $
+// $Id: connect.cc,v 1.3 1999/07/18 23:06:56 jgg Exp $
 /* ######################################################################
 
    Connect - Replacement connect call
@@ -75,7 +75,7 @@ static bool DoConnect(struct addrinfo *Addr,string Host,
 // Connect - Connect to a server					/*{{{*/
 // ---------------------------------------------------------------------
 /* Performs a connection to the server */
-bool Connect(string Host,int Port,const char *Service,int &Fd,
+bool Connect(string Host,int Port,const char *Service,int DefPort,int &Fd,
 	     unsigned long TimeOut,pkgAcqMethod *Owner)
 {
    if (_error->PendingError() == true)
@@ -106,22 +106,38 @@ bool Connect(string Host,int Port,const char *Service,int &Fd,
       struct addrinfo Hints;
       memset(&Hints,0,sizeof(Hints));
       Hints.ai_socktype = SOCK_STREAM;
+      Hints.ai_protocol = IPPROTO_TCP;       // Right?
       
       // Resolve both the host and service simultaneously
-      int Res;
-      if ((Res = getaddrinfo(Host.c_str(),S,&Hints,&LastHostAddr)) != 0 ||
-	  LastHostAddr == 0)
+      while (1)
       {
-	 if (Res == EAI_SERVICE)
-	    return _error->Error("Could not resolve service '%s'",S);
-	 
-	 if (Res == EAI_NONAME)
-	    return _error->Error("Could not resolve '%s'",Host.c_str());
-	 
-	 return _error->Error("Something wicked happend resolving '%s/%s'",
-			      Host.c_str(),S);
+	 int Res;
+	 if ((Res = getaddrinfo(Host.c_str(),S,&Hints,&LastHostAddr)) != 0 ||
+	     LastHostAddr == 0)
+	 {
+	    if (Res == EAI_SERVICE)
+	       return _error->Error("Could not resolve service '%s'",S);
+	    
+	    if (Res == EAI_NONAME)
+	    {
+	       if (DefPort != 0)
+	       {
+		  snprintf(S,sizeof(S),"%u",DefPort);
+		  DefPort = 0;
+		  continue;
+	       }
+	       return _error->Error("Could not resolve '%s'",Host.c_str());
+	    }
+	    
+	    return _error->Error("Something wicked happend resolving '%s/%s'",
+				 Host.c_str(),S);
+	 }
+	 break;
       }
       
+      if (LastHostAddr->ai_family == AF_UNIX)
+	 return _error->Error("getaddrinfo returned a unix domain socket\n");
+      
       LastHost = Host;
       LastPort = Port;
       LastUsed = 0;

+ 3 - 3
methods/connect.h

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
-// $Id: connect.h,v 1.1 1999/05/29 03:25:03 jgg Exp $
+// $Id: connect.h,v 1.2 1999/07/18 23:06:56 jgg Exp $
 /* ######################################################################
 
    Connect - Replacement connect call
@@ -13,7 +13,7 @@
 #include <string>
 #include <apt-pkg/acquire-method.h>
 
-bool Connect(string To,int Port,const char *Service,int &Fd,
-	     unsigned long TimeOut,pkgAcqMethod *Owner);
+bool Connect(string To,int Port,const char *Service,int DefPort,
+	     int &Fd,unsigned long TimeOut,pkgAcqMethod *Owner);
 
 #endif

+ 2 - 2
methods/ftp.cc

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
-// $Id: ftp.cc,v 1.13 1999/05/29 03:25:03 jgg Exp $
+// $Id: ftp.cc,v 1.14 1999/07/18 23:06:56 jgg Exp $
 /* ######################################################################
 
    HTTP Aquire Method - This is the FTP aquire method for APT.
@@ -125,7 +125,7 @@ bool FTPConn::Open(pkgAcqMethod *Owner)
    }
 
    // Connect to the remote server
-   if (Connect(Host,Port,"ftp",ServerFd,TimeOut,Owner) == false)
+   if (Connect(Host,Port,"ftp",21,ServerFd,TimeOut,Owner) == false)
       return false;
    socklen_t Len = sizeof(Peer);
    if (getpeername(ServerFd,(sockaddr *)&Peer,&Len) != 0)

+ 2 - 2
methods/http.cc

@@ -1,6 +1,6 @@
 // -*- mode: cpp; mode: fold -*-
 // Description								/*{{{*/
-// $Id: http.cc,v 1.35 1999/06/05 07:30:18 jgg Exp $
+// $Id: http.cc,v 1.36 1999/07/18 23:06:56 jgg Exp $
 /* ######################################################################
 
    HTTP Aquire Method - This is the HTTP aquire method for APT.
@@ -305,7 +305,7 @@ bool ServerState::Open()
    }
    
    // Connect to the remote server
-   if (Connect(Host,Port,"http",ServerFd,TimeOut,Owner) == false)
+   if (Connect(Host,Port,"http",80,ServerFd,TimeOut,Owner) == false)
       return false;
    
    return true;