diff options
-rw-r--r-- | ChangeLog | 8 | ||||
-rw-r--r-- | unix/tclUnixSock.c | 38 | ||||
-rw-r--r-- | win/tclWinSock.c | 10 |
3 files changed, 32 insertions, 24 deletions
@@ -1,3 +1,11 @@ +2010-12-14 Reinhard Max <max@suse.de> + + * win/tclWinSock.c (CreateSocket): Swap the loops over + * unix/tclUnixSock.c (CreateClientSocket): local and remote + addresses, so that the system's address preference for the remote + side decides which family gets tried first. Cleanup and clarify + some of the comments. + 2010-12-13 Jan Nijtmans <nijtmans@users.sf.net> * generic/tcl.h: [Bug 3135271] Link error due to hidden diff --git a/unix/tclUnixSock.c b/unix/tclUnixSock.c index 9e86a6a..f567447 100644 --- a/unix/tclUnixSock.c +++ b/unix/tclUnixSock.c @@ -8,7 +8,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclUnixSock.c,v 1.32 2010/12/10 15:44:54 nijtmans Exp $ + * RCS: @(#) $Id: tclUnixSock.c,v 1.33 2010/12/14 17:22:55 rmax Exp $ */ #include "tclInt.h" @@ -862,9 +862,9 @@ static TcpState * CreateClientSocket( Tcl_Interp *interp, /* For error reporting; can be NULL. */ int port, /* Port number to open. */ - const char *host, /* Name of host on which to open port. NULL - * implies INADDR_ANY */ - const char *myaddr, /* Optional client-side address */ + const char *host, /* Name of host on which to open port. */ + const char *myaddr, /* Optional client-side address. + * NULL implies INADDR_ANY/in6addr_any */ int myport, /* Optional client-side port */ int async) /* If nonzero and creating a client socket, * attempt to do an async connect. Otherwise @@ -885,12 +885,12 @@ CreateClientSocket( goto error; } - for (myaddrPtr = myaddrlist; myaddrPtr != NULL; - myaddrPtr = myaddrPtr->ai_next) { - for (addrPtr = addrlist; addrPtr != NULL; - addrPtr = addrPtr->ai_next) { + for (addrPtr = addrlist; addrPtr != NULL; + addrPtr = addrPtr->ai_next) { + for (myaddrPtr = myaddrlist; myaddrPtr != NULL; + myaddrPtr = myaddrPtr->ai_next) { int reuseaddr; - + /* * No need to try combinations of local and remote addresses of * different families. @@ -900,14 +900,7 @@ CreateClientSocket( continue; } - /* - * Attempt to connect. The connect may fail at present with an - * EINPROGRESS but at a later time it will complete. The caller - * will set up a file handler on the socket if she is interested - * in being informed when the connect completes. - */ - - sock = socket(myaddrPtr->ai_family, SOCK_STREAM, 0); + sock = socket(addrPtr->ai_family, SOCK_STREAM, 0); if (sock < 0) { continue; } @@ -940,6 +933,13 @@ CreateClientSocket( goto looperror; } + /* + * Attempt to connect. The connect may fail at present with an + * EINPROGRESS but at a later time it will complete. The caller + * will set up a file handler on the socket if she is interested + * in being informed when the connect completes. + */ + status = connect(sock, addrPtr->ai_addr, addrPtr->ai_addrlen); if (status < 0 && errno == EINPROGRESS) { status = 0; @@ -1196,8 +1196,8 @@ Tcl_OpenTcpServer( (char *) &reuseaddr, sizeof(reuseaddr)); /* - * Make sure we use the same port when opening two server sockets for - * IPv4 and IPv6. + * Make sure we use the same port number when opening two server + * sockets for IPv4 and IPv6 on a random port. * * As sockaddr_in6 uses the same offset and size for the port member * as sockaddr_in, we can handle both through the IPv4 API. diff --git a/win/tclWinSock.c b/win/tclWinSock.c index 5407b47..c7df204 100644 --- a/win/tclWinSock.c +++ b/win/tclWinSock.c @@ -8,7 +8,7 @@ * See the file "license.terms" for information on usage and redistribution of * this file, and for a DISCLAIMER OF ALL WARRANTIES. * - * RCS: @(#) $Id: tclWinSock.c,v 1.80 2010/12/10 15:44:53 nijtmans Exp $ + * RCS: @(#) $Id: tclWinSock.c,v 1.81 2010/12/14 17:22:55 rmax Exp $ * * ----------------------------------------------------------------------- * @@ -1142,10 +1142,10 @@ CreateSocket( } } } else { - for (myaddrPtr = myaddrlist; myaddrPtr != NULL; - myaddrPtr = myaddrPtr->ai_next) { - for (addrPtr = addrlist; addrPtr != NULL; - addrPtr = addrPtr->ai_next) { + for (addrPtr = addrlist; addrPtr != NULL; + addrPtr = addrPtr->ai_next) { + for (myaddrPtr = myaddrlist; myaddrPtr != NULL; + myaddrPtr = myaddrPtr->ai_next) { /* * No need to try combinations of local and remote addresses * of different families. |