gnunet-svn
[Top][All Lists]
Advanced

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

[GNUnet-SVN] r2501 - in GNUnet/src: applications/bootstrap_http applicat


From: grothoff
Subject: [GNUnet-SVN] r2501 - in GNUnet/src: applications/bootstrap_http applications/testbed include transports util
Date: Mon, 13 Mar 2006 00:14:25 -0800 (PST)

Author: grothoff
Date: 2006-03-13 00:14:20 -0800 (Mon, 13 Mar 2006)
New Revision: 2501

Modified:
   GNUnet/src/applications/bootstrap_http/http.c
   GNUnet/src/applications/testbed/commands.c
   GNUnet/src/applications/testbed/testbed.c
   GNUnet/src/include/gnunet_util.h
   GNUnet/src/transports/http.c
   GNUnet/src/transports/ip.c
   GNUnet/src/transports/smtp.c
   GNUnet/src/util/configuration.c
   GNUnet/src/util/tcpio.c
Log:
possibly fixing #996

Modified: GNUnet/src/applications/bootstrap_http/http.c
===================================================================
--- GNUnet/src/applications/bootstrap_http/http.c       2006-03-13 01:37:51 UTC 
(rev 2500)
+++ GNUnet/src/applications/bootstrap_http/http.c       2006-03-13 08:14:20 UTC 
(rev 2501)
@@ -63,7 +63,7 @@
   char * hostname;
   char * filename;
   unsigned int curpos, lenHostname, lenUrl;
-  struct hostent *ip_info;
+  IPaddr ip_info;
   struct sockaddr_in soaddr;
   int sock;
   size_t ret;
