1
0
mirror of https://github.com/samba-team/samba.git synced 2024-12-27 03:21:53 +03:00

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 commit is contained in:
Jelmer Vernooij 2004-09-22 22:20:40 +00:00 committed by Gerald (Jerry) Carter
parent f3bf57ca6b
commit 0fb0530389
2 changed files with 35 additions and 11 deletions

View File

@ -280,31 +280,55 @@ static const char *tcp_peer_name(struct dcerpc_pipe *p)
*/ */
NTSTATUS dcerpc_pipe_open_tcp(struct dcerpc_pipe **p, NTSTATUS dcerpc_pipe_open_tcp(struct dcerpc_pipe **p,
const char *server, const char *server,
uint32_t port) uint32_t port,
int family)
{ {
struct tcp_private *tcp; struct tcp_private *tcp;
int fd; int fd, gai_error;
struct in_addr addr;
struct fd_event fde; struct fd_event fde;
struct addrinfo hints, *res, *tmpres;
char portname[16];
if (port == 0) { if (port == 0) {
port = EPMAPPER_PORT; port = EPMAPPER_PORT;
} }
addr.s_addr = interpret_addr(server); memset(&hints, 0, sizeof(struct addrinfo));
if (addr.s_addr == 0) {
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; 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) { if (fd == -1) {
return NT_STATUS_PORT_CONNECTION_REFUSED; return NT_STATUS_PORT_CONNECTION_REFUSED;
} }
set_socket_options(fd, lp_socket_options()); 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; return NT_STATUS_NO_MEMORY;
} }

View File

@ -69,7 +69,7 @@ NTSTATUS dcerpc_epm_map_tcp_port(const char *server,
return NT_STATUS_OK; 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)) { if (!NT_STATUS_IS_OK(status)) {
return status; return status;
} }
@ -542,7 +542,7 @@ static NTSTATUS dcerpc_pipe_connect_ncacn_ip_tcp(struct dcerpc_pipe **p,
DEBUG(1,("Mapped to DCERPC/TCP port %u\n", port)); 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)) { if (!NT_STATUS_IS_OK(status)) {
DEBUG(0,("Failed to connect to %s:%d\n", binding->host, port)); DEBUG(0,("Failed to connect to %s:%d\n", binding->host, port));
return status; return status;