summaryrefslogtreecommitdiffstats
path: root/unix
diff options
context:
space:
mode:
authorlimeboy <that.lemon+tcl@gmai.com>2016-12-14 15:49:27 (GMT)
committerlimeboy <that.lemon+tcl@gmai.com>2016-12-14 15:49:27 (GMT)
commitfdc5267c5f6488e6f8065453fc078e0ebc45d861 (patch)
tree252d57e9f2c63147b2b616e30c2c54e1fe47a086 /unix
parentbba3b008ba9e94fbe9a9ffce00aaf90077136fca (diff)
downloadtcl-fdc5267c5f6488e6f8065453fc078e0ebc45d861.zip
tcl-fdc5267c5f6488e6f8065453fc078e0ebc45d861.tar.gz
tcl-fdc5267c5f6488e6f8065453fc078e0ebc45d861.tar.bz2
Make OpenTcpServerEx accept a 'service' string parameter instead of a port.
Diffstat (limited to 'unix')
-rw-r--r--unix/tclUnixSock.c9
1 files changed, 7 insertions, 2 deletions
diff --git a/unix/tclUnixSock.c b/unix/tclUnixSock.c
index 187c157..8e97543 100644
--- a/unix/tclUnixSock.c
+++ b/unix/tclUnixSock.c
@@ -1422,7 +1422,7 @@ TclpMakeTcpClientChannelMode(
Tcl_Channel
Tcl_OpenTcpServerEx(
Tcl_Interp *interp, /* For error reporting - may be NULL. */
- int port, /* Port number to open. */
+ const char *service, /* Port number to open. */
const char *myHost, /* Name of local host. */
unsigned int flags, /* Flags. */
Tcl_TcpAcceptProc *acceptProc,
@@ -1430,7 +1430,7 @@ Tcl_OpenTcpServerEx(
* clients. */
ClientData acceptProcData) /* Data for the callback. */
{
- int status = 0, sock = -1, optvalue, chosenport;
+ int status = 0, sock = -1, optvalue, port, chosenport;
struct addrinfo *addrlist = NULL, *addrPtr; /* socket address */
TcpState *statePtr = NULL;
char channelName[SOCK_CHAN_LENGTH];
@@ -1476,6 +1476,11 @@ Tcl_OpenTcpServerEx(
retry++;
chosenport = 0;
+ if (TclSockGetPort(interp, service, "tcp", &port) != TCL_OK) {
+ errorMsg = "invalid port number";
+ goto error;
+ }
+
if (!TclCreateSocketAddress(interp, &addrlist, myHost, port, 1, &errorMsg)) {
my_errno = errno;
goto error;