diff --git a/basis/io/sockets/sockets.factor b/basis/io/sockets/sockets.factor index db968e1a7c..ff01ecf037 100644 --- a/basis/io/sockets/sockets.factor +++ b/basis/io/sockets/sockets.factor @@ -442,10 +442,7 @@ M: object resolve-localhost { T{ ipv4 f "0.0.0.0" } } ? ; -: host-name ( -- string ) - 256 dup dup length gethostname - zero? [ "gethostname failed" throw ] unless - ascii alien>string ; +HOOK: host-name os ( -- string ) M: inet (client) resolve-host (client) ; diff --git a/basis/io/sockets/unix/unix.factor b/basis/io/sockets/unix/unix.factor index 83ab45feae..5c57d30464 100644 --- a/basis/io/sockets/unix/unix.factor +++ b/basis/io/sockets/unix/unix.factor @@ -1,10 +1,10 @@ ! Copyright (C) 2004, 2008 Slava Pestov, Ivan Tikhonov. ! See http://factorcode.org/license.txt for BSD license. USING: accessors alien alien.c-types alien.data alien.strings -arrays classes.struct combinators destructors io.backend.unix -io.encodings.utf8 io.files io.pathnames io.sockets.private kernel -libc locals math namespaces sequences system unix -unix.ffi vocabs ; +arrays byte-arrays classes.struct combinators destructors +io.backend.unix io.encodings.ascii io.encodings.utf8 io.files +io.pathnames io.sockets.private kernel libc locals math +namespaces sequences system unix unix.ffi vocabs ; EXCLUDE: io => read write ; EXCLUDE: io.sockets => accept ; IN: io.sockets.unix @@ -182,4 +182,8 @@ M: local parse-sockaddr drop path>> utf8 alien>string ; +M: unix host-name + 256 [ dup ] keep gethostname io-error + ascii alien>string ; + os linux? [ "io.sockets.unix.linux" require ] when diff --git a/basis/io/sockets/windows/windows.factor b/basis/io/sockets/windows/windows.factor index 82eb08a83e..e45eef2393 100755 --- a/basis/io/sockets/windows/windows.factor +++ b/basis/io/sockets/windows/windows.factor @@ -1,10 +1,13 @@ ! Copyright (C) 2007, 2009 Slava Pestov, Doug Coleman. ! See http://factorcode.org/license.txt for BSD license. -USING: accessors alien alien.c-types alien.data classes.struct -combinators destructors io.backend io.files.windows io.ports -io.sockets io.sockets.icmp io.sockets.private kernel libc locals -math sequences system windows.errors windows.handles -windows.kernel32 windows.types windows.winsock ; + +USING: accessors alien alien.c-types alien.data alien.strings +byte-arrays classes.struct combinators destructors io.backend +io.encodings.ascii io.files.windows io.ports io.sockets +io.sockets.icmp io.sockets.private kernel libc locals math +sequences system windows.errors windows.handles windows.kernel32 +windows.types windows.winsock ; + FROM: namespaces => get ; IN: io.sockets.windows @@ -318,3 +321,7 @@ M: windows (send) ( packet addrspec datagram -- ) [ wait-for-socket drop ] bi ] with-destructors ; + +M: windows host-name + 256 [ dup ] keep gethostname socket-error + ascii alien>string ;