summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorjan.nijtmans <nijtmans@users.sourceforge.net>2017-01-10 13:56:10 (GMT)
committerjan.nijtmans <nijtmans@users.sourceforge.net>2017-01-10 13:56:10 (GMT)
commit087ee7ed0d134cda28132343b258eee2afc60261 (patch)
tree1061d9a2d7d65b1c23cfa06188dc5fd2e6a3c5be
parentfc84850b75bc0741998145b52bbe2269c2d76e8d (diff)
downloadtcl-087ee7ed0d134cda28132343b258eee2afc60261.zip
tcl-087ee7ed0d134cda28132343b258eee2afc60261.tar.gz
tcl-087ee7ed0d134cda28132343b258eee2afc60261.tar.bz2
Experimental follow-up: Change internal TclCreateSocketAddress() signature, from using "int port" to "const char *service".
-rw-r--r--generic/tclIOSock.c13
-rw-r--r--generic/tclInt.h2
-rw-r--r--unix/tclUnixSock.c10
-rw-r--r--win/tclWinSock.c11
4 files changed, 21 insertions, 15 deletions
diff --git a/generic/tclIOSock.c b/generic/tclIOSock.c
index 8ad268a..b4a3df4 100644
--- a/generic/tclIOSock.c
+++ b/generic/tclIOSock.c
@@ -158,7 +158,7 @@ TclCreateSocketAddress(
* family */
struct addrinfo **addrlist, /* Socket address list */
const char *host, /* Host. NULL implies INADDR_ANY */
- int port, /* Port number */
+ const char *service, /* Service */
int willBind, /* Is this an address to bind() to or to
* connect() to? */
const char **errorMsgPtr) /* Place to store the error message detail, if
@@ -168,7 +168,7 @@ TclCreateSocketAddress(
struct addrinfo *p;
struct addrinfo *v4head = NULL, *v4ptr = NULL;
struct addrinfo *v6head = NULL, *v6ptr = NULL;
- char *native = NULL, portbuf[TCL_INTEGER_SPACE], *portstring;
+ char *native = NULL;
const char *family = NULL;
Tcl_DString ds;
int result;
@@ -182,11 +182,8 @@ TclCreateSocketAddress(
* when the loopback device is the only available network interface.
*/
- if (host != NULL && port == 0) {
- portstring = NULL;
- } else {
- TclFormatInt(portbuf, port);
- portstring = portbuf;
+ if (host != NULL && service != NULL && !strcmp(service, "0")) {
+ service = NULL;
}
(void) memset(&hints, 0, sizeof(hints));
@@ -231,7 +228,7 @@ TclCreateSocketAddress(
hints.ai_flags |= AI_PASSIVE;
}
- result = getaddrinfo(native, portstring, &hints, addrlist);
+ result = getaddrinfo(native, service, &hints, addrlist);
if (host != NULL) {
Tcl_DStringFree(&ds);
diff --git a/generic/tclInt.h b/generic/tclInt.h
index dd0c11a..5faa275 100644
--- a/generic/tclInt.h
+++ b/generic/tclInt.h
@@ -3068,7 +3068,7 @@ MODULE_SCOPE void TclpFinalizePipes(void);
MODULE_SCOPE void TclpFinalizeSockets(void);
MODULE_SCOPE int TclCreateSocketAddress(Tcl_Interp *interp,
struct addrinfo **addrlist,
- const char *host, int port, int willBind,
+ const char *host, const char *service, int willBind,
const char **errorMsgPtr);
MODULE_SCOPE int TclpThreadCreate(Tcl_ThreadId *idPtr,
Tcl_ThreadCreateProc *proc, ClientData clientData,
diff --git a/unix/tclUnixSock.c b/unix/tclUnixSock.c
index 8e97543..63bccae 100644
--- a/unix/tclUnixSock.c
+++ b/unix/tclUnixSock.c
@@ -1287,13 +1287,17 @@ Tcl_OpenTcpClient(
const char *errorMsg = NULL;
struct addrinfo *addrlist = NULL, *myaddrlist = NULL;
char channelName[SOCK_CHAN_LENGTH];
+ char service[TCL_INTEGER_SPACE], myservice[TCL_INTEGER_SPACE];
/*
* Do the name lookups for the local and remote addresses.
*/
- if (!TclCreateSocketAddress(interp, &addrlist, host, port, 0, &errorMsg)
- || !TclCreateSocketAddress(interp, &myaddrlist, myaddr, myport, 1,
+ TclFormatInt(service, port);
+ TclFormatInt(myservice, myport);
+
+ if (!TclCreateSocketAddress(interp, &addrlist, host, service, 0, &errorMsg)
+ || !TclCreateSocketAddress(interp, &myaddrlist, myaddr, myservice, 1,
&errorMsg)) {
if (addrlist != NULL) {
freeaddrinfo(addrlist);
@@ -1481,7 +1485,7 @@ Tcl_OpenTcpServerEx(
goto error;
}
- if (!TclCreateSocketAddress(interp, &addrlist, myHost, port, 1, &errorMsg)) {
+ if (!TclCreateSocketAddress(interp, &addrlist, myHost, service, 1, &errorMsg)) {
my_errno = errno;
goto error;
}
diff --git a/win/tclWinSock.c b/win/tclWinSock.c
index 5e0d7c8..b2d77a1 100644
--- a/win/tclWinSock.c
+++ b/win/tclWinSock.c
@@ -1902,6 +1902,11 @@ Tcl_OpenTcpClient(
const char *errorMsg = NULL;
struct addrinfo *addrlist = NULL, *myaddrlist = NULL;
char channelName[SOCK_CHAN_LENGTH];
+ char service[TCL_INTEGER_SPACE], myservice[TCL_INTEGER_SPACE];
+
+ TclFormatInt(service, port);
+ TclFormatInt(myservice, myport);
+
if (TclpHasSockets(interp) != TCL_OK) {
return NULL;
@@ -1921,8 +1926,8 @@ Tcl_OpenTcpClient(
* Do the name lookups for the local and remote addresses.
*/
- if (!TclCreateSocketAddress(interp, &addrlist, host, port, 0, &errorMsg)
- || !TclCreateSocketAddress(interp, &myaddrlist, myaddr, myport, 1,
+ if (!TclCreateSocketAddress(interp, &addrlist, host, service, 0, &errorMsg)
+ || !TclCreateSocketAddress(interp, &myaddrlist, myaddr, myservice, 1,
&errorMsg)) {
if (addrlist != NULL) {
freeaddrinfo(addrlist);
@@ -2078,7 +2083,7 @@ Tcl_OpenTcpServerEx(
goto error;
}
- if (!TclCreateSocketAddress(interp, &addrlist, myHost, port, 1, &errorMsg)) {
+ if (!TclCreateSocketAddress(interp, &addrlist, myHost, service, 1, &errorMsg)) {
goto error;
}