[ruby-talk:00274] IPv6-ready ruby
From:
Jun-ichiro itojun Hagino <itojun@...>
Date:
1999-04-13 18:39:11 UTC
List:
ruby-talk #274
We KAME team (www.kame.net) are working on IPv6-ready ruby.
This is currently based on ruby 1.2.5 (stable branch).
Snapshots are available at ftp://ftp.kame.net/pub/kame/misc/.
The patch mainly modifies Socket and its child classes, configure
script and ftplib.rb.
I would like to have you comments on Socket class API issues. I have
been trying to make it backward-compatible for existing applications,
but I may have broke somewhere.
We hope to supply patch to 1.3.x and hoping that to be merged into
1.3.x code tree. (IPv6 support in ruby base system would be cool...).
itojun@kame.net
--- current README.v6
IPv6-ready ruby 1.2.x
KAME Project
$Id: README.v6,v 1.10 1999/04/13 18:30:16 itojun Exp $
This patchkit enables ruby 1.2.x to perform AF_INET6 socket operations.
The only affected module is ext/socket/socket.c.
ext/socket/socket.c
Basically you can write IPv6 address where IPv4 address fits.
The code relies upon getaddrinfo().
UDPsocket
UDPsocket.open() and UDPsocket.new() takes optional argument,
address family, like:
u = UDPsocket.open(Socket.AF_INET6)
UDPsocket.open() will create a socket by socket(2) system call.
Future UDPsocket operations will perform getaddrinfo(3) to obtain
the address, then try all the addresses returned until successful
result comes from the kernel. For example,
u = UDPsocket.open(Socket.AF_INET6)
u.sendto("foo", 0, "localhost", "echo")
will perform udp packet output toward ::1 (if getaddrinfo(3) returns
127.0.0.1 and ::1, UDPsocket.sendto() will loop through the addresses).
TCPserver
TCPserver module treats integer values (0, or 0x0a000001) as
IPv4 address. Also, if host part is omitted, it will be treated
as 0. Therefore, the following statement will listen to IPv4 TCP
socket (the three statements have the same effect):
t = TCPserver.open($port) # omit host part
t = TCPserver.open(0, $port) # is equal to 0
t = TCPserver.open("0.0.0.0", $port) # is equal to 0.0.0.0
If you would like to explicitly listen to IPv6 socket, try:
t = TCPserver.open("::", $port) # force IPv6
The behavior should be fixed soon. IMHO, when address is not specified
TCPserver should listen to all the addresses returned by getaddrinfo(3).
Socket.getaddrinfo(host, port, family, socktype, protocol, flags)
Perform getaddrinfo(3). host and port are mandatory, the rest (family
to flags) are optional.
host: nil (NULL), String (as hostname)
port: nil (NULL), Integer (as port number), String (as port name)
family: nil or Integer (passed as hints.ai_family)
socktype: nil or Integer (passed as hints.ai_socktype)
protocol: nil or Integer (passed as hints.ai_protocol)
flags: nil or Integer (passed as hints.ai_flags)
The value returned is array of the following array:
elem[0]: address family as string, like "AF_INET6"
elem[1]: port number (numeric)
elem[2]: numeric hostname
elem[3]: numeric hostname, or canonical hostname if exist
elem[4]: numeric res->ai_family
elem[5]: numeric res->ai_socktype
elem[6]: numeric res->ai_protocol
Format of elem[0 .. 3] is the same as the return value of
IPsocket.addr().
Examples:
# for wildcard sockaddrs for listening socket
x = Socket.getaddrinfo(nil, 80, nil, nil, nil, Socket::AI_PASSIVE)
# for specific sockaddrs for outgoing socket
y = Socket.getaddrinfo("www.yahoo.com", 80, nil,
Socket::SOCK_STREAM)
# no port information, just getting addresses
z = Socket.getaddrinfo("localhost", nil)
constants
The following symbols are defined, and can be accessed as
Socket::AF_INET6 or likewise: AF_INET6, PF_INET6, PF_UNSPEC,
AI_xxx, NI_xxx (see RFC2553)
lib/ftplib.rb
Supports ftp over IPv6, both in passive and active mode. Based on
RFC2428 EPSV/EPRT.
configure
Configure has extra option, --enable-ipv6 and --disable-ipv6.
The option controls IPv6 support feature.
restrictions
- On KAME IPv6 protocol stack, ext/socket/socket.c cannot be
dynamically loaded, due to external reference to static link
library (libinet6.a). This should be fixed soon.
- The patched tree will compile only on UNIX variants.
Most of BeOS/Windows compatibility code is removed from
ext/socket/socet.c.
todo
- Supply Socket.getaddrinfo() and Socket.getaddrinfo().
- Clarify behavior of wildcard bind.
If you use IPv6 features, it is assumed that you have working(*)
getaddrinfo() and getnameinfo() library functions. If you compile this
on IPv4-only machine, missing/getaddrinfo.c is used as last-resort version
(which support IPv4 only) of getaddrinfo().
For more complete implementation you might want to check BIND 8.2.
(*) NOTE: we have noticed that some of IPv6 stack is shipped with broken
getaddrinfo(). In such cases, you should get working library. Contact the
vendor for details.
When compiling this kit onto IPv6, you may need to specify some additional
library paths or cpp defs. (like -linet6 or -DINET6)
--enable-ipv6 will give you some warning, if the IPv6 stack is unknown
to the "configure" script. Currently, the following IPv6 stacks
are supported:
- KAME IPv6 stack, http://www.kame.net/
Author contacts
http://www.kame.net/
mailto:core@kame.net