aboutsummaryrefslogtreecommitdiff
path: root/jim-aio.c
diff options
context:
space:
mode:
authorDanyil Bohdan <danyil.bohdan@gmail.com>2014-07-26 10:50:17 +0300
committerSteve Bennett <steveb@workware.net.au>2014-09-01 08:07:05 +1000
commita71a09f67ceb1bdadde86981da76d4f42dffab81 (patch)
treef97b52d991df6de7d2770964cd3ab67be341d52b /jim-aio.c
parent0c24afc040fcdcdc51513ea946a1cf4b36987a09 (diff)
downloadjimtcl-a71a09f67ceb1bdadde86981da76d4f42dffab81.zip
jimtcl-a71a09f67ceb1bdadde86981da76d4f42dffab81.tar.gz
jimtcl-a71a09f67ceb1bdadde86981da76d4f42dffab81.tar.bz2
aio: optional argument addrvar for accept.
Diffstat (limited to 'jim-aio.c')
-rw-r--r--jim-aio.c28
1 files changed, 26 insertions, 2 deletions
diff --git a/jim-aio.c b/jim-aio.c
index 70fc1e3..37e1ea7 100644
--- a/jim-aio.c
+++ b/jim-aio.c
@@ -623,6 +623,30 @@ static int aio_cmd_accept(Jim_Interp *interp, int argc, Jim_Obj *const *argv)
return JIM_ERR;
}
+ if (argc > 0) {
+ /* INET6_ADDRSTRLEN is 46. Add some for [] and port */
+ char addrbuf[60];
+
+#if IPV6
+ if (sa.sa.sa_family == PF_INET6) {
+ addrbuf[0] = '[';
+ /* Allow 9 for []:65535\0 */
+ inet_ntop(sa.sa.sa_family, &sa.sin6.sin6_addr, addrbuf + 1, sizeof(addrbuf) - 9);
+ snprintf(addrbuf + strlen(addrbuf), 8, "]:%d", ntohs(sa.sin.sin_port));
+ }
+ else
+#endif
+ if (sa.sa.sa_family == PF_INET) {
+ /* Allow 7 for :65535\0 */
+ inet_ntop(sa.sa.sa_family, &sa.sin.sin_addr, addrbuf, sizeof(addrbuf) - 7);
+ snprintf(addrbuf + strlen(addrbuf), 7, ":%d", ntohs(sa.sin.sin_port));
+ }
+
+ if (Jim_SetVariable(interp, argv[0], Jim_NewStringObj(interp, addrbuf, -1)) != JIM_OK) {
+ return JIM_ERR;
+ }
+ }
+
/* Create the file command */
return JimMakeChannel(interp, NULL, sock, Jim_NewStringObj(interp, "accept", -1),
"aio.sockstream%ld", af->addr_family, "r+");
@@ -916,10 +940,10 @@ static const jim_subcmd_type aio_command_table[] = {
/* Description: Send 'str' to the given address (dgram only) */
},
{ "accept",
- NULL,
+ "?addrvar?",
aio_cmd_accept,
0,
- 0,
+ 1,
/* Description: Server socket only: Accept a connection and return stream */
},
{ "listen",