svn commit: samba r2538 - in branches/SAMBA_4_0/source/librpc/rpc: .

jelmer at samba.org jelmer at samba.org
Wed Sep 22 22:20:41 GMT 2004


Author: jelmer
Date: 2004-09-22 22:20:40 +0000 (Wed, 22 Sep 2004)
New Revision: 2538

WebSVN: http://websvn.samba.org/websvn/changeset.php?rep=samba&path=/branches/SAMBA_4_0/source/librpc/rpc&rev=2538&nolog=1

Log:
Support IPv6 as transport for MSRPC. Tested against Win2k3
Implemented using the POSIX getaddrinfo() call (specified by POSIX 1003.1-2003 and 2553)
I'm not sure how portable this function is, so we might have to add a sys_getaddrinfo() later on.

Modified:
   branches/SAMBA_4_0/source/librpc/rpc/dcerpc_tcp.c
   branches/SAMBA_4_0/source/librpc/rpc/dcerpc_util.c


Changeset:
Modified: branches/SAMBA_4_0/source/librpc/rpc/dcerpc_tcp.c
===================================================================
--- branches/SAMBA_4_0/source/librpc/rpc/dcerpc_tcp.c	2004-09-22 22:10:43 UTC (rev 2537)
+++ branches/SAMBA_4_0/source/librpc/rpc/dcerpc_tcp.c	2004-09-22 22:20:40 UTC (rev 2538)
@@ -280,32 +280,56 @@
 */
 NTSTATUS dcerpc_pipe_open_tcp(struct dcerpc_pipe **p, 
 			      const char *server,
-			      uint32_t port)
+			      uint32_t port, 
+				  int family)
 {
 	struct tcp_private *tcp;
-	int fd;
-	struct in_addr addr;
+	int fd, gai_error;
 	struct fd_event fde;
+	struct addrinfo hints, *res, *tmpres;
+	char portname[16];
 
 	if (port == 0) {
 		port = EPMAPPER_PORT;
 	}
 
-	addr.s_addr = interpret_addr(server);
-	if (addr.s_addr == 0) {
+	memset(&hints, 0, sizeof(struct addrinfo));
+
+	hints.ai_family = family;
+	hints.ai_socktype = SOCK_STREAM;
+
+	snprintf(portname, sizeof(portname)-1, "%d", port);
+	
+	gai_error = getaddrinfo(server, portname, &hints, &res);
+	if (gai_error < 0) 
+	{
+		DEBUG(0, ("Unable to connect to %s:%d : %s\n", server, port, gai_strerror(gai_error)));
 		return NT_STATUS_BAD_NETWORK_NAME;
 	}
 
-	fd = open_socket_out(SOCK_STREAM, &addr, port, 30000);
+	tmpres = res;
+	
+	while (tmpres) {
+		fd = socket(tmpres->ai_family, tmpres->ai_socktype, tmpres->ai_protocol);
+
+		if(fd >= 0) {
+			if (connect(fd, tmpres->ai_addr, tmpres->ai_addrlen) == 0)	
+				break; 
+			fd = -1;
+		}
+
+		tmpres = tmpres->ai_next;
+	}
+
+	freeaddrinfo(res);
+	
 	if (fd == -1) {
 		return NT_STATUS_PORT_CONNECTION_REFUSED;
 	}
 
 	set_socket_options(fd, lp_socket_options());
 
-	set_blocking(fd, False);
-
-        if (!(*p = dcerpc_pipe_init())) {
+    if (!(*p = dcerpc_pipe_init())) {
                 return NT_STATUS_NO_MEMORY;
 	}
  

Modified: branches/SAMBA_4_0/source/librpc/rpc/dcerpc_util.c
===================================================================
--- branches/SAMBA_4_0/source/librpc/rpc/dcerpc_util.c	2004-09-22 22:10:43 UTC (rev 2537)
+++ branches/SAMBA_4_0/source/librpc/rpc/dcerpc_util.c	2004-09-22 22:20:40 UTC (rev 2538)
@@ -69,7 +69,7 @@
 		return NT_STATUS_OK;
 	}
 
-	status = dcerpc_pipe_open_tcp(&p, server, EPMAPPER_PORT);
+	status = dcerpc_pipe_open_tcp(&p, server, EPMAPPER_PORT, AF_UNSPEC );
 	if (!NT_STATUS_IS_OK(status)) {
 		return status;
 	}
@@ -542,7 +542,7 @@
 		DEBUG(1,("Mapped to DCERPC/TCP port %u\n", port));
 	}
 
-	status = dcerpc_pipe_open_tcp(p, binding->host, port);
+	status = dcerpc_pipe_open_tcp(p, binding->host, port, AF_UNSPEC);
 	if (!NT_STATUS_IS_OK(status)) {
 		DEBUG(0,("Failed to connect to %s:%d\n", binding->host, port));
                 return status;



More information about the samba-cvs mailing list