diff options
author | Mike Mackintosh <m@zyp.io> | 2015-03-22 17:08:04 -0400 |
---|---|---|
committer | Mike Mackintosh <m@zyp.io> | 2015-03-22 17:08:04 -0400 |
commit | f562a7f7a032b381cdc8b897ec50ed220bcc9452 (patch) | |
tree | 31be094880a5c37ddbd0b4ce2873e25b655153f0 /lib | |
parent | 4c759982e386e2ebdd99346c67caef3dce55e583 (diff) | |
download | ipaddress-f562a7f7a032b381cdc8b897ec50ed220bcc9452.tar.gz |
add multicast and loopback checks
Diffstat (limited to 'lib')
-rw-r--r-- | lib/ipaddress/ipv4.rb | 28 |
1 files changed, 28 insertions, 0 deletions
diff --git a/lib/ipaddress/ipv4.rb b/lib/ipaddress/ipv4.rb index 38afbb1..6437810 100644 --- a/lib/ipaddress/ipv4.rb +++ b/lib/ipaddress/ipv4.rb @@ -599,6 +599,34 @@ module IPAddress; end # + # Checks if an IPv4 address objects belongs + # to a multicast network RFC3171 + # + # Example: + # + # ip = IPAddress "224.0.0.0/4" + # ip.multicast? + # #=> true + # + def multicast? + [self.class.new("224.0.0.0/4")].any? {|i| i.include? self} + end + + # + # Checks if an IPv4 address objects belongs + # to a loopback network RFC1122 + # + # Example: + # + # ip = IPAddress "127.0.0.1" + # ip.loopback? + # #=> true + # + def loopback? + [self.class.new("127.0.0.0/8")].any? {|i| i.include? self} + end + + # # Returns the IP address in in-addr.arpa format # for DNS lookups # |