{ T{ ipv4 f "0.0.0.0" } }
? ;
-: host-name ( -- string )
- 256 <byte-array> dup dup length gethostname
- zero? [ "gethostname failed" throw ] unless
- ascii alien>string ;
+HOOK: host-name os ( -- string )
M: inet (client) resolve-host (client) ;
! 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
drop
path>> utf8 alien>string <local> ;
+M: unix host-name
+ 256 [ <byte-array> dup ] keep gethostname io-error
+ ascii alien>string ;
+
os linux? [ "io.sockets.unix.linux" require ] when
! 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
[ wait-for-socket drop ]
bi
] with-destructors ;
+
+M: windows host-name
+ 256 [ <byte-array> dup ] keep gethostname socket-error
+ ascii alien>string ;