Fix %I macro expansion for IPv4 mapped IPv6 addresses.
authorMichael Adam <obnox@samba.org>
Thu, 13 Mar 2008 22:02:58 +0000 (23:02 +0100)
committerMichael Adam <obnox@samba.org>
Thu, 13 Mar 2008 22:08:25 +0000 (23:08 +0100)
On some systems (linux e.g.), when listening on ipv6 and ipv4,
addresses of ipv4 clients are printed as mapped ipv4 addresses
by getnameinfo (e.g. ::ffff:127.0.0.1). This re-establishes
the original behaviour of %I to expand to the plain ipv4 address
for an ipv4 client.

Michael
(This used to be commit 0abc8863f87fe5d2473492797c010784cb086008)

source3/lib/substitute.c

index 59b54c4dff00b06875ebfef8cad2e56a5987746f..ce97a36188766b027f4a21d1e8572c55c47afaf9 100644 (file)
@@ -597,10 +597,16 @@ char *alloc_sub_basic(const char *smb_name, const char *domain_name,
                        }
                        a_string = realloc_string_sub(a_string, "%D", r);
                        break;
-               case 'I' :
+               case 'I' : {
+                       int offset = 0;
+                       client_addr(get_client_fd(), addr, sizeof(addr));
+                       if (strnequal(addr,"::ffff:",7)) {
+                               offset = 7;
+                       }
                        a_string = realloc_string_sub(a_string, "%I",
-                                       client_addr(get_client_fd(),addr, sizeof(addr)));
+                                                     addr + offset);
                        break;
+               }
                case 'i': 
                        a_string = realloc_string_sub( a_string, "%i",
                                        client_socket_addr(get_client_fd(), addr, sizeof(addr)) );