diff options
author | Jelmer Vernooij <jelmer@samba.org> | 2004-09-22 22:20:40 +0000 |
---|---|---|
committer | Gerald (Jerry) Carter <jerry@samba.org> | 2007-10-10 12:59:04 -0500 |
commit | 924fa2db941095719b476e3b458ced34426401bb (patch) | |
tree | 9842fdb288092a04409ca32b7b4a6e0a2c09fd6d /source4/librpc/rpc/dcerpc_tcp.c | |
parent | 814cd2bc3f25c62a8a8dbb2252524cd1e29addd2 (diff) | |
download | samba-924fa2db941095719b476e3b458ced34426401bb.tar.gz samba-924fa2db941095719b476e3b458ced34426401bb.tar.bz2 samba-924fa2db941095719b476e3b458ced34426401bb.zip |
r2538: 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.
(This used to be commit 0fb0530389751c6fb4ca58f5e9a0f23491699f17)
Diffstat (limited to 'source4/librpc/rpc/dcerpc_tcp.c')
-rw-r--r-- | source4/librpc/rpc/dcerpc_tcp.c | 42 |
1 files changed, 33 insertions, 9 deletions
diff --git a/source4/librpc/rpc/dcerpc_tcp.c b/source4/librpc/rpc/dcerpc_tcp.c index 2152c4c5d0..0edc5226a6 100644 --- a/source4/librpc/rpc/dcerpc_tcp.c +++ b/source4/librpc/rpc/dcerpc_tcp.c @@ -280,32 +280,56 @@ static const char *tcp_peer_name(struct dcerpc_pipe *p) */ 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; } |