diff options
author | Kaz Kylheku <kaz@kylheku.com> | 2022-10-02 10:11:58 -0700 |
---|---|---|
committer | Kaz Kylheku <kaz@kylheku.com> | 2022-10-02 10:11:58 -0700 |
commit | 16272e28b07167948d93c5000a5fec16664f51d2 (patch) | |
tree | 0a01239b7fa7269d5f95b51546ba70584a67ec1c /stdlib/socket.tl | |
parent | 7047c9534390f8f40297e2d384436568da7916d4 (diff) | |
download | txr-16272e28b07167948d93c5000a5fec16664f51d2.tar.gz txr-16272e28b07167948d93c5000a5fec16664f51d2.tar.bz2 txr-16272e28b07167948d93c5000a5fec16664f51d2.zip |
New sockaddr-str function.
This function "intelligently" constructs an
address object of the right type from a string.
* socket.c (sock_set_entries): Autoload socket.tl
on sockaddr-str function being accessed.
* stdlib/socket.tl (sockaddr-str): New function.
* tests/014/sockaddr-str.tl: New file.
* txr.1: Documented.
* stdlib.doc-syms.tl: Updated.
Diffstat (limited to 'stdlib/socket.tl')
-rw-r--r-- | stdlib/socket.tl | 9 |
1 files changed, 9 insertions, 0 deletions
diff --git a/stdlib/socket.tl b/stdlib/socket.tl index 80a60ec5..af4aca4e 100644 --- a/stdlib/socket.tl +++ b/stdlib/socket.tl @@ -279,3 +279,12 @@ (,setter (val) ^(sock-set-opt ,',sock ,',level ,',option ,val ,',type))) ,body))) + +(defun sockaddr-str (str) + (cond + ((starts-with "[" str) (in6addr-str str)) + ((starts-with "/" str) (new sockaddr-un path str)) + ((contains "::" str) (in6addr-str str)) + ((contains "." str) (inaddr-str str)) + (t (or (ignerr (in6addr-str str)) + (inaddr-str str))))) |