simpleproxy (3.4-5) fix_mdns_use.dpatch

Summary

 simpleproxy.c |   13 +++++++++++--
 1 file changed, 11 insertions(+), 2 deletions(-)

    
download this patch

Patch contents

#! /bin/sh /usr/share/dpatch/dpatch-run
## fix_mdns_use.dpatch by  <apollock@debian.org>
##
## All lines beginning with `## DP:' are a description of the patch.
## DP: Switches from gethostbyaddr() to getnameinfo() to fix performance 
## DP: issues when using nss_mdns
## DP: See http://bugs.debian.org/508148

@DPATCH@
diff -urNad simpleproxy-3.4~/simpleproxy.c simpleproxy-3.4/simpleproxy.c
--- simpleproxy-3.4~/simpleproxy.c	2005-08-25 21:45:46.000000000 -0700
+++ simpleproxy-3.4/simpleproxy.c	2008-12-08 23:30:27.000000000 -0800
@@ -78,6 +78,9 @@
 #include <arpa/inet.h>
 #include <ctype.h>
 
+#include <sys/socket.h>
+#include <netdb.h>
+
 #include "cfg.h"
 
 #ifndef nil
@@ -166,6 +169,9 @@
     int    rsp = 1;
     char  *http_auth = nil;
     char  *HTTPAuthHash = nil;
+    struct sockaddr *sa;
+    int    len;
+    char   hbuf[NI_MAXHOST];
 
     /* Check for the arguments, and overwrite values from cfg file */
     while((c = getopt(ac, av, "iVv7dhL:R:H:f:p:P:D:S:s:a:t:")) != -1)
@@ -394,8 +400,11 @@
                 break;
                 
             case 0: /* Child */
-                hp = gethostbyaddr((char *)&cli_addr, clien, AF_INET);
-                client_name = strdup(hp?(hp->h_name): inet_ntoa(cli_addr.sin_addr));
+		if (getnameinfo((const struct sockaddr *) &cli_addr, len,
+					hbuf, sizeof(hbuf), NULL, 0, 0) == 0)
+			client_name = strdup(hbuf);
+		else
+			client_name = inet_ntoa(cli_addr.sin_addr);
 
                 /*
                  * I don't know is that a bug, but on Irix 6.2 parent