summaryrefslogtreecommitdiff
path: root/methods
diff options
context:
space:
mode:
authorArch Librarian <arch@canonical.com>2004-09-20 16:53:51 +0000
committerArch Librarian <arch@canonical.com>2004-09-20 16:53:51 +0000
commit533151d3ff0e22a91d0e2bcfc0fa225e8843c97f (patch)
tree8dc1efb8c9dab1d481fd7373f0eb07122c7bbd81 /methods
parent934b6582b4518630a050c8b84853b8e78ed87905 (diff)
Final rfc2553 changes
Author: jgg Date: 1999-05-26 04:08:39 GMT Final rfc2553 changes
Diffstat (limited to 'methods')
-rw-r--r--methods/http.cc13
-rw-r--r--methods/rfc2553emu.cc95
-rw-r--r--methods/rfc2553emu.h22
3 files changed, 120 insertions, 10 deletions
diff --git a/methods/http.cc b/methods/http.cc
index 0c0acf60f..067d80564 100644
--- a/methods/http.cc
+++ b/methods/http.cc
@@ -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.32 1999/05/26 04:08:39 jgg Exp $
/* ######################################################################
HTTP Aquire Method - This is the HTTP aquire method for APT.
@@ -338,10 +338,15 @@ 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");
diff --git a/methods/rfc2553emu.cc b/methods/rfc2553emu.cc
index 66fe781fb..1b0628f98 100644
--- a/methods/rfc2553emu.cc
+++ b/methods/rfc2553emu.cc
@@ -1,6 +1,6 @@
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: rfc2553emu.cc,v 1.1 1999/05/25 05:56:24 jgg Exp $
+// $Id: rfc2553emu.cc,v 1.2 1999/05/26 04:08:39 jgg Exp $
/* ######################################################################
RFC 2553 Emulation - Provides emulation for RFC 2553 getaddrinfo,
@@ -14,9 +14,13 @@
#include "rfc2553emu.h"
#include <stdlib.h>
#include <arpa/inet.h>
-#include <iostream.h>
+#include <string.h>
+#include <stdio.h>
#ifndef HAVE_GETADDRINFO
+// getaddrinfo - Resolve a hostname /*{{{*/
+// ---------------------------------------------------------------------
+/* */
int getaddrinfo(const char *nodename, const char *servname,
const struct addrinfo *hints,
struct addrinfo **res)
@@ -123,7 +127,10 @@ int getaddrinfo(const char *nodename, const char *servname,
return 0;
}
-
+ /*}}}*/
+// freeaddrinfo - Free the result of getaddrinfo /*{{{*/
+// ---------------------------------------------------------------------
+/* */
void freeaddrinfo(struct addrinfo *ai)
{
struct addrinfo *Tmp;
@@ -135,5 +142,85 @@ void freeaddrinfo(struct addrinfo *ai)
free(ai);
}
}
-
+ /*}}}*/
#endif // HAVE_GETADDRINFO
+
+#ifndef HAVE_GETNAMEINFO
+// getnameinfo - Convert a sockaddr to a string /*{{{*/
+// ---------------------------------------------------------------------
+/* */
+int getnameinfo(const struct sockaddr *sa, socklen_t salen,
+ char *host, size_t hostlen,
+ char *serv, size_t servlen,
+ int flags)
+{
+ struct sockaddr_in *sin = (struct sockaddr_in *)sa;
+
+ // This routine only support internet addresses
+ if (sa->sa_family != AF_INET)
+ return EAI_ADDRFAMILY;
+
+ if (host != 0)
+ {
+ // Try to resolve the hostname
+ if ((flags & NI_NUMERICHOST) != NI_NUMERICHOST)
+ {
+ struct hostent *Ent = gethostbyaddr((char *)&sin->sin_addr,sizeof(sin->sin_addr),
+ AF_INET);
+ if (Ent != 0)
+ strncpy(host,Ent->h_name,hostlen);
+ else
+ {
+ if ((flags & NI_NAMEREQD) == NI_NAMEREQD)
+ {
+ if (h_errno == TRY_AGAIN)
+ return EAI_AGAIN;
+ if (h_errno == NO_RECOVERY)
+ return EAI_FAIL;
+ return EAI_NONAME;
+ }
+
+ flags |= NI_NUMERICHOST;
+ }
+ }
+
+ // Resolve as a plain numberic
+ if ((flags & NI_NUMERICHOST) == NI_NUMERICHOST)
+ {
+ strncpy(host,inet_ntoa(sin->sin_addr),hostlen);
+ }
+ }
+
+ if (serv != 0)
+ {
+ // Try to resolve the hostname
+ if ((flags & NI_NUMERICSERV) != NI_NUMERICSERV)
+ {
+ struct servent *Ent;
+ if ((flags & NI_DATAGRAM) == NI_DATAGRAM)
+ Ent = getservbyport(sin->sin_port,"udp");
+ else
+ Ent = getservbyport(sin->sin_port,"tcp");
+
+ if (Ent != 0)
+ strncpy(serv,Ent->s_name,servlen);
+ else
+ {
+ if ((flags & NI_NAMEREQD) == NI_NAMEREQD)
+ return EAI_NONAME;
+
+ flags |= NI_NUMERICSERV;
+ }
+ }
+
+ // Resolve as a plain numberic
+ if ((flags & NI_NUMERICSERV) == NI_NUMERICSERV)
+ {
+ snprintf(serv,servlen,"%u",sin->sin_port);
+ }
+ }
+
+ return 0;
+}
+ /*}}}*/
+#endif // HAVE_GETNAMEINFO
diff --git a/methods/rfc2553emu.h b/methods/rfc2553emu.h
index e24e7a3c1..5b9abbd84 100644
--- a/methods/rfc2553emu.h
+++ b/methods/rfc2553emu.h
@@ -1,6 +1,6 @@
// -*- mode: cpp; mode: fold -*-
// Description /*{{{*/
-// $Id: rfc2553emu.h,v 1.1 1999/05/25 05:56:24 jgg Exp $
+// $Id: rfc2553emu.h,v 1.2 1999/05/26 04:08:39 jgg Exp $
/* ######################################################################
RFC 2553 Emulation - Provides emulation for RFC 2553 getaddrinfo,
@@ -31,6 +31,11 @@
#define HAVE_GETADDRINFO
#endif
+// Autosense getnameinfo
+#if defined(NI_NUMERICHOST)
+#define HAVE_GETNAMEINFO
+#endif
+
// getaddrinfo support?
#ifndef HAVE_GETADDRINFO
#error Boink
@@ -67,7 +72,6 @@
#define EAI_SOCKTYPE -6
#define EAI_SERVICE -7
#define EAI_ADDRFAMILY -8
- #define EAI_ADDRFAMILY -8
#define EAI_SYSTEM -10
#endif
@@ -80,6 +84,20 @@
char *host, size_t hostlen,
char *serv, size_t servlen,
int flags);
+
+ #ifndef NI_MAXHOST
+ #define NI_MAXHOST 1025
+ #define NI_MAXSERV 32
+ #endif
+
+ #ifndef NI_NUMERICHOST
+ #define NI_NUMERICHOST (1<<0)
+ #define NI_NUMERICSERV (1<<1)
+// #define NI_NOFQDN (1<<2)
+ #define NI_NAMEREQD (1<<3)
+ #define NI_DATAGRAM (1<<4)
+ #endif
+
#endif
#endif