chiark / gitweb /
dgram: Provide `dgram-socket sockname S'.
authorIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 18 Aug 2018 21:50:51 +0000 (22:50 +0100)
committerIan Jackson <ijackson@chiark.greenend.org.uk>
Sat, 18 Aug 2018 21:50:53 +0000 (22:50 +0100)
Closes:#865451.

Signed-off-by: Ian Jackson <ijackson@chiark.greenend.org.uk>
debian/changelog
dgram/dgram.c
dgram/dgram.tct

index c859f29..1c3415d 100644 (file)
@@ -4,6 +4,9 @@ chiark-tcl (1.2.2~) unstable; urgency=medium
   * Fix IPv6 PTR (reverse) lookups, and compilation with GCC-8.
     Closes:#891544.
 
+  dgram:
+  * Provide `dgram-socket sockname S'.  Closes:#865451.
+
   tcmdifgen:
   * Turn on warnings and `use strict' and fix everything.
   * Replace deprecated `use IO;' with `use IO::File'.
index 24c5446..5ffe91f 100644 (file)
@@ -134,6 +134,18 @@ x_rc:
     Tcl_BackgroundError(ip);
 }
 
+int cht_do_dgramsocket_sockname(ClientData cd, Tcl_Interp *ip,
+                               void *sock_v, SockAddr_Value *result) {
+  DgramSocket *sock= sock_v;
+  int r;
+
+  socklen_t salen = sock->addr_buflen;
+  r= getsockname(sock->fd, sock->addr_buf, &salen);
+  if (r) return cht_posixerr(ip,errno,"getsockname");
+  cht_sockaddr_create(result, sock->addr_buf, salen);
+  return TCL_OK;
+}
+
 int cht_do_dgramsocket_on_receive(ClientData cd, Tcl_Interp *ip,
                               void *sock_v, Tcl_Obj *newscript) {
   DgramSocket *sock= sock_v;
index 119e354..938d0a3 100644 (file)
@@ -32,6 +32,9 @@ Table dgramsocket DgramSocket_SubCommand
                sock    iddata(&cht_dgram_socks)
                data    hb
                remote  sockaddr
+       sockname
+               sock    iddata(&cht_dgram_socks)
+               =>      sockaddr
        on-receive
                sock    iddata(&cht_dgram_socks)
                ?script obj