@@ -127,8 +127,7 @@
 
   /* Do we need to connect through a proxy? */
   if (theProxy.sin_addr.s_addr == 0) {
-    ip_info = GETHOSTBYNAME(hostname);
-    if (ip_info == NULL) {
+    if (OK != GN_getHostByName(hostname, &ip_info)) {
       LOG(LOG_WARNING,
          _("Could not download list of peer contacts, host `%s' unknown.\n"),
          hostname);
@@ -136,8 +135,9 @@
       return;
     }
 
-    soaddr.sin_addr.s_addr
-      = ((struct in_addr*)(ip_info->h_addr))->s_addr;
+    memcpy(&soaddr.sin_addr.s_addr,
+          &ip_info,
+          sizeof(IPaddr));
     soaddr.sin_port
       = htons(port);
   } else {
@@ -319,20 +319,21 @@
 provide_module_bootstrap(CoreAPIForApplication * capi) {
   static Bootstrap_ServiceAPI api;
   char *proxy, *proxyPort;
-  struct hostent *ip;
+  IPaddr ip;
 
   proxy = getConfigurationString("GNUNETD",
                                 "HTTP-PROXY");
   if (proxy != NULL) {
-    ip = GETHOSTBYNAME(proxy);
-    if (ip == NULL) {
+    if (OK != GN_getHostByName(proxy,
+                              &ip)) {
       LOG(LOG_ERROR,
          _("Could not resolve name of HTTP proxy `%s'. Trying without a 
proxy.\n"),
          proxy);
       theProxy.sin_addr.s_addr = 0;
     } else {
-      theProxy.sin_addr.s_addr
-       = ((struct in_addr *)ip->h_addr)->s_addr;
+      memcpy(&theProxy.sin_addr.s_addr,
+            &ip,
+            sizeof(IPaddr));
       proxyPort = getConfigurationString("GNUNETD",
                                         "HTTP-PROXY-PORT");
       if (proxyPort == NULL) {

Modified: GNUnet/src/applications/testbed/commands.c
===================================================================
--- GNUnet/src/applications/testbed/commands.c  2006-03-13 01:37:51 UTC (rev 
2500)
+++ GNUnet/src/applications/testbed/commands.c  2006-03-13 08:14:20 UTC (rev 
2501)
@@ -1450,7 +1450,6 @@
   long int port;
   char * hostname;
   unsigned int curpos;
-  struct hostent *ip_info;
   struct sockaddr_in soaddr;
   int sock;
   size_t ret;
@@ -1463,7 +1462,7 @@
   int k;
   struct sockaddr_in theProxy;
   char *proxy, *proxyPort;
-  struct hostent *ip;
+  IPaddr ip;
   size_t n;
 
   if (argc == 0) {
@@ -1481,14 +1480,15 @@
   proxy = getConfigurationString("GNUNETD",
                                 "HTTP-PROXY");
   if (proxy != NULL) {
-    ip = GETHOSTBYNAME(proxy);
-    if (ip == NULL) {
-      XPRINTF(" Couldn't resolve name of HTTP proxy %s\n",
-            proxy);
+    if (OK != GN_getHostByName(proxy,
+                              &ip)) {
+      XPRINTF(" Couldn't resolve name of HTTP proxy '%s'\n",
+             proxy);
       theProxy.sin_addr.s_addr = 0;
     } else {
-      theProxy.sin_addr.s_addr
-       = ((struct in_addr *)ip->h_addr)->s_addr;
+      memcpy(&theProxy.sin_addr.s_addr,
+            &ip,
+            sizeof(IPaddr));
       proxyPort = getConfigurationString("GNUNETD",
                                         "HTTP-PROXY-PORT");
       if (proxyPort == NULL) {
@@ -1578,16 +1578,17 @@
   /* Do we need to connect through a proxy? */
   if (theProxy.sin_addr.s_addr == 0) {
     /* no proxy */
-    ip_info = GETHOSTBYNAME(hostname);
-    if (ip_info == NULL) {
-      XPRINTF(" could not download hostlist, host %s unknown\n",
+    if (OK != GN_getHostByName(hostname,
+                              &ip)) {
+      XPRINTF(" could not download hostlist, host '%s' unknown\n",
             hostname);
       FREE(reg);
       FREE(hostname);
       return -1;
     }
-    soaddr.sin_addr.s_addr
-      = ((struct in_addr*)(ip_info->h_addr))->s_addr;
+    memcpy(&soaddr.sin_addr.s_addr,
+          &ip,
+          sizeof(IPaddr));
     soaddr.sin_port
       = htons((unsigned short)port);
   } else {

Modified: GNUnet/src/applications/testbed/testbed.c
===================================================================
--- GNUnet/src/applications/testbed/testbed.c   2006-03-13 01:37:51 UTC (rev 
2500)
+++ GNUnet/src/applications/testbed/testbed.c   2006-03-13 08:14:20 UTC (rev 
2501)
@@ -1019,7 +1019,7 @@
   long int port;
   char * hostname;
   unsigned int curpos;
-  struct hostent *ip_info;
+  IPaddr ip_info;
   struct sockaddr_in soaddr;
   int sock;
   size_t ret;
@@ -1050,15 +1050,15 @@
   proxy = getConfigurationString("GNUNETD",
                                 "HTTP-PROXY");
   if (proxy != NULL) {
-    ip = GETHOSTBYNAME(proxy);
-    if (ip == NULL) {
+    if (OK != GN_getHostByName(proxy, &ip_info)) {
       LOG(LOG_ERROR,
          _("Could not resolve name of HTTP proxy `%s'.\n"),
          proxy);
       theProxy.sin_addr.s_addr = 0;
     } else {
-      theProxy.sin_addr.s_addr
-       = ((struct in_addr *)ip->h_addr)->s_addr;
+      memcpy(&theProxy.sin_addr.s_addr,
+            &ip_info,
+            sizeof(IPaddr));
       proxyPort = getConfigurationString("GNUNETD",
                                         "HTTP-PROXY-PORT");
       if (proxyPort == NULL) {
@@ -1149,8 +1149,8 @@
   /* Do we need to connect through a proxy? */
   if (theProxy.sin_addr.s_addr == 0) {
     /* no proxy */
-    ip_info = GETHOSTBYNAME(hostname);
-    if (ip_info == NULL) {
+    if (OK != GN_getHostByName(hostname,
+                              &ip_info)) {
       LOG(LOG_WARNING,
          _("Could not register testbed, host `%s' unknown\n"),
          hostname);
@@ -1158,8 +1158,9 @@
       FREE(hostname);
       return;
     }
-    soaddr.sin_addr.s_addr
-      = ((struct in_addr*)(ip_info->h_addr))->s_addr;
+    memcpy(&soaddr.sin_addr.s_addr,
+          &ip_info,
+          sizeof(IPaddr));
     soaddr.sin_port
       = htons((unsigned short)port);
   } else {

Modified: GNUnet/src/include/gnunet_util.h
===================================================================
--- GNUnet/src/include/gnunet_util.h    2006-03-13 01:37:51 UTC (rev 2500)
+++ GNUnet/src/include/gnunet_util.h    2006-03-13 08:14:20 UTC (rev 2501)
@@ -1,6 +1,6 @@
 /*
      This file is part of GNUnet.
-     (C) 2001, 2002, 2003, 2004, 2005 Christian Grothoff (and other 
contributing authors)
+     (C) 2001, 2002, 2003, 2004, 2005, 2006 Christian Grothoff (and other 
contributing authors)
 
      GNUnet is free software; you can redistribute it and/or modify
      it under the terms of the GNU General Public License as published
@@ -64,7 +64,7 @@
  * especially the least significant bits may change
  * frequently, even between different SVN versions.
  */
-#define GNUNET_UTIL_VERSION 0x00070001
+#define GNUNET_UTIL_VERSION 0x00070002
 
 /**
  * We use an unsigned short in the protocol header, thus:
@@ -1236,6 +1236,13 @@
 char * GN_CTIME(const TIME_T * t);
 
 /**
+ * Get the IP address of the given host.
+ * @return OK on success, SYSERR on error
+ */
+int GN_getHostByName(const char * hostname,
+                    IPaddr * ip);
+
+/**
  * Give relative time in human-readable fancy format.
  */
 char * timeIntervalToFancyString(cron_t delta);

Modified: GNUnet/src/transports/http.c
===================================================================
--- GNUnet/src/transports/http.c        2006-03-13 01:37:51 UTC (rev 2500)
+++ GNUnet/src/transports/http.c        2006-03-13 08:14:20 UTC (rev 2501)
@@ -1433,7 +1433,7 @@
  * via a global and returns the udp transport API.
  */
 TransportAPI * inittransport_http(CoreAPIForTransport * core) {
-  struct hostent *ip;
+  IPaddr ip;
   char * proxy;
   char * proxyPort;
 
@@ -1449,14 +1449,16 @@
   proxy = getConfigurationString("GNUNETD",
                                 "HTTP-PROXY");
   if (proxy != NULL) {
-    ip = GETHOSTBYNAME(proxy);
-    if (ip == NULL) {
+    if (OK != GN_getHostByName(proxy,
+                              &ip)) {
       LOG(LOG_ERROR,
          _("Could not resolve name of HTTP proxy `%s'.\n"),
          proxy);
       theProxy.sin_addr.s_addr = 0;
     } else {
-      theProxy.sin_addr.s_addr = ((struct in_addr *)ip->h_addr)->s_addr;
+      memcpy(&theProxy.sin_addr.s_addr,
+            &ip,
+            sizeof(IPaddr));
       proxyPort = getConfigurationString("GNUNETD",
                                         "HTTP-PROXY-PORT");
       if (proxyPort == NULL) {

Modified: GNUnet/src/transports/ip.c
===================================================================
--- GNUnet/src/transports/ip.c  2006-03-13 01:37:51 UTC (rev 2500)
+++ GNUnet/src/transports/ip.c  2006-03-13 08:14:20 UTC (rev 2501)
@@ -49,7 +49,7 @@
  */
 static int getAddressFromHostname(IPaddr * identity) {
   char * hostname;
-  struct hostent * ip;
+  int ret;
 
   hostname = MALLOC(1024);
   if (0 != gethostname(hostname, 1024)) {
@@ -57,28 +57,10 @@
     LOG_STRERROR(LOG_ERROR, "gethostname");
     return SYSERR;
   }
-  /* LOG(LOG_DEBUG,
-      " looking up $HOSTNAME (%s) to obtain local IP\n",
-      hostname); */
-
-  ip = GETHOSTBYNAME(hostname);
-  if (ip == NULL) {    
-    LOG(LOG_ERROR,
-       _("Could not find IP of host `%s': %s\n"),
-       hostname, 
-       hstrerror(h_errno));
-    FREE(hostname);
-    return SYSERR;
-  }
+  ret = GN_getHostByName(hostname,
+                        identity);
   FREE(hostname);
-  if (ip->h_addrtype != AF_INET) {
-    BREAK();
-    return SYSERR;
-  }
-  memcpy(identity,
-        &((struct in_addr*)ip->h_addr_list[0])->s_addr,
-        sizeof(struct in_addr));
-  return OK;
+  return ret;
 }
 
 #if LINUX || SOMEBSD || MINGW
@@ -242,8 +224,7 @@
          _("Could not resolve `%s' to "
            "determine our IP address: %s\n"), 
          "www.example.com",
-         STRERROR(errno));
-        
+         STRERROR(errno));        
       return SYSERR;
     }
     
@@ -288,12 +269,10 @@
 static int getAddress(IPaddr  * address){
   char * ipString;
   int retval;
-  struct hostent * ip; /* for the lookup of the IP in gnunet.conf */
 
-  retval = SYSERR;
   ipString = getConfigurationString("NETWORK",
                                    "IP");
-  if (ipString == NULL || !ipString[0]) {
+  if ( (ipString == NULL) || (ipString[0] == '\0') ) {
 #if LINUX || SOMEBSD || MINGW
     if (OK == getAddressFromIOCTL(address))
       retval = OK;
@@ -301,28 +280,10 @@
 #endif
       retval = getAddressFromHostname(address);
   } else {
-    /* LOG(LOG_DEBUG,
-        "obtaining local IP address from hostname %s\n",
-       ipString); */
-    ip = GETHOSTBYNAME(ipString);
-    if (ip == NULL) {     
-      LOG(LOG_ERROR,
-         _("Could not resolve `%s': %s\n"),
-         ipString, hstrerror(h_errno));
-      retval = SYSERR;
-    } else {
-      if (ip->h_addrtype != AF_INET) {
-       BREAK();
-       retval = SYSERR;
-      } else {
-       memcpy (address,
-               &((struct in_addr*) ip->h_addr_list[0])->s_addr,
-               sizeof(struct in_addr));
-       retval = OK;
-      }
-    }
-    FREE(ipString);
+    retval = GN_getHostByName(ipString,
+                             address);
   }
+  FREENONNULL(ipString);
   return retval;
 }
 

Modified: GNUnet/src/transports/smtp.c
===================================================================
--- GNUnet/src/transports/smtp.c        2006-03-13 01:37:51 UTC (rev 2500)
+++ GNUnet/src/transports/smtp.c        2006-03-13 08:14:20 UTC (rev 2501)
@@ -283,15 +283,16 @@
   int res;
   struct sockaddr_in soaddr;
   char * hostname;
-  struct hostent * ip; /* for the lookup of the IP in gnunet.conf */
+  IPaddr ip;
   int one = 1;
 
   hostname = getConfigurationString("SMTP",
                                    "SERVER");
   if (hostname == NULL)
     hostname = STRDUP("localhost");
-  ip = GETHOSTBYNAME(hostname);
-  if (ip == NULL) {
+
+  if (OK != GN_getHostByName(hostname,
+                            &ip)) {
     LOG(LOG_ERROR,
        _("Could not resolve name of SMTP server `%s': %s"),
        hostname, hstrerror(h_errno));
@@ -307,8 +308,8 @@
   SETSOCKOPT(res, IPPROTO_TCP, TCP_NODELAY, &one, sizeof(one));
   soaddr.sin_family = AF_INET;
   memcpy(&soaddr.sin_addr,
-        &((struct in_addr*)ip->h_addr)->s_addr,
-        sizeof(struct in_addr));
+        &ip,
+        sizeof(IPaddr));
   soaddr.sin_port = htons(getSMTPPort());
   if (0 > CONNECT(res,
                  (struct sockaddr*)&soaddr,

Modified: GNUnet/src/util/configuration.c
===================================================================
--- GNUnet/src/util/configuration.c     2006-03-13 01:37:51 UTC (rev 2500)
+++ GNUnet/src/util/configuration.c     2006-03-13 08:14:20 UTC (rev 2501)
@@ -252,7 +252,7 @@
  * @return YES or NO
  */
 static int cfg_exists(const char *sec,
-                                               const char *ent)
+                     const char *ent)
 {
        struct CFG_ENTRIES *e = NULL;
        int i;
@@ -909,4 +909,37 @@
   valuesCount = count;
 }
 
+/**
+ * Get the IP address of the given host.
+ * @return OK on success, SYSERR on error
+ */
+int GN_getHostByName(const char * hostname,
+                    IPaddr * ip) {
+  struct hostent * he;
+  
+  /* slight hack: re-use config lock */
+  MUTEX_LOCK(&configLock);
+  he = GETHOSTBYNAME(hostname);
+  if (he == NULL) {    
+    LOG(LOG_ERROR,
+       _("Could not find IP of host `%s': %s\n"),
+       hostname, 
+       hstrerror(h_errno));
+    MUTEX_UNLOCK(&configLock);
+    return SYSERR;
+  }
+  if (he->h_addrtype != AF_INET) {
+    BREAK();
+    MUTEX_UNLOCK(&configLock);
+    return SYSERR;
+  }
+  memcpy(ip,
+        &((struct in_addr*)he->h_addr_list[0])->s_addr,
+        sizeof(struct in_addr));
+  MUTEX_UNLOCK(&configLock);
+  return OK;
+}
+                     
+
+
 /* end of configuration.c */

Modified: GNUnet/src/util/tcpio.c
===================================================================
--- GNUnet/src/util/tcpio.c     2006-03-13 01:37:51 UTC (rev 2500)
+++ GNUnet/src/util/tcpio.c     2006-03-13 08:14:20 UTC (rev 2501)
@@ -72,8 +72,6 @@
 int initGNUnetClientSocket(unsigned short port,
                           const char * hostname,
                           GNUNET_TCP_SOCKET * result) {
-  struct hostent * he;
-
   GNUNET_ASSERT(hostname != NULL);
 #if DEBUG_TCPIO
   LOG(LOG_DEBUG,
@@ -81,15 +79,9 @@
       hostname,
       port);
 #endif
-  he = GETHOSTBYNAME(hostname);
-  if (he == NULL) {
-    LOG(LOG_ERROR,
-       _("Could not find IP of host `%s': %s\n"),
-       hostname,
-       hstrerror(h_errno));
+  if (OK != GN_getHostByName(hostname,
+                            &result->ip)) 
     return SYSERR;
-  }
-  result->ip.addr = (unsigned int) ((struct in_addr*)he->h_addr)->s_addr;
   result->port = port;
   result->socket = -1; /* closed */
   result->outBufLen = 0;





reply via email to

[Prev in Thread] Current Thread [Next in Thread]