Only return ipv4 addresses for binding to on linux.
parent
5c30c3db1c
commit
a2a598546f
|
@ -87,12 +87,9 @@ M: f (>insecure) ;
|
||||||
>insecure
|
>insecure
|
||||||
[ dup { [ secure? ] [ not ] } 1|| [ <secure> ] unless ] map ;
|
[ dup { [ secure? ] [ not ] } 1|| [ <secure> ] unless ] map ;
|
||||||
|
|
||||||
: filter-ipv6 ( seq -- seq' )
|
|
||||||
ipv6-supported? [ [ ipv6? not ] filter ] unless ;
|
|
||||||
|
|
||||||
: listen-on ( threaded-server -- addrspecs )
|
: listen-on ( threaded-server -- addrspecs )
|
||||||
[ secure>> >secure ] [ insecure>> >insecure ] bi append
|
[ secure>> >secure ] [ insecure>> >insecure ] bi append
|
||||||
[ resolve-host ] map concat filter-ipv6 ;
|
[ resolve-host ] map concat ;
|
||||||
|
|
||||||
: accepted-connection ( remote local -- )
|
: accepted-connection ( remote local -- )
|
||||||
[
|
[
|
||||||
|
|
|
@ -4,10 +4,11 @@
|
||||||
USING: accessors alien.c-types alien.data alien.strings arrays
|
USING: accessors alien.c-types alien.data alien.strings arrays
|
||||||
assocs byte-arrays classes classes.struct combinators
|
assocs byte-arrays classes classes.struct combinators
|
||||||
combinators.short-circuit continuations destructors fry generic
|
combinators.short-circuit continuations destructors fry generic
|
||||||
grouping io.backend io.binary io.encodings io.encodings.ascii
|
grouping init io.backend io.binary io.encodings
|
||||||
io.encodings.binary io.ports io.streams.duplex kernel math
|
io.encodings.ascii io.encodings.binary io.ports
|
||||||
math.parser namespaces parser present sequences splitting
|
io.streams.duplex kernel math math.parser memoize namespaces
|
||||||
strings summary system vocabs.loader vocabs.parser ;
|
parser present sequences splitting strings summary system
|
||||||
|
vocabs.loader vocabs.parser ;
|
||||||
IN: io.sockets
|
IN: io.sockets
|
||||||
|
|
||||||
<< {
|
<< {
|
||||||
|
@ -349,8 +350,16 @@ SYMBOL: remote-address
|
||||||
: send ( packet addrspec datagram -- )
|
: send ( packet addrspec datagram -- )
|
||||||
check-send (send) ;
|
check-send (send) ;
|
||||||
|
|
||||||
|
MEMO: ipv6-supported? ( -- ? )
|
||||||
|
[ "::1" 0 <inet6> binary <server> dispose t ] [ drop f ] recover ;
|
||||||
|
|
||||||
|
[ \ ipv6-supported? reset-memoized ipv6-supported? drop ]
|
||||||
|
"ipv6-support-check" add-startup-hook
|
||||||
|
|
||||||
GENERIC: resolve-host ( addrspec -- seq )
|
GENERIC: resolve-host ( addrspec -- seq )
|
||||||
|
|
||||||
|
HOOK: resolve-localhost os ( -- obj )
|
||||||
|
|
||||||
TUPLE: hostname { host ?string read-only } ;
|
TUPLE: hostname { host ?string read-only } ;
|
||||||
|
|
||||||
TUPLE: inet < hostname port ;
|
TUPLE: inet < hostname port ;
|
||||||
|
@ -378,7 +387,14 @@ M: inet6 resolve-host 1array ;
|
||||||
M: local resolve-host 1array ;
|
M: local resolve-host 1array ;
|
||||||
|
|
||||||
M: f resolve-host
|
M: f resolve-host
|
||||||
drop { T{ ipv6 f "::" } T{ ipv4 f "0.0.0.0" } } ;
|
drop resolve-localhost ;
|
||||||
|
|
||||||
|
M: object resolve-localhost
|
||||||
|
ipv6-supported? [
|
||||||
|
{ T{ ipv4 f "0.0.0.0" } T{ ipv6 f "::" } }
|
||||||
|
] [
|
||||||
|
{ T{ ipv4 f "0.0.0.0" } }
|
||||||
|
] if ;
|
||||||
|
|
||||||
: host-name ( -- string )
|
: host-name ( -- string )
|
||||||
256 <byte-array> dup dup length gethostname
|
256 <byte-array> dup dup length gethostname
|
||||||
|
@ -407,9 +423,6 @@ M: invalid-local-address summary
|
||||||
[ invalid-local-address ] if
|
[ invalid-local-address ] if
|
||||||
] dip with-variable ; inline
|
] dip with-variable ; inline
|
||||||
|
|
||||||
: ipv6-supported? ( -- ? )
|
|
||||||
[ "::1" 0 <inet6> binary <server> dispose t ] [ drop f ] recover ;
|
|
||||||
|
|
||||||
{
|
{
|
||||||
{ [ os unix? ] [ "io.sockets.unix" require ] }
|
{ [ os unix? ] [ "io.sockets.unix" require ] }
|
||||||
{ [ os windows? ] [ "io.sockets.windows" require ] }
|
{ [ os windows? ] [ "io.sockets.windows" require ] }
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
Doug Coleman
|
|
@ -0,0 +1,9 @@
|
||||||
|
! Copyright (C) 2010 Doug Coleman.
|
||||||
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
|
USING: io.sockets kernel system ;
|
||||||
|
IN: io.sockets.unix.linux
|
||||||
|
|
||||||
|
! Linux seems to use the same port-space for ipv4 and ipv6.
|
||||||
|
|
||||||
|
M: linux resolve-localhost { T{ ipv4 f "0.0.0.0" } } ;
|
||||||
|
|
|
@ -0,0 +1 @@
|
||||||
|
linux
|
|
@ -1,16 +1,15 @@
|
||||||
! Copyright (C) 2004, 2008 Slava Pestov, Ivan Tikhonov.
|
! Copyright (C) 2004, 2008 Slava Pestov, Ivan Tikhonov.
|
||||||
! See http://factorcode.org/license.txt for BSD license.
|
! See http://factorcode.org/license.txt for BSD license.
|
||||||
USING: alien alien.c-types alien.strings generic kernel math
|
USING: accessors alien alien.c-types alien.data alien.strings
|
||||||
threads sequences byte-arrays io.binary io.backend.unix
|
byte-arrays classes.struct combinators continuations
|
||||||
io.streams.duplex io.backend io.pathnames io.sockets.private
|
destructors generic init io.backend io.backend.unix io.binary
|
||||||
io.files.private io.encodings.utf8 math.parser continuations
|
io.encodings.utf8 io.files.private io.pathnames
|
||||||
libc combinators system accessors destructors unix locals init
|
io.sockets.private io.streams.duplex kernel libc locals math
|
||||||
classes.struct alien.data unix.ffi ;
|
math.parser sequences system threads unix unix.ffi
|
||||||
|
vocabs.loader ;
|
||||||
EXCLUDE: namespaces => bind ;
|
EXCLUDE: namespaces => bind ;
|
||||||
EXCLUDE: io => read write ;
|
EXCLUDE: io => read write ;
|
||||||
EXCLUDE: io.sockets => accept ;
|
EXCLUDE: io.sockets => accept ;
|
||||||
|
|
||||||
IN: io.sockets.unix
|
IN: io.sockets.unix
|
||||||
|
|
||||||
: socket-fd ( domain type protocol -- fd )
|
: socket-fd ( domain type protocol -- fd )
|
||||||
|
@ -185,3 +184,5 @@ M: local make-sockaddr
|
||||||
M: local parse-sockaddr
|
M: local parse-sockaddr
|
||||||
drop
|
drop
|
||||||
path>> utf8 alien>string <local> ;
|
path>> utf8 alien>string <local> ;
|
||||||
|
|
||||||
|
os linux? [ "io.sockets.unix.linux" require ] when
|
||||||
|
|
Loading…
Reference in New Issue