mirror of
https://github.com/ruby/ruby.git
synced 2022-11-09 12:17:21 -05:00
* ext/socket: AddrInfo is renamed to Addrinfo. [ruby-dev:37876]
git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@22077 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
b3e665760e
commit
88f04bdd32
13 changed files with 229 additions and 225 deletions
|
@ -1,3 +1,7 @@
|
|||
Thu Feb 5 19:58:40 2009 Tanaka Akira <akr@fsij.org>
|
||||
|
||||
* ext/socket: AddrInfo is renamed to Addrinfo. [ruby-dev:37876]
|
||||
|
||||
Thu Feb 5 16:18:13 2009 Nobuyoshi Nakada <nobu@ruby-lang.org>
|
||||
|
||||
* configure.in (RUBY_SITE_LIB_PATH, RUBY_VENDOR_LIB_PATH): fix for
|
||||
|
|
6
NEWS
6
NEWS
|
@ -85,11 +85,11 @@ with all sufficient information, see the ChangeLog file.
|
|||
|
||||
* incompatible changes:
|
||||
* Socket#{recvfrom,recvfrom_nonblock,accept,accept_nonblock,sysaccept}
|
||||
returns a sender address as AddrInfo object instead of a string.
|
||||
returns a sender address as Addrinfo object instead of a string.
|
||||
* BasicSocket#getsockopt returns Socket::Option object instead of a string.
|
||||
|
||||
* new class:
|
||||
* AddrInfo
|
||||
* Addrinfo
|
||||
* Socket::Option
|
||||
* Socket::AncillaryData
|
||||
|
||||
|
@ -115,7 +115,7 @@ with all sufficient information, see the ChangeLog file.
|
|||
* Socket.pair's 3rd argument is optional now.
|
||||
* Socket.pair and UNIXSocket.pair can take a block.
|
||||
* BasicSocket#send, UDPSocket#send, Socket.getnameinfo, Socket#bind, and
|
||||
Socket#{connect,connect_nonblock} accepts an AddrInfo object as sockaddr.
|
||||
Socket#{connect,connect_nonblock} accepts an Addrinfo object as sockaddr.
|
||||
* BasicSocket#getsockopt accepts a Socket::Option object.
|
||||
|
||||
* string/symbol as protocol/address family, socket type, protocol level,
|
||||
|
|
|
@ -736,7 +736,7 @@ bsock_sendmsg_internal(int argc, VALUE *argv, VALUE sock, int nonblock)
|
|||
*
|
||||
* _dest_sockaddr_ is a destination socket address for connection-less socket.
|
||||
* It should be a sockaddr such as a result of Socket.sockaddr_in.
|
||||
* An AddrInfo object can be used too.
|
||||
* An Addrinfo object can be used too.
|
||||
*
|
||||
* _controls_ is a list of ancillary data.
|
||||
* The element of _controls_ should be Socket::AncillaryData or
|
||||
|
@ -997,7 +997,7 @@ bsock_recvmsg_internal(int argc, VALUE *argv, VALUE sock, int nonblock)
|
|||
* _mesg_ is a string of the received message.
|
||||
*
|
||||
* _sender_addrinfo_ is a sender socket address for connection-less socket.
|
||||
* It is an AddrInfo object.
|
||||
* It is an Addrinfo object.
|
||||
* For connection-oriented socket such as TCP, sender_addrinfo is platform dependent.
|
||||
*
|
||||
* _rflags_ is a flags on the received message which is bitwise OR of MSG_* constants such as Socket::MSG_TRUNC.
|
||||
|
|
|
@ -359,12 +359,12 @@ bsock_getpeername(VALUE sock)
|
|||
* call-seq:
|
||||
* bsock.local_address => addrinfo
|
||||
*
|
||||
* Returns an AddrInfo object for local address obtained by getsockname.
|
||||
* Returns an Addrinfo object for local address obtained by getsockname.
|
||||
*
|
||||
* Note that addrinfo.protocol is filled by 0.
|
||||
*
|
||||
* TCPServer.open("127.0.0.1", 1512) {|serv|
|
||||
* p serv.local_address #=> #<AddrInfo: 127.0.0.1:1512 TCP>
|
||||
* p serv.local_address #=> #<Addrinfo: 127.0.0.1:1512 TCP>
|
||||
* }
|
||||
*
|
||||
*/
|
||||
|
@ -385,14 +385,14 @@ bsock_local_address(VALUE sock)
|
|||
* call-seq:
|
||||
* bsock.remote_address => addrinfo
|
||||
*
|
||||
* Returns an AddrInfo object for remote address obtained by getpeername.
|
||||
* Returns an Addrinfo object for remote address obtained by getpeername.
|
||||
*
|
||||
* Note that addrinfo.protocol is filled by 0.
|
||||
*
|
||||
* TCPServer.open("127.0.0.1", 1728) {|serv|
|
||||
* c = TCPSocket.new("127.0.0.1", 1728)
|
||||
* s = serv.accept
|
||||
* p s.remote_address #=> #<AddrInfo: 127.0.0.1:36504 TCP>
|
||||
* p s.remote_address #=> #<Addrinfo: 127.0.0.1:36504 TCP>
|
||||
* }
|
||||
*
|
||||
*/
|
||||
|
|
|
@ -20,7 +20,7 @@ VALUE rb_cUNIXSocket;
|
|||
VALUE rb_cUNIXServer;
|
||||
#endif
|
||||
VALUE rb_cSocket;
|
||||
VALUE rb_cAddrInfo;
|
||||
VALUE rb_cAddrinfo;
|
||||
|
||||
VALUE rb_eSocket;
|
||||
|
||||
|
|
|
@ -1,29 +1,29 @@
|
|||
require 'socket.so'
|
||||
|
||||
class AddrInfo
|
||||
# creates an AddrInfo object from the arguments.
|
||||
class Addrinfo
|
||||
# creates an Addrinfo object from the arguments.
|
||||
#
|
||||
# The arguments are interpreted as similar to self.
|
||||
#
|
||||
# AddrInfo.tcp("0.0.0.0", 4649).family_addrinfo("www.ruby-lang.org", 80)
|
||||
# #=> #<AddrInfo: 221.186.184.68:80 TCP (www.ruby-lang.org:80)>
|
||||
# Addrinfo.tcp("0.0.0.0", 4649).family_addrinfo("www.ruby-lang.org", 80)
|
||||
# #=> #<Addrinfo: 221.186.184.68:80 TCP (www.ruby-lang.org:80)>
|
||||
#
|
||||
# AddrInfo.unix("/tmp/sock").family_addrinfo("/tmp/sock2")
|
||||
# #=> #<AddrInfo: /tmp/sock2 SOCK_STREAM>
|
||||
# Addrinfo.unix("/tmp/sock").family_addrinfo("/tmp/sock2")
|
||||
# #=> #<Addrinfo: /tmp/sock2 SOCK_STREAM>
|
||||
#
|
||||
def family_addrinfo(*args)
|
||||
if args.empty?
|
||||
raise ArgumentError, "no address specified"
|
||||
elsif AddrInfo === args.first
|
||||
elsif Addrinfo === args.first
|
||||
raise ArgumentError, "too man argument" if args.length != 1
|
||||
elsif self.ip?
|
||||
raise ArgumentError, "IP address needs host and port but #{args.length} arguments given" if args.length != 2
|
||||
host, port = args
|
||||
AddrInfo.getaddrinfo(host, port, self.pfamily, self.socktype, self.protocol)[0]
|
||||
Addrinfo.getaddrinfo(host, port, self.pfamily, self.socktype, self.protocol)[0]
|
||||
elsif self.unix?
|
||||
raise ArgumentError, "UNIX socket needs single path argument but #{args.length} arguments given" if args.length != 1
|
||||
path, = args
|
||||
AddrInfo.unix(path)
|
||||
Addrinfo.unix(path)
|
||||
else
|
||||
raise ArgumentError, "unexpected family"
|
||||
end
|
||||
|
@ -57,13 +57,13 @@ class AddrInfo
|
|||
# If a block is given, it is called with the socket and the value of the block is returned.
|
||||
# The socket is returned otherwise.
|
||||
#
|
||||
# AddrInfo.tcp("www.ruby-lang.org", 80).connect_from("0.0.0.0", 4649) {|s|
|
||||
# Addrinfo.tcp("www.ruby-lang.org", 80).connect_from("0.0.0.0", 4649) {|s|
|
||||
# s.print "GET / HTTP/1.0\r\n\r\n"
|
||||
# p s.read
|
||||
# }
|
||||
#
|
||||
# # AddrInfo object can be taken for the argument.
|
||||
# AddrInfo.tcp("www.ruby-lang.org", 80).connect_from(AddrInfo.tcp("0.0.0.0", 4649)) {|s|
|
||||
# # Addrinfo object can be taken for the argument.
|
||||
# Addrinfo.tcp("www.ruby-lang.org", 80).connect_from(Addrinfo.tcp("0.0.0.0", 4649)) {|s|
|
||||
# s.print "GET / HTTP/1.0\r\n\r\n"
|
||||
# p s.read
|
||||
# }
|
||||
|
@ -77,7 +77,7 @@ class AddrInfo
|
|||
# If a block is given, it is called with the socket and the value of the block is returned.
|
||||
# The socket is returned otherwise.
|
||||
#
|
||||
# AddrInfo.tcp("www.ruby-lang.org", 80).connect {|s|
|
||||
# Addrinfo.tcp("www.ruby-lang.org", 80).connect {|s|
|
||||
# s.print "GET / HTTP/1.0\r\n\r\n"
|
||||
# p s.read
|
||||
# }
|
||||
|
@ -91,7 +91,7 @@ class AddrInfo
|
|||
# If a block is given, it is called with the socket and the value of the block is returned.
|
||||
# The socket is returned otherwise.
|
||||
#
|
||||
# AddrInfo.tcp("0.0.0.0", 4649).connect_to("www.ruby-lang.org", 80) {|s|
|
||||
# Addrinfo.tcp("0.0.0.0", 4649).connect_to("www.ruby-lang.org", 80) {|s|
|
||||
# s.print "GET / HTTP/1.0\r\n\r\n"
|
||||
# p s.read
|
||||
# }
|
||||
|
@ -106,7 +106,7 @@ class AddrInfo
|
|||
# If a block is given, it is called with the socket and the value of the block is returned.
|
||||
# The socket is returned otherwise.
|
||||
#
|
||||
# AddrInfo.udp("0.0.0.0", 9981).bind {|s|
|
||||
# Addrinfo.udp("0.0.0.0", 9981).bind {|s|
|
||||
# s.local_address.connect {|s| s.send "hello", 0 }
|
||||
# p s.recv(10) #=> "hello"
|
||||
# }
|
||||
|
@ -145,16 +145,16 @@ class AddrInfo
|
|||
end
|
||||
end
|
||||
|
||||
# iterates over the list of AddrInfo objects obtained by AddrInfo.getaddrinfo.
|
||||
# iterates over the list of Addrinfo objects obtained by Addrinfo.getaddrinfo.
|
||||
#
|
||||
# AddrInfo.foreach(nil, 80) {|x| p x }
|
||||
# #=> #<AddrInfo: 127.0.0.1:80 TCP (:80)>
|
||||
# # #<AddrInfo: 127.0.0.1:80 UDP (:80)>
|
||||
# # #<AddrInfo: [::1]:80 TCP (:80)>
|
||||
# # #<AddrInfo: [::1]:80 UDP (:80)>
|
||||
# Addrinfo.foreach(nil, 80) {|x| p x }
|
||||
# #=> #<Addrinfo: 127.0.0.1:80 TCP (:80)>
|
||||
# # #<Addrinfo: 127.0.0.1:80 UDP (:80)>
|
||||
# # #<Addrinfo: [::1]:80 TCP (:80)>
|
||||
# # #<Addrinfo: [::1]:80 UDP (:80)>
|
||||
#
|
||||
def self.foreach(nodename, service, family=nil, socktype=nil, protocol=nil, flags=nil, &block)
|
||||
AddrInfo.getaddrinfo(nodename, service, family, socktype, protocol, flags).each(&block)
|
||||
Addrinfo.getaddrinfo(nodename, service, family, socktype, protocol, flags).each(&block)
|
||||
end
|
||||
end
|
||||
|
||||
|
@ -189,10 +189,10 @@ class Socket
|
|||
|
||||
local_addr_list = nil
|
||||
if local_host != nil || local_port != nil
|
||||
local_addr_list = AddrInfo.getaddrinfo(local_host, local_port, nil, :STREAM, nil)
|
||||
local_addr_list = Addrinfo.getaddrinfo(local_host, local_port, nil, :STREAM, nil)
|
||||
end
|
||||
|
||||
AddrInfo.foreach(host, port, nil, :STREAM) {|ai|
|
||||
Addrinfo.foreach(host, port, nil, :STREAM) {|ai|
|
||||
if local_addr_list
|
||||
local_addr = local_addr_list.find {|local_ai| local_ai.afamily == ai.afamily }
|
||||
next if !local_addr
|
||||
|
@ -227,7 +227,7 @@ class Socket
|
|||
end
|
||||
|
||||
def self.tcp_server_sockets_port0(host)
|
||||
ai_list = AddrInfo.getaddrinfo(host, 0, nil, :STREAM, nil, Socket::AI_PASSIVE)
|
||||
ai_list = Addrinfo.getaddrinfo(host, 0, nil, :STREAM, nil, Socket::AI_PASSIVE)
|
||||
begin
|
||||
sockets = []
|
||||
port = nil
|
||||
|
@ -244,7 +244,7 @@ class Socket
|
|||
s.bind(ai)
|
||||
port = s.local_address.ip_port
|
||||
else
|
||||
s.bind(AddrInfo.tcp(ai.ip_address, port))
|
||||
s.bind(Addrinfo.tcp(ai.ip_address, port))
|
||||
end
|
||||
s.listen(5)
|
||||
}
|
||||
|
@ -280,21 +280,21 @@ class Socket
|
|||
#
|
||||
# # The sockets contains IPv6 and IPv4 sockets.
|
||||
# sockets.each {|s| p s.local_address }
|
||||
# #=> #<AddrInfo: [::]:1296 TCP>
|
||||
# # #<AddrInfo: 0.0.0.0:1296 TCP>
|
||||
# #=> #<Addrinfo: [::]:1296 TCP>
|
||||
# # #<Addrinfo: 0.0.0.0:1296 TCP>
|
||||
#
|
||||
# # IPv6 and IPv4 socket has same port number, 53114, even if it is choosen dynamically.
|
||||
# sockets = Socket.tcp_server_sockets(0)
|
||||
# sockets.each {|s| p s.local_address }
|
||||
# #=> #<AddrInfo: [::]:53114 TCP>
|
||||
# # #<AddrInfo: 0.0.0.0:53114 TCP>
|
||||
# #=> #<Addrinfo: [::]:53114 TCP>
|
||||
# # #<Addrinfo: 0.0.0.0:53114 TCP>
|
||||
#
|
||||
def self.tcp_server_sockets(host=nil, port)
|
||||
return tcp_server_sockets_port0(host) if port == 0
|
||||
begin
|
||||
last_error = nil
|
||||
sockets = []
|
||||
AddrInfo.foreach(host, port, nil, :STREAM, nil, Socket::AI_PASSIVE) {|ai|
|
||||
Addrinfo.foreach(host, port, nil, :STREAM, nil, Socket::AI_PASSIVE) {|ai|
|
||||
begin
|
||||
s = ai.listen
|
||||
rescue SystemCallError
|
||||
|
@ -344,7 +344,7 @@ class Socket
|
|||
end
|
||||
|
||||
# creates a TCP server on _port_ and calls the block for each connection accepted.
|
||||
# The block is called with a socket and a client_address as an AddrInfo object.
|
||||
# The block is called with a socket and a client_address as an Addrinfo object.
|
||||
#
|
||||
# If _host_ is specified, it is used with _port_ to determine the server addresses.
|
||||
#
|
||||
|
@ -355,8 +355,8 @@ class Socket
|
|||
# It means that the next connection is not accepted until the block returns.
|
||||
# So concurrent mechanism, thread for example, should be used to service multiple clients at a time.
|
||||
#
|
||||
# Note that AddrInfo.getaddrinfo is used to determine the server socket addresses.
|
||||
# When AddrInfo.getaddrinfo returns two or more addresses,
|
||||
# Note that Addrinfo.getaddrinfo is used to determine the server socket addresses.
|
||||
# When Addrinfo.getaddrinfo returns two or more addresses,
|
||||
# IPv4 and IPv6 address for example,
|
||||
# all of them are used.
|
||||
# Socket.tcp_server_loop succeeds if one socket can be used at least.
|
||||
|
@ -411,7 +411,7 @@ class Socket
|
|||
# }
|
||||
#
|
||||
def self.unix(path) # :yield: socket
|
||||
addr = AddrInfo.unix(path)
|
||||
addr = Addrinfo.unix(path)
|
||||
sock = addr.connect
|
||||
if block_given?
|
||||
begin
|
||||
|
@ -430,7 +430,7 @@ class Socket
|
|||
#
|
||||
# socket = Socket.unix_server_socket("/tmp/s")
|
||||
# p socket #=> #<Socket:fd 3>
|
||||
# p socket.local_address #=> #<AddrInfo: /tmp/s SOCK_STREAM>
|
||||
# p socket.local_address #=> #<Addrinfo: /tmp/s SOCK_STREAM>
|
||||
#
|
||||
def self.unix_server_socket(path)
|
||||
begin
|
||||
|
@ -440,7 +440,7 @@ class Socket
|
|||
if st && st.socket? && st.owned?
|
||||
File.unlink path
|
||||
end
|
||||
AddrInfo.unix(path).listen
|
||||
Addrinfo.unix(path).listen
|
||||
end
|
||||
|
||||
# creates a UNIX socket server on _path_.
|
||||
|
|
|
@ -505,7 +505,7 @@ check_addrinfo(VALUE self)
|
|||
{
|
||||
Check_Type(self, RUBY_T_DATA);
|
||||
if (!IS_ADDRINFO(self)) {
|
||||
rb_raise(rb_eTypeError, "wrong argument type %s (expected AddrInfo)",
|
||||
rb_raise(rb_eTypeError, "wrong argument type %s (expected Addrinfo)",
|
||||
rb_class2name(CLASS_OF(self)));
|
||||
}
|
||||
return DATA_PTR(self);
|
||||
|
@ -558,7 +558,7 @@ addrinfo_new(struct sockaddr *addr, socklen_t len,
|
|||
VALUE a;
|
||||
rb_addrinfo_t *rai;
|
||||
|
||||
a = addrinfo_s_allocate(rb_cAddrInfo);
|
||||
a = addrinfo_s_allocate(rb_cAddrinfo);
|
||||
DATA_PTR(a) = rai = alloc_addrinfo();
|
||||
init_addrinfo(rai, addr, len, family, socktype, protocol, canonname, inspectname);
|
||||
return a;
|
||||
|
@ -740,12 +740,12 @@ init_unix_addrinfo(rb_addrinfo_t *rai, VALUE path)
|
|||
|
||||
/*
|
||||
* call-seq:
|
||||
* AddrInfo.new(sockaddr) => addrinfo
|
||||
* AddrInfo.new(sockaddr, family) => addrinfo
|
||||
* AddrInfo.new(sockaddr, family, socktype) => addrinfo
|
||||
* AddrInfo.new(sockaddr, family, socktype, protocol) => addrinfo
|
||||
* Addrinfo.new(sockaddr) => addrinfo
|
||||
* Addrinfo.new(sockaddr, family) => addrinfo
|
||||
* Addrinfo.new(sockaddr, family, socktype) => addrinfo
|
||||
* Addrinfo.new(sockaddr, family, socktype, protocol) => addrinfo
|
||||
*
|
||||
* returns a new instance of AddrInfo.
|
||||
* returns a new instance of Addrinfo.
|
||||
* It the instnace contains sockaddr, family, socktype, protocol.
|
||||
* sockaddr means struct sockaddr which can be used for connect(2), etc.
|
||||
* family, socktype and protocol are integers which is used for arguments of socket(2).
|
||||
|
@ -765,8 +765,8 @@ init_unix_addrinfo(rb_addrinfo_t *rai, VALUE path)
|
|||
* - Socket.sockaddr_un("/tmp/sock")
|
||||
*
|
||||
* In an AF_INET/AF_INET6 sockaddr array, the 4th element,
|
||||
* numeric IP address, is used to construct socket address in the AddrInfo instance.
|
||||
* The 3rd element, textual host name, is also recorded but only used for AddrInfo#inspect.
|
||||
* numeric IP address, is used to construct socket address in the Addrinfo instance.
|
||||
* The 3rd element, textual host name, is also recorded but only used for Addrinfo#inspect.
|
||||
*
|
||||
* family is specified as an integer to specify the protocol family such as Socket::PF_INET.
|
||||
* It can be a symbol or a string which is the constant name
|
||||
|
@ -1018,8 +1018,8 @@ inspect_sockaddr(VALUE addrinfo, VALUE ret)
|
|||
*
|
||||
* returns a string which shows addrinfo in human-readable form.
|
||||
*
|
||||
* AddrInfo.tcp("localhost", 80).inspect #=> "#<AddrInfo: 127.0.0.1:80 TCP (localhost:80)>"
|
||||
* AddrInfo.unix("/tmp/sock").inspect #=> "#<AddrInfo: /tmp/sock SOCK_STREAM>"
|
||||
* Addrinfo.tcp("localhost", 80).inspect #=> "#<Addrinfo: 127.0.0.1:80 TCP (localhost:80)>"
|
||||
* Addrinfo.unix("/tmp/sock").inspect #=> "#<Addrinfo: /tmp/sock SOCK_STREAM>"
|
||||
*
|
||||
*/
|
||||
static VALUE
|
||||
|
@ -1097,9 +1097,9 @@ addrinfo_inspect(VALUE self)
|
|||
*
|
||||
* returns a string which shows the sockaddr in _addrinfo_ with human-readable form.
|
||||
*
|
||||
* AddrInfo.tcp("localhost", 80).inspect_sockaddr #=> "127.0.0.1:80"
|
||||
* AddrInfo.tcp("ip6-localhost", 80).inspect_sockaddr #=> "[::1]:80"
|
||||
* AddrInfo.unix("/tmp/sock").inspect_sockaddr #=> "/tmp/sock"
|
||||
* Addrinfo.tcp("localhost", 80).inspect_sockaddr #=> "127.0.0.1:80"
|
||||
* Addrinfo.tcp("ip6-localhost", 80).inspect_sockaddr #=> "[::1]:80"
|
||||
* Addrinfo.unix("/tmp/sock").inspect_sockaddr #=> "/tmp/sock"
|
||||
*
|
||||
*/
|
||||
static VALUE
|
||||
|
@ -1299,7 +1299,7 @@ addrinfo_mload(VALUE self, VALUE ary)
|
|||
*
|
||||
* returns the address family as an integer.
|
||||
*
|
||||
* AddrInfo.tcp("localhost", 80).afamily == Socket::AF_INET #=> true
|
||||
* Addrinfo.tcp("localhost", 80).afamily == Socket::AF_INET #=> true
|
||||
*
|
||||
*/
|
||||
static VALUE
|
||||
|
@ -1315,7 +1315,7 @@ addrinfo_afamily(VALUE self)
|
|||
*
|
||||
* returns the protocol family as an integer.
|
||||
*
|
||||
* AddrInfo.tcp("localhost", 80).pfamily == Socket::PF_INET #=> true
|
||||
* Addrinfo.tcp("localhost", 80).pfamily == Socket::PF_INET #=> true
|
||||
*
|
||||
*/
|
||||
static VALUE
|
||||
|
@ -1331,7 +1331,7 @@ addrinfo_pfamily(VALUE self)
|
|||
*
|
||||
* returns the socket type as an integer.
|
||||
*
|
||||
* AddrInfo.tcp("localhost", 80).socktype == Socket::SOCK_STREAM #=> true
|
||||
* Addrinfo.tcp("localhost", 80).socktype == Socket::SOCK_STREAM #=> true
|
||||
*
|
||||
*/
|
||||
static VALUE
|
||||
|
@ -1347,7 +1347,7 @@ addrinfo_socktype(VALUE self)
|
|||
*
|
||||
* returns the socket type as an integer.
|
||||
*
|
||||
* AddrInfo.tcp("localhost", 80).protocol == Socket::IPPROTO_TCP #=> true
|
||||
* Addrinfo.tcp("localhost", 80).protocol == Socket::IPPROTO_TCP #=> true
|
||||
*
|
||||
*/
|
||||
static VALUE
|
||||
|
@ -1363,7 +1363,7 @@ addrinfo_protocol(VALUE self)
|
|||
*
|
||||
* returns the socket address as packed struct sockaddr string.
|
||||
*
|
||||
* AddrInfo.tcp("localhost", 80).to_sockaddr
|
||||
* Addrinfo.tcp("localhost", 80).to_sockaddr
|
||||
* #=> "\x02\x00\x00P\x7F\x00\x00\x01\x00\x00\x00\x00\x00\x00\x00\x00"
|
||||
*
|
||||
*/
|
||||
|
@ -1385,10 +1385,10 @@ addrinfo_to_sockaddr(VALUE self)
|
|||
*
|
||||
* nil is returned if no canonical name.
|
||||
*
|
||||
* The canonical name is set by AddrInfo.getaddrinfo when AI_CANONNAME is specified.
|
||||
* The canonical name is set by Addrinfo.getaddrinfo when AI_CANONNAME is specified.
|
||||
*
|
||||
* list = AddrInfo.getaddrinfo("www.ruby-lang.org", 80, :INET, :STREAM, nil, Socket::AI_CANONNAME)
|
||||
* p list[0] #=> #<AddrInfo: 221.186.184.68:80 TCP carbon.ruby-lang.org (www.ruby-lang.org:80)>
|
||||
* list = Addrinfo.getaddrinfo("www.ruby-lang.org", 80, :INET, :STREAM, nil, Socket::AI_CANONNAME)
|
||||
* p list[0] #=> #<Addrinfo: 221.186.184.68:80 TCP carbon.ruby-lang.org (www.ruby-lang.org:80)>
|
||||
* p list[0].canonname #=> "carbon.ruby-lang.org"
|
||||
*
|
||||
*/
|
||||
|
@ -1406,9 +1406,9 @@ addrinfo_canonname(VALUE self)
|
|||
* returns true if addrinfo is internet (IPv4/IPv6) address.
|
||||
* returns false otherwise.
|
||||
*
|
||||
* AddrInfo.tcp("127.0.0.1", 80).ip? #=> true
|
||||
* AddrInfo.tcp("::1", 80).ip? #=> true
|
||||
* AddrInfo.unix("/tmp/sock").ip? #=> false
|
||||
* Addrinfo.tcp("127.0.0.1", 80).ip? #=> true
|
||||
* Addrinfo.tcp("::1", 80).ip? #=> true
|
||||
* Addrinfo.unix("/tmp/sock").ip? #=> false
|
||||
*
|
||||
*/
|
||||
static VALUE
|
||||
|
@ -1426,9 +1426,9 @@ addrinfo_ip_p(VALUE self)
|
|||
* returns true if addrinfo is IPv4 address.
|
||||
* returns false otherwise.
|
||||
*
|
||||
* AddrInfo.tcp("127.0.0.1", 80).ipv4? #=> true
|
||||
* AddrInfo.tcp("::1", 80).ipv4? #=> false
|
||||
* AddrInfo.unix("/tmp/sock").ipv4? #=> false
|
||||
* Addrinfo.tcp("127.0.0.1", 80).ipv4? #=> true
|
||||
* Addrinfo.tcp("::1", 80).ipv4? #=> false
|
||||
* Addrinfo.unix("/tmp/sock").ipv4? #=> false
|
||||
*
|
||||
*/
|
||||
static VALUE
|
||||
|
@ -1445,9 +1445,9 @@ addrinfo_ipv4_p(VALUE self)
|
|||
* returns true if addrinfo is IPv6 address.
|
||||
* returns false otherwise.
|
||||
*
|
||||
* AddrInfo.tcp("127.0.0.1", 80).ipv6? #=> false
|
||||
* AddrInfo.tcp("::1", 80).ipv6? #=> true
|
||||
* AddrInfo.unix("/tmp/sock").ipv6? #=> false
|
||||
* Addrinfo.tcp("127.0.0.1", 80).ipv6? #=> false
|
||||
* Addrinfo.tcp("::1", 80).ipv6? #=> true
|
||||
* Addrinfo.unix("/tmp/sock").ipv6? #=> false
|
||||
*
|
||||
*/
|
||||
static VALUE
|
||||
|
@ -1468,9 +1468,9 @@ addrinfo_ipv6_p(VALUE self)
|
|||
* returns true if addrinfo is UNIX address.
|
||||
* returns false otherwise.
|
||||
*
|
||||
* AddrInfo.tcp("127.0.0.1", 80).unix? #=> false
|
||||
* AddrInfo.tcp("::1", 80).unix? #=> false
|
||||
* AddrInfo.unix("/tmp/sock").unix? #=> true
|
||||
* Addrinfo.tcp("127.0.0.1", 80).unix? #=> false
|
||||
* Addrinfo.tcp("::1", 80).unix? #=> false
|
||||
* Addrinfo.unix("/tmp/sock").unix? #=> true
|
||||
*
|
||||
*/
|
||||
static VALUE
|
||||
|
@ -1494,9 +1494,9 @@ addrinfo_unix_p(VALUE self)
|
|||
*
|
||||
* flags should be bitwise OR of Socket::NI_??? constants.
|
||||
*
|
||||
* AddrInfo.tcp("127.0.0.1", 80).getnameinfo #=> ["localhost", "www"]
|
||||
* Addrinfo.tcp("127.0.0.1", 80).getnameinfo #=> ["localhost", "www"]
|
||||
*
|
||||
* AddrInfo.tcp("127.0.0.1", 80).getnameinfo(Socket::NI_NUMERICSERV)
|
||||
* Addrinfo.tcp("127.0.0.1", 80).getnameinfo(Socket::NI_NUMERICSERV)
|
||||
* #=> ["localhost", "80"]
|
||||
*/
|
||||
static VALUE
|
||||
|
@ -1530,8 +1530,8 @@ addrinfo_getnameinfo(int argc, VALUE *argv, VALUE self)
|
|||
*
|
||||
* Returns the IP address and port number as 2-element array.
|
||||
*
|
||||
* AddrInfo.tcp("127.0.0.1", 80).ip_unpack #=> ["127.0.0.1", 80]
|
||||
* AddrInfo.tcp("::1", 80).ip_unpack #=> ["::1", 80]
|
||||
* Addrinfo.tcp("127.0.0.1", 80).ip_unpack #=> ["127.0.0.1", 80]
|
||||
* Addrinfo.tcp("::1", 80).ip_unpack #=> ["::1", 80]
|
||||
*/
|
||||
static VALUE
|
||||
addrinfo_ip_unpack(VALUE self)
|
||||
|
@ -1557,8 +1557,8 @@ addrinfo_ip_unpack(VALUE self)
|
|||
*
|
||||
* Returns the IP address as a string.
|
||||
*
|
||||
* AddrInfo.tcp("127.0.0.1", 80).ip_address #=> "127.0.0.1"
|
||||
* AddrInfo.tcp("::1", 80).ip_address #=> "::1"
|
||||
* Addrinfo.tcp("127.0.0.1", 80).ip_address #=> "127.0.0.1"
|
||||
* Addrinfo.tcp("::1", 80).ip_address #=> "::1"
|
||||
*/
|
||||
static VALUE
|
||||
addrinfo_ip_address(VALUE self)
|
||||
|
@ -1582,8 +1582,8 @@ addrinfo_ip_address(VALUE self)
|
|||
*
|
||||
* Returns the port number as an integer.
|
||||
*
|
||||
* AddrInfo.tcp("127.0.0.1", 80).ip_port #=> 80
|
||||
* AddrInfo.tcp("::1", 80).ip_port #=> 80
|
||||
* Addrinfo.tcp("127.0.0.1", 80).ip_port #=> 80
|
||||
* Addrinfo.tcp("::1", 80).ip_port #=> 80
|
||||
*/
|
||||
static VALUE
|
||||
addrinfo_ip_port(VALUE self)
|
||||
|
@ -1836,11 +1836,11 @@ addrinfo_ipv6_mc_global_p(VALUE self)
|
|||
* Returns IPv4 address of IPv4 mapped/compatible IPv6 address.
|
||||
* It returns nil if +self+ is not IPv4 mapped/compatible IPv6 address.
|
||||
*
|
||||
* AddrInfo.ip("::192.0.2.3").ipv6_to_ipv4 #=> #<AddrInfo: 192.0.2.3>
|
||||
* AddrInfo.ip("::ffff:192.0.2.3").ipv6_to_ipv4 #=> #<AddrInfo: 192.0.2.3>
|
||||
* AddrInfo.ip("::1").ipv6_to_ipv4 #=> nil
|
||||
* AddrInfo.ip("192.0.2.3").ipv6_to_ipv4 #=> nil
|
||||
* AddrInfo.unix("/tmp/sock").ipv6_to_ipv4 #=> nil
|
||||
* Addrinfo.ip("::192.0.2.3").ipv6_to_ipv4 #=> #<Addrinfo: 192.0.2.3>
|
||||
* Addrinfo.ip("::ffff:192.0.2.3").ipv6_to_ipv4 #=> #<Addrinfo: 192.0.2.3>
|
||||
* Addrinfo.ip("::1").ipv6_to_ipv4 #=> nil
|
||||
* Addrinfo.ip("192.0.2.3").ipv6_to_ipv4 #=> nil
|
||||
* Addrinfo.unix("/tmp/sock").ipv6_to_ipv4 #=> nil
|
||||
*/
|
||||
static VALUE
|
||||
addrinfo_ipv6_to_ipv4(VALUE self)
|
||||
|
@ -1874,7 +1874,7 @@ addrinfo_ipv6_to_ipv4(VALUE self)
|
|||
*
|
||||
* Returns the socket path as a string.
|
||||
*
|
||||
* AddrInfo.unix("/tmp/sock").unix_path #=> "/tmp/sock"
|
||||
* Addrinfo.unix("/tmp/sock").unix_path #=> "/tmp/sock"
|
||||
*/
|
||||
static VALUE
|
||||
addrinfo_unix_path(VALUE self)
|
||||
|
@ -1903,11 +1903,11 @@ addrinfo_unix_path(VALUE self)
|
|||
|
||||
/*
|
||||
* call-seq:
|
||||
* AddrInfo.getaddrinfo(nodename, service, family, socktype, protocol, flags) => [addrinfo, ...]
|
||||
* AddrInfo.getaddrinfo(nodename, service, family, socktype, protocol) => [addrinfo, ...]
|
||||
* AddrInfo.getaddrinfo(nodename, service, family, socktype) => [addrinfo, ...]
|
||||
* AddrInfo.getaddrinfo(nodename, service, family) => [addrinfo, ...]
|
||||
* AddrInfo.getaddrinfo(nodename, service) => [addrinfo, ...]
|
||||
* Addrinfo.getaddrinfo(nodename, service, family, socktype, protocol, flags) => [addrinfo, ...]
|
||||
* Addrinfo.getaddrinfo(nodename, service, family, socktype, protocol) => [addrinfo, ...]
|
||||
* Addrinfo.getaddrinfo(nodename, service, family, socktype) => [addrinfo, ...]
|
||||
* Addrinfo.getaddrinfo(nodename, service, family) => [addrinfo, ...]
|
||||
* Addrinfo.getaddrinfo(nodename, service) => [addrinfo, ...]
|
||||
*
|
||||
* returns a list of addrinfo objects as an array.
|
||||
*
|
||||
|
@ -1919,7 +1919,7 @@ addrinfo_unix_path(VALUE self)
|
|||
* family, socktype and protocol are hint for prefered protocol.
|
||||
* If the result will be used for a socket with SOCK_STREAM,
|
||||
* SOCK_STREAM should be specified as socktype.
|
||||
* If so, AddrInfo.getaddrinfo returns addrinfo list appropriate for SOCK_STREAM.
|
||||
* If so, Addrinfo.getaddrinfo returns addrinfo list appropriate for SOCK_STREAM.
|
||||
* If they are omitted or nil is given, the result is not restricted.
|
||||
*
|
||||
* Similary, PF_INET6 as family restricts for IPv6.
|
||||
|
@ -1930,9 +1930,9 @@ addrinfo_unix_path(VALUE self)
|
|||
* Some platform causes an error when socktype is ommitted and servname is specified as an integer
|
||||
* because some port numbers, 512 for example, are ambiguous without socktype.
|
||||
*
|
||||
* AddrInfo.getaddrinfo("www.kame.net", 80, nil, :STREAM)
|
||||
* #=> [#<AddrInfo: 203.178.141.194:80 TCP (www.kame.net:80)>,
|
||||
* # #<AddrInfo: [2001:200:0:8002:203:47ff:fea5:3085]:80 TCP (www.kame.net:80)>]
|
||||
* Addrinfo.getaddrinfo("www.kame.net", 80, nil, :STREAM)
|
||||
* #=> [#<Addrinfo: 203.178.141.194:80 TCP (www.kame.net:80)>,
|
||||
* # #<Addrinfo: [2001:200:0:8002:203:47ff:fea5:3085]:80 TCP (www.kame.net:80)>]
|
||||
*
|
||||
*/
|
||||
static VALUE
|
||||
|
@ -1946,14 +1946,14 @@ addrinfo_s_getaddrinfo(int argc, VALUE *argv, VALUE self)
|
|||
|
||||
/*
|
||||
* call-seq:
|
||||
* AddrInfo.ip(host) => addrinfo
|
||||
* Addrinfo.ip(host) => addrinfo
|
||||
*
|
||||
* returns an addrinfo object for IP address.
|
||||
*
|
||||
* The port, socktype, protocol of the result is filled by zero.
|
||||
* So, it is not appropriate to create a socket.
|
||||
*
|
||||
* AddrInfo.ip("localhost") #=> #<AddrInfo: 127.0.0.1 (localhost)>
|
||||
* Addrinfo.ip("localhost") #=> #<Addrinfo: 127.0.0.1 (localhost)>
|
||||
*/
|
||||
static VALUE
|
||||
addrinfo_s_ip(VALUE self, VALUE host)
|
||||
|
@ -1970,11 +1970,11 @@ addrinfo_s_ip(VALUE self, VALUE host)
|
|||
|
||||
/*
|
||||
* call-seq:
|
||||
* AddrInfo.tcp(host, port) => addrinfo
|
||||
* Addrinfo.tcp(host, port) => addrinfo
|
||||
*
|
||||
* returns an addrinfo object for TCP address.
|
||||
*
|
||||
* AddrInfo.tcp("localhost", "smtp") #=> #<AddrInfo: 127.0.0.1:25 TCP (localhost:smtp)>
|
||||
* Addrinfo.tcp("localhost", "smtp") #=> #<Addrinfo: 127.0.0.1:25 TCP (localhost:smtp)>
|
||||
*/
|
||||
static VALUE
|
||||
addrinfo_s_tcp(VALUE self, VALUE host, VALUE port)
|
||||
|
@ -1985,11 +1985,11 @@ addrinfo_s_tcp(VALUE self, VALUE host, VALUE port)
|
|||
|
||||
/*
|
||||
* call-seq:
|
||||
* AddrInfo.udp(host, port) => addrinfo
|
||||
* Addrinfo.udp(host, port) => addrinfo
|
||||
*
|
||||
* returns an addrinfo object for UDP address.
|
||||
*
|
||||
* AddrInfo.udp("localhost", "daytime") #=> #<AddrInfo: 127.0.0.1:13 UDP (localhost:daytime)>
|
||||
* Addrinfo.udp("localhost", "daytime") #=> #<Addrinfo: 127.0.0.1:13 UDP (localhost:daytime)>
|
||||
*/
|
||||
static VALUE
|
||||
addrinfo_s_udp(VALUE self, VALUE host, VALUE port)
|
||||
|
@ -2002,11 +2002,11 @@ addrinfo_s_udp(VALUE self, VALUE host, VALUE port)
|
|||
|
||||
/*
|
||||
* call-seq:
|
||||
* AddrInfo.udp(host, port) => addrinfo
|
||||
* Addrinfo.udp(host, port) => addrinfo
|
||||
*
|
||||
* returns an addrinfo object for UNIX socket address.
|
||||
*
|
||||
* AddrInfo.unix("/tmp/sock") #=> #<AddrInfo: /tmp/sock SOCK_STREAM>
|
||||
* Addrinfo.unix("/tmp/sock") #=> #<Addrinfo: /tmp/sock SOCK_STREAM>
|
||||
*/
|
||||
static VALUE
|
||||
addrinfo_s_unix(VALUE self, VALUE path)
|
||||
|
@ -2014,7 +2014,7 @@ addrinfo_s_unix(VALUE self, VALUE path)
|
|||
VALUE addr;
|
||||
rb_addrinfo_t *rai;
|
||||
|
||||
addr = addrinfo_s_allocate(rb_cAddrInfo);
|
||||
addr = addrinfo_s_allocate(rb_cAddrinfo);
|
||||
DATA_PTR(addr) = rai = alloc_addrinfo();
|
||||
init_unix_addrinfo(rai, path);
|
||||
OBJ_INFECT(addr, path);
|
||||
|
@ -2090,69 +2090,69 @@ io_socket_addrinfo(VALUE io, struct sockaddr *addr, socklen_t len)
|
|||
}
|
||||
|
||||
/*
|
||||
* AddrInfo class
|
||||
* Addrinfo class
|
||||
*/
|
||||
void
|
||||
Init_addrinfo(void)
|
||||
{
|
||||
rb_cAddrInfo = rb_define_class("AddrInfo", rb_cData);
|
||||
rb_define_alloc_func(rb_cAddrInfo, addrinfo_s_allocate);
|
||||
rb_define_method(rb_cAddrInfo, "initialize", addrinfo_initialize, -1);
|
||||
rb_define_method(rb_cAddrInfo, "inspect", addrinfo_inspect, 0);
|
||||
rb_define_method(rb_cAddrInfo, "inspect_sockaddr", addrinfo_inspect_sockaddr, 0);
|
||||
rb_define_singleton_method(rb_cAddrInfo, "getaddrinfo", addrinfo_s_getaddrinfo, -1);
|
||||
rb_define_singleton_method(rb_cAddrInfo, "ip", addrinfo_s_ip, 1);
|
||||
rb_define_singleton_method(rb_cAddrInfo, "tcp", addrinfo_s_tcp, 2);
|
||||
rb_define_singleton_method(rb_cAddrInfo, "udp", addrinfo_s_udp, 2);
|
||||
rb_cAddrinfo = rb_define_class("Addrinfo", rb_cData);
|
||||
rb_define_alloc_func(rb_cAddrinfo, addrinfo_s_allocate);
|
||||
rb_define_method(rb_cAddrinfo, "initialize", addrinfo_initialize, -1);
|
||||
rb_define_method(rb_cAddrinfo, "inspect", addrinfo_inspect, 0);
|
||||
rb_define_method(rb_cAddrinfo, "inspect_sockaddr", addrinfo_inspect_sockaddr, 0);
|
||||
rb_define_singleton_method(rb_cAddrinfo, "getaddrinfo", addrinfo_s_getaddrinfo, -1);
|
||||
rb_define_singleton_method(rb_cAddrinfo, "ip", addrinfo_s_ip, 1);
|
||||
rb_define_singleton_method(rb_cAddrinfo, "tcp", addrinfo_s_tcp, 2);
|
||||
rb_define_singleton_method(rb_cAddrinfo, "udp", addrinfo_s_udp, 2);
|
||||
#ifdef HAVE_SYS_UN_H
|
||||
rb_define_singleton_method(rb_cAddrInfo, "unix", addrinfo_s_unix, 1);
|
||||
rb_define_singleton_method(rb_cAddrinfo, "unix", addrinfo_s_unix, 1);
|
||||
#endif
|
||||
|
||||
rb_define_method(rb_cAddrInfo, "afamily", addrinfo_afamily, 0);
|
||||
rb_define_method(rb_cAddrInfo, "pfamily", addrinfo_pfamily, 0);
|
||||
rb_define_method(rb_cAddrInfo, "socktype", addrinfo_socktype, 0);
|
||||
rb_define_method(rb_cAddrInfo, "protocol", addrinfo_protocol, 0);
|
||||
rb_define_method(rb_cAddrInfo, "canonname", addrinfo_canonname, 0);
|
||||
rb_define_method(rb_cAddrinfo, "afamily", addrinfo_afamily, 0);
|
||||
rb_define_method(rb_cAddrinfo, "pfamily", addrinfo_pfamily, 0);
|
||||
rb_define_method(rb_cAddrinfo, "socktype", addrinfo_socktype, 0);
|
||||
rb_define_method(rb_cAddrinfo, "protocol", addrinfo_protocol, 0);
|
||||
rb_define_method(rb_cAddrinfo, "canonname", addrinfo_canonname, 0);
|
||||
|
||||
rb_define_method(rb_cAddrInfo, "ipv4?", addrinfo_ipv4_p, 0);
|
||||
rb_define_method(rb_cAddrInfo, "ipv6?", addrinfo_ipv6_p, 0);
|
||||
rb_define_method(rb_cAddrInfo, "unix?", addrinfo_unix_p, 0);
|
||||
rb_define_method(rb_cAddrinfo, "ipv4?", addrinfo_ipv4_p, 0);
|
||||
rb_define_method(rb_cAddrinfo, "ipv6?", addrinfo_ipv6_p, 0);
|
||||
rb_define_method(rb_cAddrinfo, "unix?", addrinfo_unix_p, 0);
|
||||
|
||||
rb_define_method(rb_cAddrInfo, "ip?", addrinfo_ip_p, 0);
|
||||
rb_define_method(rb_cAddrInfo, "ip_unpack", addrinfo_ip_unpack, 0);
|
||||
rb_define_method(rb_cAddrInfo, "ip_address", addrinfo_ip_address, 0);
|
||||
rb_define_method(rb_cAddrInfo, "ip_port", addrinfo_ip_port, 0);
|
||||
rb_define_method(rb_cAddrinfo, "ip?", addrinfo_ip_p, 0);
|
||||
rb_define_method(rb_cAddrinfo, "ip_unpack", addrinfo_ip_unpack, 0);
|
||||
rb_define_method(rb_cAddrinfo, "ip_address", addrinfo_ip_address, 0);
|
||||
rb_define_method(rb_cAddrinfo, "ip_port", addrinfo_ip_port, 0);
|
||||
|
||||
rb_define_method(rb_cAddrInfo, "ipv4_private?", addrinfo_ipv4_private_p, 0);
|
||||
rb_define_method(rb_cAddrInfo, "ipv4_loopback?", addrinfo_ipv4_loopback_p, 0);
|
||||
rb_define_method(rb_cAddrInfo, "ipv4_multicast?", addrinfo_ipv4_multicast_p, 0);
|
||||
rb_define_method(rb_cAddrinfo, "ipv4_private?", addrinfo_ipv4_private_p, 0);
|
||||
rb_define_method(rb_cAddrinfo, "ipv4_loopback?", addrinfo_ipv4_loopback_p, 0);
|
||||
rb_define_method(rb_cAddrinfo, "ipv4_multicast?", addrinfo_ipv4_multicast_p, 0);
|
||||
|
||||
#ifdef INET6
|
||||
rb_define_method(rb_cAddrInfo, "ipv6_unspecified?", addrinfo_ipv6_unspecified_p, 0);
|
||||
rb_define_method(rb_cAddrInfo, "ipv6_loopback?", addrinfo_ipv6_loopback_p, 0);
|
||||
rb_define_method(rb_cAddrInfo, "ipv6_multicast?", addrinfo_ipv6_multicast_p, 0);
|
||||
rb_define_method(rb_cAddrInfo, "ipv6_linklocal?", addrinfo_ipv6_linklocal_p, 0);
|
||||
rb_define_method(rb_cAddrInfo, "ipv6_sitelocal?", addrinfo_ipv6_sitelocal_p, 0);
|
||||
rb_define_method(rb_cAddrInfo, "ipv6_v4mapped?", addrinfo_ipv6_v4mapped_p, 0);
|
||||
rb_define_method(rb_cAddrInfo, "ipv6_v4compat?", addrinfo_ipv6_v4compat_p, 0);
|
||||
rb_define_method(rb_cAddrInfo, "ipv6_mc_nodelocal?", addrinfo_ipv6_mc_nodelocal_p, 0);
|
||||
rb_define_method(rb_cAddrInfo, "ipv6_mc_linklocal?", addrinfo_ipv6_mc_linklocal_p, 0);
|
||||
rb_define_method(rb_cAddrInfo, "ipv6_mc_sitelocal?", addrinfo_ipv6_mc_sitelocal_p, 0);
|
||||
rb_define_method(rb_cAddrInfo, "ipv6_mc_orglocal?", addrinfo_ipv6_mc_orglocal_p, 0);
|
||||
rb_define_method(rb_cAddrInfo, "ipv6_mc_global?", addrinfo_ipv6_mc_global_p, 0);
|
||||
rb_define_method(rb_cAddrinfo, "ipv6_unspecified?", addrinfo_ipv6_unspecified_p, 0);
|
||||
rb_define_method(rb_cAddrinfo, "ipv6_loopback?", addrinfo_ipv6_loopback_p, 0);
|
||||
rb_define_method(rb_cAddrinfo, "ipv6_multicast?", addrinfo_ipv6_multicast_p, 0);
|
||||
rb_define_method(rb_cAddrinfo, "ipv6_linklocal?", addrinfo_ipv6_linklocal_p, 0);
|
||||
rb_define_method(rb_cAddrinfo, "ipv6_sitelocal?", addrinfo_ipv6_sitelocal_p, 0);
|
||||
rb_define_method(rb_cAddrinfo, "ipv6_v4mapped?", addrinfo_ipv6_v4mapped_p, 0);
|
||||
rb_define_method(rb_cAddrinfo, "ipv6_v4compat?", addrinfo_ipv6_v4compat_p, 0);
|
||||
rb_define_method(rb_cAddrinfo, "ipv6_mc_nodelocal?", addrinfo_ipv6_mc_nodelocal_p, 0);
|
||||
rb_define_method(rb_cAddrinfo, "ipv6_mc_linklocal?", addrinfo_ipv6_mc_linklocal_p, 0);
|
||||
rb_define_method(rb_cAddrinfo, "ipv6_mc_sitelocal?", addrinfo_ipv6_mc_sitelocal_p, 0);
|
||||
rb_define_method(rb_cAddrinfo, "ipv6_mc_orglocal?", addrinfo_ipv6_mc_orglocal_p, 0);
|
||||
rb_define_method(rb_cAddrinfo, "ipv6_mc_global?", addrinfo_ipv6_mc_global_p, 0);
|
||||
|
||||
rb_define_method(rb_cAddrInfo, "ipv6_to_ipv4", addrinfo_ipv6_to_ipv4, 0);
|
||||
rb_define_method(rb_cAddrinfo, "ipv6_to_ipv4", addrinfo_ipv6_to_ipv4, 0);
|
||||
#endif
|
||||
|
||||
#ifdef HAVE_SYS_UN_H
|
||||
rb_define_method(rb_cAddrInfo, "unix_path", addrinfo_unix_path, 0);
|
||||
rb_define_method(rb_cAddrinfo, "unix_path", addrinfo_unix_path, 0);
|
||||
#endif
|
||||
|
||||
rb_define_method(rb_cAddrInfo, "to_sockaddr", addrinfo_to_sockaddr, 0);
|
||||
rb_define_method(rb_cAddrInfo, "to_s", addrinfo_to_sockaddr, 0); /* compatibility for ruby before 1.9.2 */
|
||||
rb_define_method(rb_cAddrinfo, "to_sockaddr", addrinfo_to_sockaddr, 0);
|
||||
rb_define_method(rb_cAddrinfo, "to_s", addrinfo_to_sockaddr, 0); /* compatibility for ruby before 1.9.2 */
|
||||
|
||||
rb_define_method(rb_cAddrInfo, "getnameinfo", addrinfo_getnameinfo, -1);
|
||||
rb_define_method(rb_cAddrinfo, "getnameinfo", addrinfo_getnameinfo, -1);
|
||||
|
||||
rb_define_method(rb_cAddrInfo, "marshal_dump", addrinfo_mdump, 0);
|
||||
rb_define_method(rb_cAddrInfo, "marshal_load", addrinfo_mload, 1);
|
||||
rb_define_method(rb_cAddrinfo, "marshal_dump", addrinfo_mdump, 0);
|
||||
rb_define_method(rb_cAddrinfo, "marshal_load", addrinfo_mload, 1);
|
||||
}
|
||||
|
|
|
@ -158,7 +158,7 @@ extern VALUE rb_cUNIXSocket;
|
|||
extern VALUE rb_cUNIXServer;
|
||||
#endif
|
||||
extern VALUE rb_cSocket;
|
||||
extern VALUE rb_cAddrInfo;
|
||||
extern VALUE rb_cAddrinfo;
|
||||
extern VALUE rb_cSockOpt;
|
||||
|
||||
extern VALUE rb_eSocket;
|
||||
|
|
|
@ -674,13 +674,13 @@ sock_recvfrom_nonblock(int argc, VALUE *argv, VALUE sock)
|
|||
* socket.accept => [client_socket, client_addrinfo]
|
||||
*
|
||||
* Accepts a next connection.
|
||||
* Returns a new Socket object and AddrInfo object.
|
||||
* Returns a new Socket object and Addrinfo object.
|
||||
*
|
||||
* serv = Socket.new(:INET, :STREAM, 0)
|
||||
* serv.listen(5)
|
||||
* c = Socket.new(:INET, :STREAM, 0)
|
||||
* c.connect(serv.local_address)
|
||||
* p serv.accept #=> [#<Socket:fd 6>, #<AddrInfo: 127.0.0.1:48555 TCP>]
|
||||
* p serv.accept #=> [#<Socket:fd 6>, #<Addrinfo: 127.0.0.1:48555 TCP>]
|
||||
*
|
||||
*/
|
||||
static VALUE
|
||||
|
@ -1442,12 +1442,12 @@ sockaddr_obj(struct sockaddr *addr)
|
|||
*
|
||||
* Returns local IP addresses as an array.
|
||||
*
|
||||
* The array contains AddrInfo objects.
|
||||
* The array contains Addrinfo objects.
|
||||
*
|
||||
* pp Socket.ip_address_list
|
||||
* #=> [#<AddrInfo: 127.0.0.1>,
|
||||
* #<AddrInfo: 192.168.0.128>,
|
||||
* #<AddrInfo: ::1>,
|
||||
* #=> [#<Addrinfo: 127.0.0.1>,
|
||||
* #<Addrinfo: 192.168.0.128>,
|
||||
* #<Addrinfo: ::1>,
|
||||
* ...]
|
||||
*
|
||||
*/
|
||||
|
|
|
@ -129,11 +129,11 @@ unix_path(VALUE sock)
|
|||
* _flags_ should be a bitwise OR of Socket::MSG_* constants.
|
||||
*
|
||||
* s1 = Socket.new(:UNIX, :DGRAM, 0)
|
||||
* s1_ai = AddrInfo.unix("/tmp/sock1")
|
||||
* s1_ai = Addrinfo.unix("/tmp/sock1")
|
||||
* s1.bind(s1_ai)
|
||||
*
|
||||
* s2 = Socket.new(:UNIX, :DGRAM, 0)
|
||||
* s2_ai = AddrInfo.unix("/tmp/sock2")
|
||||
* s2_ai = Addrinfo.unix("/tmp/sock2")
|
||||
* s2.bind(s2_ai)
|
||||
* s3 = UNIXSocket.for_fd(s2.fileno)
|
||||
*
|
||||
|
|
|
@ -5,23 +5,23 @@ end
|
|||
|
||||
require "test/unit"
|
||||
|
||||
class TestSocketAddrInfo < Test::Unit::TestCase
|
||||
class TestSocketAddrinfo < Test::Unit::TestCase
|
||||
HAS_UNIXSOCKET = defined?(UNIXSocket) && /cygwin/ !~ RUBY_PLATFORM
|
||||
|
||||
def tcp_unspecified_to_loopback(addrinfo)
|
||||
if addrinfo.ipv4? && addrinfo.ip_address == "0.0.0.0"
|
||||
AddrInfo.tcp("127.0.0.1", addrinfo.ip_port)
|
||||
Addrinfo.tcp("127.0.0.1", addrinfo.ip_port)
|
||||
elsif addrinfo.ipv6? && addrinfo.ipv6_unspecified?
|
||||
AddrInfo.tcp("::1", addrinfo.ip_port)
|
||||
Addrinfo.tcp("::1", addrinfo.ip_port)
|
||||
elsif addrinfo.ipv6? && (ai = addrinfo.ipv6_to_ipv4) && ai.ip_address == "0.0.0.0"
|
||||
AddrInfo.tcp("127.0.0.1", addrinfo.ip_port)
|
||||
Addrinfo.tcp("127.0.0.1", addrinfo.ip_port)
|
||||
else
|
||||
addrinfo
|
||||
end
|
||||
end
|
||||
|
||||
def test_addrinfo_ip
|
||||
ai = AddrInfo.ip("127.0.0.1")
|
||||
ai = Addrinfo.ip("127.0.0.1")
|
||||
assert_equal([0, "127.0.0.1"], Socket.unpack_sockaddr_in(ai))
|
||||
assert_equal(Socket::AF_INET, ai.afamily)
|
||||
assert_equal(Socket::PF_INET, ai.pfamily)
|
||||
|
@ -30,7 +30,7 @@ class TestSocketAddrInfo < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_addrinfo_tcp
|
||||
ai = AddrInfo.tcp("127.0.0.1", 80)
|
||||
ai = Addrinfo.tcp("127.0.0.1", 80)
|
||||
assert_equal([80, "127.0.0.1"], Socket.unpack_sockaddr_in(ai))
|
||||
assert_equal(Socket::AF_INET, ai.afamily)
|
||||
assert_equal(Socket::PF_INET, ai.pfamily)
|
||||
|
@ -39,7 +39,7 @@ class TestSocketAddrInfo < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_addrinfo_udp
|
||||
ai = AddrInfo.udp("127.0.0.1", 80)
|
||||
ai = Addrinfo.udp("127.0.0.1", 80)
|
||||
assert_equal([80, "127.0.0.1"], Socket.unpack_sockaddr_in(ai))
|
||||
assert_equal(Socket::AF_INET, ai.afamily)
|
||||
assert_equal(Socket::PF_INET, ai.pfamily)
|
||||
|
@ -48,19 +48,19 @@ class TestSocketAddrInfo < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_addrinfo_ip_unpack
|
||||
ai = AddrInfo.tcp("127.0.0.1", 80)
|
||||
ai = Addrinfo.tcp("127.0.0.1", 80)
|
||||
assert_equal(["127.0.0.1", 80], ai.ip_unpack)
|
||||
assert_equal("127.0.0.1", ai.ip_address)
|
||||
assert_equal(80, ai.ip_port)
|
||||
end
|
||||
|
||||
def test_addrinfo_inspect_sockaddr
|
||||
ai = AddrInfo.tcp("127.0.0.1", 80)
|
||||
ai = Addrinfo.tcp("127.0.0.1", 80)
|
||||
assert_equal("127.0.0.1:80", ai.inspect_sockaddr)
|
||||
end
|
||||
|
||||
def test_addrinfo_new_inet
|
||||
ai = AddrInfo.new(["AF_INET", 46102, "localhost.localdomain", "127.0.0.2"])
|
||||
ai = Addrinfo.new(["AF_INET", 46102, "localhost.localdomain", "127.0.0.2"])
|
||||
assert_equal([46102, "127.0.0.2"], Socket.unpack_sockaddr_in(ai))
|
||||
assert_equal(Socket::AF_INET, ai.afamily)
|
||||
assert_equal(Socket::PF_INET, ai.pfamily)
|
||||
|
@ -69,7 +69,7 @@ class TestSocketAddrInfo < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_addrinfo_predicates
|
||||
ipv4_ai = AddrInfo.new(Socket.sockaddr_in(80, "192.168.0.1"))
|
||||
ipv4_ai = Addrinfo.new(Socket.sockaddr_in(80, "192.168.0.1"))
|
||||
assert(ipv4_ai.ip?)
|
||||
assert(ipv4_ai.ipv4?)
|
||||
assert(!ipv4_ai.ipv6?)
|
||||
|
@ -86,10 +86,10 @@ class TestSocketAddrInfo < Test::Unit::TestCase
|
|||
]
|
||||
list.each {|meth, *addrs|
|
||||
addrs.each {|addr|
|
||||
assert(AddrInfo.ip(addr).send(meth), "AddrInfo.ip(#{addr.inspect}).#{meth}")
|
||||
assert(Addrinfo.ip(addr).send(meth), "Addrinfo.ip(#{addr.inspect}).#{meth}")
|
||||
list.each {|meth2,|
|
||||
next if meth == meth2
|
||||
assert(!AddrInfo.ip(addr).send(meth2), "!AddrInfo.ip(#{addr.inspect}).#{meth2}")
|
||||
assert(!Addrinfo.ip(addr).send(meth2), "!Addrinfo.ip(#{addr.inspect}).#{meth2}")
|
||||
}
|
||||
}
|
||||
}
|
||||
|
@ -99,7 +99,7 @@ class TestSocketAddrInfo < Test::Unit::TestCase
|
|||
s1 = Socket.new(:INET, :DGRAM, 0)
|
||||
s1.bind(Socket.sockaddr_in(0, "127.0.0.1"))
|
||||
sa = s1.getsockname
|
||||
ai = AddrInfo.new(sa)
|
||||
ai = Addrinfo.new(sa)
|
||||
s2 = Socket.new(:INET, :DGRAM, 0)
|
||||
s2.send("test-basicsocket-send", 0, ai)
|
||||
assert_equal("test-basicsocket-send", s1.recv(100))
|
||||
|
@ -111,7 +111,7 @@ class TestSocketAddrInfo < Test::Unit::TestCase
|
|||
def test_udpsocket_send
|
||||
s1 = UDPSocket.new
|
||||
s1.bind("127.0.0.1", 0)
|
||||
ai = AddrInfo.new(s1.getsockname)
|
||||
ai = Addrinfo.new(s1.getsockname)
|
||||
s2 = UDPSocket.new
|
||||
s2.send("test-udp-send", 0, ai)
|
||||
assert_equal("test-udp-send", s1.recv(100))
|
||||
|
@ -123,7 +123,7 @@ class TestSocketAddrInfo < Test::Unit::TestCase
|
|||
def test_socket_bind
|
||||
s1 = Socket.new(:INET, :DGRAM, 0)
|
||||
sa = Socket.sockaddr_in(0, "127.0.0.1")
|
||||
ai = AddrInfo.new(sa)
|
||||
ai = Addrinfo.new(sa)
|
||||
s1.bind(ai)
|
||||
s2 = UDPSocket.new
|
||||
s2.send("test-socket-bind", 0, s1.getsockname)
|
||||
|
@ -137,7 +137,7 @@ class TestSocketAddrInfo < Test::Unit::TestCase
|
|||
s1 = Socket.new(:INET, :STREAM, 0)
|
||||
s1.bind(Socket.sockaddr_in(0, "127.0.0.1"))
|
||||
s1.listen(5)
|
||||
ai = AddrInfo.new(s1.getsockname)
|
||||
ai = Addrinfo.new(s1.getsockname)
|
||||
s2 = Socket.new(:INET, :STREAM, 0)
|
||||
s2.connect(ai)
|
||||
s3, sender_addr = s1.accept
|
||||
|
@ -153,7 +153,7 @@ class TestSocketAddrInfo < Test::Unit::TestCase
|
|||
s1 = Socket.new(:INET, :STREAM, 0)
|
||||
s1.bind(Socket.sockaddr_in(0, "127.0.0.1"))
|
||||
s1.listen(5)
|
||||
ai = AddrInfo.new(s1.getsockname)
|
||||
ai = Addrinfo.new(s1.getsockname)
|
||||
s2 = Socket.new(:INET, :STREAM, 0)
|
||||
begin
|
||||
s2.connect_nonblock(ai)
|
||||
|
@ -174,7 +174,7 @@ class TestSocketAddrInfo < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_socket_getnameinfo
|
||||
ai = AddrInfo.udp("127.0.0.1", 8888)
|
||||
ai = Addrinfo.udp("127.0.0.1", 8888)
|
||||
assert_equal(["127.0.0.1", "8888"], Socket.getnameinfo(ai, Socket::NI_NUMERICHOST|Socket::NI_NUMERICSERV))
|
||||
end
|
||||
|
||||
|
@ -218,7 +218,7 @@ class TestSocketAddrInfo < Test::Unit::TestCase
|
|||
s, ai = ret
|
||||
assert_kind_of(Array, ret)
|
||||
assert_equal(2, ret.length)
|
||||
assert_kind_of(AddrInfo, ai)
|
||||
assert_kind_of(Addrinfo, ai)
|
||||
e = Socket.unpack_sockaddr_in(c.getsockname)
|
||||
a = Socket.unpack_sockaddr_in(ai.to_sockaddr)
|
||||
assert_equal(e, a)
|
||||
|
@ -243,7 +243,7 @@ class TestSocketAddrInfo < Test::Unit::TestCase
|
|||
s, ai = ret
|
||||
assert_kind_of(Array, ret)
|
||||
assert_equal(2, ret.length)
|
||||
assert_kind_of(AddrInfo, ai)
|
||||
assert_kind_of(Addrinfo, ai)
|
||||
e = Socket.unpack_sockaddr_in(c.getsockname)
|
||||
a = Socket.unpack_sockaddr_in(ai.to_sockaddr)
|
||||
assert_equal(e, a)
|
||||
|
@ -264,7 +264,7 @@ class TestSocketAddrInfo < Test::Unit::TestCase
|
|||
s = IO.new(fd)
|
||||
assert_kind_of(Array, ret)
|
||||
assert_equal(2, ret.length)
|
||||
assert_kind_of(AddrInfo, ai)
|
||||
assert_kind_of(Addrinfo, ai)
|
||||
e = Socket.unpack_sockaddr_in(c.getsockname)
|
||||
a = Socket.unpack_sockaddr_in(ai.to_sockaddr)
|
||||
assert_equal(e, a)
|
||||
|
@ -282,7 +282,7 @@ class TestSocketAddrInfo < Test::Unit::TestCase
|
|||
s2.send("test-socket-recvfrom", 0, s1.getsockname)
|
||||
data, ai = s1.recvfrom(100)
|
||||
assert_equal("test-socket-recvfrom", data)
|
||||
assert_kind_of(AddrInfo, ai)
|
||||
assert_kind_of(Addrinfo, ai)
|
||||
e = Socket.unpack_sockaddr_in(s2.getsockname)
|
||||
a = Socket.unpack_sockaddr_in(ai.to_sockaddr)
|
||||
assert_equal(e, a)
|
||||
|
@ -304,7 +304,7 @@ class TestSocketAddrInfo < Test::Unit::TestCase
|
|||
retry
|
||||
end
|
||||
assert_equal("test-socket-recvfrom", data)
|
||||
assert_kind_of(AddrInfo, ai)
|
||||
assert_kind_of(Addrinfo, ai)
|
||||
e = Socket.unpack_sockaddr_in(s2.getsockname)
|
||||
a = Socket.unpack_sockaddr_in(ai.to_sockaddr)
|
||||
assert_equal(e, a)
|
||||
|
@ -314,10 +314,10 @@ class TestSocketAddrInfo < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_family_addrinfo
|
||||
ai = AddrInfo.tcp("0.0.0.0", 4649).family_addrinfo("www.ruby-lang.org", 80)
|
||||
ai = Addrinfo.tcp("0.0.0.0", 4649).family_addrinfo("www.ruby-lang.org", 80)
|
||||
assert_equal(["221.186.184.68", 80], ai.ip_unpack)
|
||||
assert_equal(Socket::SOCK_STREAM, ai.socktype)
|
||||
ai = AddrInfo.unix("/tmp/sock").family_addrinfo("/tmp/sock2")
|
||||
ai = Addrinfo.unix("/tmp/sock").family_addrinfo("/tmp/sock2")
|
||||
assert_equal("/tmp/sock2", ai.unix_path)
|
||||
assert_equal(Socket::SOCK_STREAM, ai.socktype)
|
||||
end
|
||||
|
@ -330,7 +330,7 @@ class TestSocketAddrInfo < Test::Unit::TestCase
|
|||
|
||||
def test_connect_from
|
||||
TCPServer.open("0.0.0.0", 0) {|serv|
|
||||
serv_ai = AddrInfo.new(serv.getsockname, :INET, :STREAM)
|
||||
serv_ai = Addrinfo.new(serv.getsockname, :INET, :STREAM)
|
||||
serv_ai = tcp_unspecified_to_loopback(serv_ai)
|
||||
port = random_port
|
||||
begin
|
||||
|
@ -350,10 +350,10 @@ class TestSocketAddrInfo < Test::Unit::TestCase
|
|||
|
||||
def test_connect_to
|
||||
TCPServer.open("0.0.0.0", 0) {|serv|
|
||||
serv_ai = AddrInfo.new(serv.getsockname, :INET, :STREAM)
|
||||
serv_ai = Addrinfo.new(serv.getsockname, :INET, :STREAM)
|
||||
serv_ai = tcp_unspecified_to_loopback(serv_ai)
|
||||
port = random_port
|
||||
client_ai = AddrInfo.tcp("0.0.0.0", port)
|
||||
client_ai = Addrinfo.tcp("0.0.0.0", port)
|
||||
begin
|
||||
client_ai.connect_to(*serv_ai.ip_unpack) {|s1|
|
||||
s2 = serv.accept
|
||||
|
@ -371,7 +371,7 @@ class TestSocketAddrInfo < Test::Unit::TestCase
|
|||
|
||||
def test_connect
|
||||
TCPServer.open("0.0.0.0", 0) {|serv|
|
||||
serv_ai = AddrInfo.new(serv.getsockname, :INET, :STREAM)
|
||||
serv_ai = Addrinfo.new(serv.getsockname, :INET, :STREAM)
|
||||
serv_ai = tcp_unspecified_to_loopback(serv_ai)
|
||||
begin
|
||||
serv_ai.connect {|s1|
|
||||
|
@ -391,7 +391,7 @@ class TestSocketAddrInfo < Test::Unit::TestCase
|
|||
|
||||
def test_bind
|
||||
port = random_port
|
||||
client_ai = AddrInfo.tcp("0.0.0.0", port)
|
||||
client_ai = Addrinfo.tcp("0.0.0.0", port)
|
||||
begin
|
||||
client_ai.bind {|s|
|
||||
assert_equal(port, s.local_address.ip_port)
|
||||
|
@ -403,7 +403,7 @@ class TestSocketAddrInfo < Test::Unit::TestCase
|
|||
|
||||
def test_listen
|
||||
port = random_port
|
||||
client_ai = AddrInfo.tcp("0.0.0.0", port)
|
||||
client_ai = Addrinfo.tcp("0.0.0.0", port)
|
||||
begin
|
||||
client_ai.listen {|serv|
|
||||
assert_equal(port, serv.local_address.ip_port)
|
||||
|
@ -426,13 +426,13 @@ class TestSocketAddrInfo < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_s_foreach
|
||||
AddrInfo.foreach(nil, 80, nil, :STREAM) {|ai|
|
||||
assert_kind_of(AddrInfo, ai)
|
||||
Addrinfo.foreach(nil, 80, nil, :STREAM) {|ai|
|
||||
assert_kind_of(Addrinfo, ai)
|
||||
}
|
||||
end
|
||||
|
||||
def test_marshal
|
||||
ai1 = AddrInfo.tcp("127.0.0.1", 80)
|
||||
ai1 = Addrinfo.tcp("127.0.0.1", 80)
|
||||
ai2 = Marshal.load(Marshal.dump(ai1))
|
||||
assert_equal(ai1.afamily, ai2.afamily)
|
||||
assert_equal(ai1.ip_unpack, ai2.ip_unpack)
|
||||
|
@ -445,7 +445,7 @@ class TestSocketAddrInfo < Test::Unit::TestCase
|
|||
if Socket.const_defined?("AF_INET6")
|
||||
|
||||
def test_addrinfo_new_inet6
|
||||
ai = AddrInfo.new(["AF_INET6", 42304, "ip6-localhost", "::1"])
|
||||
ai = Addrinfo.new(["AF_INET6", 42304, "ip6-localhost", "::1"])
|
||||
assert_equal([42304, "::1"], Socket.unpack_sockaddr_in(ai))
|
||||
assert_equal(Socket::AF_INET6, ai.afamily)
|
||||
assert_equal(Socket::PF_INET6, ai.pfamily)
|
||||
|
@ -454,19 +454,19 @@ class TestSocketAddrInfo < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_addrinfo_ip_unpack_inet6
|
||||
ai = AddrInfo.tcp("::1", 80)
|
||||
ai = Addrinfo.tcp("::1", 80)
|
||||
assert_equal(["::1", 80], ai.ip_unpack)
|
||||
assert_equal("::1", ai.ip_address)
|
||||
assert_equal(80, ai.ip_port)
|
||||
end
|
||||
|
||||
def test_addrinfo_inspect_sockaddr_inet6
|
||||
ai = AddrInfo.tcp("::1", 80)
|
||||
ai = Addrinfo.tcp("::1", 80)
|
||||
assert_equal("[::1]:80", ai.inspect_sockaddr)
|
||||
end
|
||||
|
||||
def test_marshal_inet6
|
||||
ai1 = AddrInfo.tcp("::1", 80)
|
||||
ai1 = Addrinfo.tcp("::1", 80)
|
||||
ai2 = Marshal.load(Marshal.dump(ai1))
|
||||
assert_equal(ai1.afamily, ai2.afamily)
|
||||
assert_equal(ai1.ip_unpack, ai2.ip_unpack)
|
||||
|
@ -477,7 +477,7 @@ class TestSocketAddrInfo < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def ipv6(str)
|
||||
AddrInfo.getaddrinfo(str, nil, :INET6, :DGRAM).fetch(0)
|
||||
Addrinfo.getaddrinfo(str, nil, :INET6, :DGRAM).fetch(0)
|
||||
end
|
||||
|
||||
def test_ipv6_address_predicates
|
||||
|
@ -499,7 +499,7 @@ class TestSocketAddrInfo < Test::Unit::TestCase
|
|||
]
|
||||
list.each {|meth, *addrs|
|
||||
addrs.each {|addr|
|
||||
addr_exp = "AddrInfo.getaddrinfo(#{addr.inspect}, nil, :INET6, :DGRAM).fetch(0)"
|
||||
addr_exp = "Addrinfo.getaddrinfo(#{addr.inspect}, nil, :INET6, :DGRAM).fetch(0)"
|
||||
if meth == :ipv6_v4compat? || meth == :ipv6_v4mapped?
|
||||
# MacOS X returns IPv4 address for ::ffff:1.2.3.4 and ::1.2.3.4.
|
||||
# Solaris returns IPv4 address for ::ffff:1.2.3.4.
|
||||
|
@ -517,7 +517,7 @@ class TestSocketAddrInfo < Test::Unit::TestCase
|
|||
}
|
||||
mlist.each {|meth, *addrs|
|
||||
addrs.each {|addr|
|
||||
addr_exp = "AddrInfo.getaddrinfo(#{addr.inspect}, nil, :INET6, :DGRAM).fetch(0)"
|
||||
addr_exp = "Addrinfo.getaddrinfo(#{addr.inspect}, nil, :INET6, :DGRAM).fetch(0)"
|
||||
assert(ipv6(addr).send(meth), "#{addr_exp}.#{meth}")
|
||||
assert(ipv6(addr).ipv6_multicast?, "#{addr_exp}.ipv6_multicast?")
|
||||
mlist.each {|meth2,|
|
||||
|
@ -533,20 +533,20 @@ class TestSocketAddrInfo < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_ipv6_to_ipv4
|
||||
ai = AddrInfo.ip("::192.0.2.3")
|
||||
ai = Addrinfo.ip("::192.0.2.3")
|
||||
ai = ai.ipv6_to_ipv4 if !ai.ipv4?
|
||||
assert(ai.ipv4?)
|
||||
assert_equal("192.0.2.3", ai.ip_address)
|
||||
|
||||
ai = AddrInfo.ip("::ffff:192.0.2.3")
|
||||
ai = Addrinfo.ip("::ffff:192.0.2.3")
|
||||
ai = ai.ipv6_to_ipv4 if !ai.ipv4?
|
||||
assert(ai.ipv4?)
|
||||
assert_equal("192.0.2.3", ai.ip_address)
|
||||
|
||||
assert_nil(AddrInfo.ip("::1").ipv6_to_ipv4)
|
||||
assert_nil(AddrInfo.ip("192.0.2.3").ipv6_to_ipv4)
|
||||
assert_nil(Addrinfo.ip("::1").ipv6_to_ipv4)
|
||||
assert_nil(Addrinfo.ip("192.0.2.3").ipv6_to_ipv4)
|
||||
if HAS_UNIXSOCKET
|
||||
assert_nil(AddrInfo.unix("/tmp/sock").ipv6_to_ipv4)
|
||||
assert_nil(Addrinfo.unix("/tmp/sock").ipv6_to_ipv4)
|
||||
end
|
||||
end
|
||||
end
|
||||
|
@ -554,7 +554,7 @@ class TestSocketAddrInfo < Test::Unit::TestCase
|
|||
if HAS_UNIXSOCKET
|
||||
|
||||
def test_addrinfo_unix
|
||||
ai = AddrInfo.unix("/tmp/sock")
|
||||
ai = Addrinfo.unix("/tmp/sock")
|
||||
assert_equal("/tmp/sock", Socket.unpack_sockaddr_un(ai))
|
||||
assert_equal(Socket::AF_UNIX, ai.afamily)
|
||||
assert_equal(Socket::PF_UNIX, ai.pfamily)
|
||||
|
@ -563,17 +563,17 @@ class TestSocketAddrInfo < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_addrinfo_unix_path
|
||||
ai = AddrInfo.unix("/tmp/sock1")
|
||||
ai = Addrinfo.unix("/tmp/sock1")
|
||||
assert_equal("/tmp/sock1", ai.unix_path)
|
||||
end
|
||||
|
||||
def test_addrinfo_inspect_sockaddr_unix
|
||||
ai = AddrInfo.unix("/tmp/test_addrinfo_inspect_sockaddr_unix")
|
||||
ai = Addrinfo.unix("/tmp/test_addrinfo_inspect_sockaddr_unix")
|
||||
assert_equal("/tmp/test_addrinfo_inspect_sockaddr_unix", ai.inspect_sockaddr)
|
||||
end
|
||||
|
||||
def test_addrinfo_new_unix
|
||||
ai = AddrInfo.new(["AF_UNIX", "/tmp/sock"])
|
||||
ai = Addrinfo.new(["AF_UNIX", "/tmp/sock"])
|
||||
assert_equal("/tmp/sock", Socket.unpack_sockaddr_un(ai))
|
||||
assert_equal(Socket::AF_UNIX, ai.afamily)
|
||||
assert_equal(Socket::PF_UNIX, ai.pfamily)
|
||||
|
@ -582,7 +582,7 @@ class TestSocketAddrInfo < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_addrinfo_predicates_unix
|
||||
unix_ai = AddrInfo.new(Socket.sockaddr_un("/tmp/sososo"))
|
||||
unix_ai = Addrinfo.new(Socket.sockaddr_un("/tmp/sososo"))
|
||||
assert(!unix_ai.ip?)
|
||||
assert(!unix_ai.ipv4?)
|
||||
assert(!unix_ai.ipv6?)
|
||||
|
@ -590,7 +590,7 @@ class TestSocketAddrInfo < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
def test_marshal_unix
|
||||
ai1 = AddrInfo.unix("/var/tmp/sock")
|
||||
ai1 = Addrinfo.unix("/var/tmp/sock")
|
||||
ai2 = Marshal.load(Marshal.dump(ai1))
|
||||
assert_equal(ai1.afamily, ai2.afamily)
|
||||
assert_equal(ai1.unix_path, ai2.unix_path)
|
||||
|
|
|
@ -68,18 +68,18 @@ class TestSocket < Test::Unit::TestCase
|
|||
return
|
||||
end
|
||||
list.each {|ai|
|
||||
assert_instance_of(AddrInfo, ai)
|
||||
assert_instance_of(Addrinfo, ai)
|
||||
assert(ai.ip?)
|
||||
}
|
||||
end
|
||||
|
||||
def tcp_unspecified_to_loopback(addrinfo)
|
||||
if addrinfo.ipv4? && addrinfo.ip_address == "0.0.0.0"
|
||||
AddrInfo.tcp("127.0.0.1", addrinfo.ip_port)
|
||||
Addrinfo.tcp("127.0.0.1", addrinfo.ip_port)
|
||||
elsif addrinfo.ipv6? && addrinfo.ipv6_unspecified?
|
||||
AddrInfo.tcp("::1", addrinfo.ip_port)
|
||||
Addrinfo.tcp("::1", addrinfo.ip_port)
|
||||
elsif addrinfo.ipv6? && (ai = addrinfo.ipv6_to_ipv4) && ai.ip_address == "0.0.0.0"
|
||||
AddrInfo.tcp("127.0.0.1", addrinfo.ip_port)
|
||||
Addrinfo.tcp("127.0.0.1", addrinfo.ip_port)
|
||||
else
|
||||
addrinfo
|
||||
end
|
||||
|
|
|
@ -123,7 +123,7 @@ class TestUNIXSocket < Test::Unit::TestCase
|
|||
else
|
||||
# struct msghdr is POSIX/4.4BSD style (msg_control field).
|
||||
assert_equal(0, flags & (Socket::MSG_TRUNC|Socket::MSG_CTRUNC))
|
||||
assert_instance_of(AddrInfo, srcaddr)
|
||||
assert_instance_of(Addrinfo, srcaddr)
|
||||
assert_instance_of(Array, ctls)
|
||||
assert_equal(1, ctls.length)
|
||||
assert_instance_of(Socket::AncillaryData, ctls[0])
|
||||
|
|
Loading…
Reference in a new issue