* lib/ipaddr.rb: Improve documentation. Patch by Sandor Szucs.
[Ruby 1.9 - Bug #4753] git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@31686 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
This commit is contained in:
parent
bb34bcbe47
commit
95e1fc5b4e
@ -1,3 +1,8 @@
|
|||||||
|
Sun May 22 11:21:41 2011 Eric Hodel <drbrain@segment7.net>
|
||||||
|
|
||||||
|
* lib/ipaddr.rb: Improve documentation. Patch by Sandor Szucs.
|
||||||
|
[Ruby 1.9 - Bug #4753]
|
||||||
|
|
||||||
Sun May 22 11:14:40 2011 Eric Hodel <drbrain@segment7.net>
|
Sun May 22 11:14:40 2011 Eric Hodel <drbrain@segment7.net>
|
||||||
|
|
||||||
* lib/forwardable.rb: Document def_delegator. Patch by Sandor Szucs.
|
* lib/forwardable.rb: Document def_delegator. Patch by Sandor Szucs.
|
||||||
|
@ -19,6 +19,7 @@ require 'socket'
|
|||||||
|
|
||||||
unless Socket.const_defined? "AF_INET6"
|
unless Socket.const_defined? "AF_INET6"
|
||||||
class Socket < BasicSocket
|
class Socket < BasicSocket
|
||||||
|
# IPv6 protocol family
|
||||||
AF_INET6 = Object.new
|
AF_INET6 = Object.new
|
||||||
end
|
end
|
||||||
|
|
||||||
@ -51,6 +52,14 @@ unless Socket.const_defined? "AF_INET6"
|
|||||||
end
|
end
|
||||||
|
|
||||||
alias getaddress_orig getaddress
|
alias getaddress_orig getaddress
|
||||||
|
|
||||||
|
# Returns a +String+ based representation of a valid DNS hostname,
|
||||||
|
# IPv4 or IPv6 address.
|
||||||
|
#
|
||||||
|
# IPSocket.getaddress 'localhost' #=> "::1"
|
||||||
|
# IPSocket.getaddress 'broadcasthost' #=> "255.255.255.255"
|
||||||
|
# IPSocket.getaddress 'www.ruby-lang.org' #=> "221.186.184.68"
|
||||||
|
# IPSocket.getaddress 'www.ccc.de' #=> "2a00:1328:e102:ccc0::122"
|
||||||
def getaddress(s)
|
def getaddress(s)
|
||||||
if valid?(s)
|
if valid?(s)
|
||||||
s
|
s
|
||||||
@ -86,8 +95,11 @@ end
|
|||||||
|
|
||||||
class IPAddr
|
class IPAddr
|
||||||
|
|
||||||
|
# 32 bit mask for IPv4
|
||||||
IN4MASK = 0xffffffff
|
IN4MASK = 0xffffffff
|
||||||
|
# 128 bit mask for IPv4
|
||||||
IN6MASK = 0xffffffffffffffffffffffffffffffff
|
IN6MASK = 0xffffffffffffffffffffffffffffffff
|
||||||
|
# Formatstring for IPv6
|
||||||
IN6FORMAT = (["%.4x"] * 8).join(':')
|
IN6FORMAT = (["%.4x"] * 8).join(':')
|
||||||
|
|
||||||
# Returns the address family of this IP address.
|
# Returns the address family of this IP address.
|
||||||
@ -377,6 +389,9 @@ class IPAddr
|
|||||||
|
|
||||||
protected
|
protected
|
||||||
|
|
||||||
|
# Set +@addr+, the internal stored ip address, to given +addr+. The
|
||||||
|
# parameter +addr+ is validated using the first +family+ member,
|
||||||
|
# which is +Socket::AF_INET+ or +Socket::AF_INET6+.
|
||||||
def set(addr, *family)
|
def set(addr, *family)
|
||||||
case family[0] ? family[0] : @family
|
case family[0] ? family[0] : @family
|
||||||
when Socket::AF_INET
|
when Socket::AF_INET
|
||||||
@ -397,6 +412,7 @@ class IPAddr
|
|||||||
return self
|
return self
|
||||||
end
|
end
|
||||||
|
|
||||||
|
# Set current netmask to given mask.
|
||||||
def mask!(mask)
|
def mask!(mask)
|
||||||
if mask.kind_of?(String)
|
if mask.kind_of?(String)
|
||||||
if mask =~ /^\d+$/
|
if mask =~ /^\d+$/
|
||||||
|
Loading…
x
Reference in New Issue
Block a user