! Binding to all interfaces should work
[ ] [ f 0 <inet4> <datagram> dispose ] unit-test
[ ] [ f 0 <inet6> <datagram> dispose ] unit-test
+
+[ 80 ] [ "http" protocol-port ] unit-test
[ invalid-local-address ] if
] dip with-variable ; inline
+: protocol-port ( protocol -- port )
+ f getservbyname [ port>> htons ] [ f ] if* ;
+
{
{ [ os unix? ] [ "io.sockets.unix" require ] }
{ [ os windows? ] [ "io.sockets.windows" require ] }
--- /dev/null
+IN: unix.ffi.tests
+USING: accessors alien.c-types tools.test unix.ffi ;
+
+[ 80 ] [ "http" f getservbyname port>> ntohs ] unit-test
+
+[ "www" ] [
+ 0 "http" f getservbyname aliases>> c-string alien-element
+] unit-test
+
+[ "http" ] [ 80 htons f getservbyport name>> ] unit-test
{ iov_base void* }
{ iov_len size_t } ;
+STRUCT: servent
+ { name c-string }
+ { aliases void* }
+ { port int }
+ { proto c-string } ;
+
CONSTANT: F_OK 0 ! test for existence of file
CONSTANT: X_OK 1 ! test for execute or search permission
CONSTANT: W_OK 2 ! test for write permission
FUNCTION: int getsockname ( int socket, sockaddr* address, socklen_t* address_len ) ;
FUNCTION: int getpeername ( int socket, sockaddr* address, socklen_t* address_len ) ;
FUNCTION: protoent* getprotobyname ( c-string name ) ;
+FUNCTION: servent* getservbyname ( c-string name, c-string prot ) ;
+FUNCTION: servent* getservbyport ( int port, c-string prot ) ;
FUNCTION: uid_t getuid ;
FUNCTION: uint htonl ( uint n ) ;
FUNCTION: ushort htons ( ushort n ) ;
M: pathname >url string>> >url ;
-: protocol-port ( protocol -- port )
- {
- { "http" [ 80 ] }
- { "https" [ 443 ] }
- { "ftp" [ 21 ] }
- [ drop f ]
- } case ;
-
: relative-url ( url -- url' )
clone
f >>protocol
{ sec long }
{ usec long } ;
+STRUCT: servent
+ { name c-string }
+ { proto c-string } ;
+
GENERIC: sockaddr>ip ( sockaddr -- string )
M: sockaddr-in sockaddr>ip ( sockaddr -- string )
FUNCTION: protoent* getprotobyname ( c-string name ) ;
+FUNCTION: servent* getservbyname ( c-string name, c-string prot ) ;
+FUNCTION: servent* getservbyport ( c-string name, c-string prot ) ;
+
TYPEDEF: uint SERVICETYPE
TYPEDEF: OVERLAPPED WSAOVERLAPPED
TYPEDEF: WSAOVERLAPPED* LPWSAOVERLAPPED
: throw-winsock-error ( -- * )
WSAGetLastError (throw-winsock-error) ;
-
+
: winsock-error=0/f ( n/f -- )
{ 0 f } member? [ throw-winsock-error ] when ;