Description: deals with ipv4 addresses (usually converted by xinetd)
 .
 weborf (0.13-2) unstable; urgency=low
 .
   * Backport fix from upstream: qweborf doesn't crash when miredo is in use
Author: Salvo 'LtWorf' Tomaselli <tiposchi@tiscali.it>
Bug-Debian: http://bugs.debian.org/601253

---
The information above should follow the Patch Tagging Guidelines, please
checkout http://dep.debian.net/deps/dep3/ to learn about the format. Here
are templates for supplementary fields that you might want to add:

Origin: <vendor|upstream|other>, <url of original patch>
Bug: <url in upstream bugtracker>
Bug-Ubuntu: https://launchpad.net/bugs/<bugnumber>
Forwarded: <no|not-needed|url proving that it has been forwarded>
Reviewed-By: <name and email of someone who approved the patch>
Last-Update: <YYYY-MM-DD>

--- weborf-0.13.orig/instance.c
+++ weborf-0.13/instance.c
@@ -297,15 +297,7 @@ void * instance(void * nulla) {
         }
 
         connection_prop.sock=sock;//Assigned socket into the struct
-
-        //Converting address to string
-#ifdef IPV6
-        getpeername(sock, (struct sockaddr *)&addr, &addr_l);
-        inet_ntop(AF_INET6, &addr.sin6_addr, connection_prop.ip_addr, INET6_ADDRSTRLEN);
-#else
-        getpeername(sock, (struct sockaddr *)&addr,(socklen_t *) &addr_l);
-        inet_ntop(AF_INET, &addr.sin_addr, connection_prop.ip_addr, INET_ADDRSTRLEN);
-#endif
+        net_getpeername(sock,connection_prop.ip_addr);
 
 #ifdef THREADDBG
         syslog(LOG_DEBUG,"Thread %ld: Reading from socket",thread_prop.id);
@@ -1274,14 +1266,7 @@ void inetd() {
         goto release_resources;
     }
 
-    //Converting address to string
-#ifdef IPV6
-    getpeername(sock, (struct sockaddr *)&addr, &addr_l);
-    inet_ntop(AF_INET6, &addr.sin6_addr, connection_prop.ip_addr, INET6_ADDRSTRLEN);
-#else
-    getpeername(sock, (struct sockaddr *)&addr,(socklen_t *) &addr_l);
-    inet_ntop(AF_INET, &addr.sin_addr, connection_prop.ip_addr, INET_ADDRSTRLEN);
-#endif
+    net_getpeername(sock,connection_prop.ip_addr);
 
     handle_requests(buf,&read_b,&bufFull,&connection_prop,thread_prop.id);
     //close(sock);//Closing the socket
--- weborf-0.13.orig/mynet.c
+++ weborf-0.13/mynet.c
@@ -154,3 +154,31 @@ void net_bind_and_listen(int s) {
     listen(s, MAXQ); //Listen to the socket
 
 }
+
+
+void net_getpeername(int socket,char* buffer) {
+
+#ifdef IPV6
+
+    struct sockaddr_storage t_addr;
+    socklen_t addr_l=sizeof(t_addr);
+    
+    getpeername(socket, (struct sockaddr *)&t_addr, &addr_l);
+    
+    if (t_addr.ss_family==AF_INET) {
+        struct sockaddr_in *addr =(struct sockaddr_in *)&t_addr;
+        char temp_buffer[INET_ADDRSTRLEN];
+        inet_ntop(AF_INET, &(addr->sin_addr), temp_buffer, INET_ADDRSTRLEN);
+        snprintf(buffer,INET6_ADDRSTRLEN,"::ffff:%s",temp_buffer);
+    } else {
+        struct sockaddr_in6 *addr =(struct sockaddr_in6 *)&t_addr;
+        inet_ntop(AF_INET6, &(addr->sin6_addr), buffer, INET6_ADDRSTRLEN);
+    }
+#else
+    struct sockaddr_in addr;
+    socklen_t addr_l=sizeof(struct sockaddr_in);
+
+    getpeername(socket, (struct sockaddr *)&addr,&addr_l);
+    inet_ntop(AF_INET, &addr.sin_addr, buffer, INET_ADDRSTRLEN);
+#endif
+}
--- weborf-0.13.orig/mynet.h
+++ weborf-0.13/mynet.h
@@ -26,5 +26,6 @@ along with this program.  If not, see <h
 
 int net_create_server_socket();
 void net_bind_and_listen(int s);
+void net_getpeername(int,char*);
 
-#endif
\ No newline at end of file
+#endif
