--- samba-3.5.0rc2/lib/tsocket/tsocket.c	2010-01-26 15:05:01.000000000 +0100
+++ samba-3.5.0rc2.patch/lib/tsocket/tsocket.c	2010-02-16 15:57:25.972699888 +0100
@@ -81,6 +81,16 @@
 	return addr;
 }
 
+/* getting addr_family typ */
+int tsocket_get_addr_family(const struct tsocket_address *addr)
+{
+	if (addr)
+	{
+		return tsocket_get_addr_family_bsd(addr);
+	}
+	return NULL;
+}
+
 char *tsocket_address_string(const struct tsocket_address *addr,
 			     TALLOC_CTX *mem_ctx)
 {
--- samba-3.5.0rc2/lib/tsocket/tsocket.h	2010-01-26 15:05:01.000000000 +0100
+++ samba-3.5.0rc2.patch/lib/tsocket/tsocket.h	2010-02-16 15:25:31.503229000 +0100
@@ -243,5 +243,7 @@
 					     size_t count);
 int tstream_writev_queue_recv(struct tevent_req *req, int *perrno);
 
+int tsocket_get_addr_family(const struct tsocket_address *addr);
+
 #endif /* _TSOCKET_H */
 
--- samba-3.5.0rc2/lib/tsocket/tsocket_internal.h	2010-01-26 15:05:01.000000000 +0100
+++ samba-3.5.0rc2.patch/lib/tsocket/tsocket_internal.h	2010-02-16 15:26:07.206346000 +0100
@@ -140,5 +140,7 @@
 
 int tsocket_simple_int_recv(struct tevent_req *req, int *perrno);
 
+int tsocket_get_addr_family_bsd(const struct tsocket_address *addr);
+
 #endif /* _TSOCKET_H */
 
--- samba-3.5.0rc2/lib/tsocket/tsocket_bsd.c	2010-01-26 15:05:01.000000000 +0100
+++ samba-3.5.0rc2.patch/lib/tsocket/tsocket_bsd.c	2010-02-16 15:26:29.769242000 +0100
@@ -201,6 +201,18 @@
 	} u;
 };
 
+/* getting the addess-family or NULL */
+int tsocket_get_addr_family_bsd(const struct tsocket_address *addr)
+{
+	struct tsocket_address_bsd *bsda = talloc_get_type_abort(addr->private_data,
+                        				        struct tsocket_address_bsd);
+	if (bsda) 
+	{
+		return bsda->u.sa.sa_family;
+	}
+	return NULL;
+}
+
 int _tsocket_address_bsd_from_sockaddr(TALLOC_CTX *mem_ctx,
 				       struct sockaddr *sa,
 				       size_t sa_socklen,
@@ -1136,11 +1148,15 @@
 	int ret;
 	bool do_bind = false;
 	bool do_reuseaddr = false;
-	socklen_t sa_socklen = sizeof(lbsda->u.ss);
+	/* setting size of socket - not of u.ss */
+	socklen_t sa_socklen = sizeof(lbsda->u.sa);
+	socklen_t sa_socklen_rbsda = 0;
 
 	if (remote) {
 		rbsda = talloc_get_type_abort(remote->private_data,
 			struct tsocket_address_bsd);
+		/* settig size of remote socketaddr */
+		sa_socklen_rbsda = sizeof(rbsda->u.sa);
 	}
 
 	switch (lbsda->u.sa.sa_family) {
@@ -1248,7 +1264,7 @@
 	}
 
 	if (rbsda) {
-		ret = connect(fd, &rbsda->u.sa, sa_socklen);
+		ret = connect(fd, &rbsda->u.sa, sa_socklen_rbsda);
 		if (ret == -1) {
 			int saved_errno = errno;
 			talloc_free(dgram);
--- samba-3.5.0rc2/libcli/cldap/cldap.c	2010-01-26 15:05:01.000000000 +0100
+++ samba-3.5.0rc2.patch/libcli/cldap/cldap.c	2010-02-16 15:25:02.055516000 +0100
@@ -320,9 +320,34 @@
 	c->event.ctx = ev;
 
 	if (!local_addr) {
+
+/* 
+  if HAVE_IPV6 is defined we have to prove if we have *remote_addr and 
+  if it is from type IPv4 or IPv6. I know ther must be a better implementation :-)
+*/
+#ifdef HAVE_IPV6
+		if (remote_addr) {
+			if(tsocket_get_addr_family(remote_addr) == AF_INET) {
+				ret = tsocket_address_inet_from_strings(c, "ipv4",
+									NULL, 0,
+									&any);
+			}
+			else {
+				ret = tsocket_address_inet_from_strings(c, "ip",
+									NULL, 0,
+									&any);
+			}
+		}
+		else {
+			ret = tsocket_address_inet_from_strings(c, "ip",
+								NULL, 0,
+								&any);
+		}
+#else
 		ret = tsocket_address_inet_from_strings(c, "ip",
 							NULL, 0,
 							&any);
+#endif
 		if (ret != 0) {
 			status = map_nt_error_from_unix(errno);
 			goto nterror;
