]> git.ipfire.org Git - thirdparty/apache/httpd.git/commitdiff
APR-ize the resolver logic in mod_unique_id. This fixes a bug
authorJeff Trawick <trawick@apache.org>
Mon, 19 Nov 2001 13:48:57 +0000 (13:48 +0000)
committerJeff Trawick <trawick@apache.org>
Mon, 19 Nov 2001 13:48:57 +0000 (13:48 +0000)
in logging the error from a failed DNS lookup.

Note: For a funky error scenario to work right (huge host name),
this requires a tweak to apr_gethostname() which I have not yet
committed.

git-svn-id: https://svn.apache.org/repos/asf/httpd/httpd/trunk@92032 13f79535-47bb-0310-9956-ffa450edef68

CHANGES
STATUS
modules/metadata/mod_unique_id.c

diff --git a/CHANGES b/CHANGES
index 87259bc9a23550e1943ae0bb82eec0a2691d65b4..026557cceba47cd45a4747a06aefadd9810c5255 100644 (file)
--- a/CHANGES
+++ b/CHANGES
@@ -1,5 +1,8 @@
 Changes with Apache 2.0.29-dev
 
+  *) APR-ize the resolver logic in mod_unique_id.  This fixes a bug
+     in logging the error from a failed DNS lookup.  [Jeff Trawick]
+
   *) Added the missing macros AP_INIT_TAKE13 and AP_INIT_TAKE123.
      [Cliff Woolley]
 
diff --git a/STATUS b/STATUS
index a9670ff402bc3de3a706cf405545be6c04f94cf6..a0860fe01d5eafcaf4f4016632a2824dc1abb883 100644 (file)
--- a/STATUS
+++ b/STATUS
@@ -1,5 +1,5 @@
 APACHE 2.0 STATUS:                                             -*-text-*-
-Last modified at [$Date: 2001/11/17 14:02:25 $]
+Last modified at [$Date: 2001/11/19 13:48:57 $]
 
 Release:
 
@@ -292,8 +292,6 @@ RELEASE NON-SHOWSTOPPERS BUT WOULD BE REAL NICE TO WRAP THESE UP:
 
     * shift stuff to mod_core.h
 
-    * APR-ize resolver stuff in mod_unique_id (Jeff volunteers)
-
     * callers of ap_run_create_request() should check the return value
       for failure (Doug volunteers)
 
index bc33cb32cd892ecb234616857c458b544f492555..8fbbde8878d1d1973680f9f45fb7279bd6977d28 100644 (file)
  */
 
 #include "apr_general.h"    /* for APR_XtOffsetOf                */
+#include "apr_network_io.h"
 
 #include "httpd.h"
 #include "http_config.h"
 #include "http_log.h"
 #include "http_protocol.h"  /* for ap_hook_post_read_request */
 
-#if APR_HAVE_NETDB_H
-#include <netdb.h>
-#endif
-#if APR_HAVE_ARPA_INET_H
-#include <arpa/inet.h>
-#endif
 #if APR_HAVE_UNISTD_H
-#include <unistd.h>
+#include <unistd.h>         /* for getpid() */
 #endif
 
 typedef struct {
@@ -177,12 +172,11 @@ static unsigned short unique_id_rec_offset[UNIQUE_ID_REC_MAX],
 
 static void unique_id_global_init(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *ptemp, server_rec *main_server)
 {
-#ifndef MAXHOSTNAMELEN
-#define MAXHOSTNAMELEN 256
-#endif
-    char str[MAXHOSTNAMELEN + 1];
-    struct hostent *hent;
+    char str[APRMAXHOSTLEN + 1];
     apr_short_interval_time_t pause;
+    apr_status_t rv;
+    char *ipaddrstr;
+    apr_sockaddr_t *sockaddr;
 
     /*
      * Calculate the sizes and offsets in cur_unique_id.
@@ -211,24 +205,27 @@ static void unique_id_global_init(apr_pool_t *p, apr_pool_t *plog, apr_pool_t *p
      * of the addresses from the main_server, since those aren't as likely to
      * be unique as the physical address of the machine
      */
-    if (gethostname(str, sizeof(str) - 1) != 0) {
-        ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ALERT, errno, main_server,
-          "gethostname: mod_unique_id requires the hostname of the server");
+    if ((rv = apr_gethostname(str, sizeof(str) - 1, p)) != APR_SUCCESS) {
+        ap_log_error(APLOG_MARK, APLOG_ALERT, rv, main_server,
+          "mod_unique_id: unable to find hostname of the server");
         exit(1);
     }
-    str[sizeof(str) - 1] = '\0';
 
-    if ((hent = gethostbyname(str)) == NULL) {
-        ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_ALERT, h_errno, main_server,
-                    "mod_unique_id: unable to gethostbyname(\"%s\")", str);
+    /* XXX theoretically there are boxes out there which want to use
+     *     mod_unique_id but which have no IPv4 address...  send in a patch :)
+     */
+    if ((rv = apr_sockaddr_info_get(&sockaddr, str, AF_INET, 0, 0, p)) != APR_SUCCESS) {
+        ap_log_error(APLOG_MARK, APLOG_ALERT, rv, main_server,
+                    "mod_unique_id: unable to find IPv4 address of \"%s\"", str);
         exit(1);
     }
 
-    global_in_addr = ((struct in_addr *) hent->h_addr_list[0])->s_addr;
+    global_in_addr = sockaddr->sa.sin.sin_addr.s_addr;
 
+    apr_sockaddr_ip_get(&ipaddrstr, sockaddr);
     ap_log_error(APLOG_MARK, APLOG_NOERRNO|APLOG_INFO, 0, main_server,
                 "mod_unique_id: using ip addr %s",
-                inet_ntoa(*(struct in_addr *) hent->h_addr_list[0]));
+                 ipaddrstr);
 
     /*
      * If the server is pummelled with restart requests we could possibly end