Module: ReDNS::Support
Instance Method Summary collapse
- #addr_to_arpa(ip) ⇒ Object
- #bind_all_addr ⇒ Object
- #default_nameservers ⇒ Object
- #default_resolver_address ⇒ Object
- #dns_port ⇒ Object
- #inet_aton(s) ⇒ Object
- #inet_ntoa(addr) ⇒ Object
- #io_nonblock(nb = true, &block) ⇒ Object
- #io_nonblock?(io) ⇒ Boolean
- #io_set_nonblock(io, nb = true) ⇒ Object
- #is_ip?(address) ⇒ Boolean
Instance Method Details
#addr_to_arpa(ip) ⇒ Object
2 3 4 |
# File 'lib/redns/support.rb', line 2 def addr_to_arpa(ip) ip and (ip.split(/\./).reverse.join('.') + '.in-addr.arpa.') end |
#bind_all_addr ⇒ Object
44 45 46 |
# File 'lib/redns/support.rb', line 44 def bind_all_addr '0.0.0.0' end |
#default_nameservers ⇒ Object
56 57 58 |
# File 'lib/redns/support.rb', line 56 def default_nameservers ReDNS::Resolver.servers end |
#default_resolver_address ⇒ Object
60 61 62 |
# File 'lib/redns/support.rb', line 60 def default_resolver_address ReDNS::Resolver.servers.first end |
#dns_port ⇒ Object
52 53 54 |
# File 'lib/redns/support.rb', line 52 def dns_port 53 end |
#inet_aton(s) ⇒ Object
12 13 14 15 16 |
# File 'lib/redns/support.rb', line 12 def inet_aton(s) s.split(/\./).map do |c| c.to_i end.pack("C*") end |
#inet_ntoa(addr) ⇒ Object
6 7 8 9 10 |
# File 'lib/redns/support.rb', line 6 def inet_ntoa(addr) addr.unpack("C4")[0, 4].collect do |v| v or 0 end.join('.') end |
#io_nonblock(nb = true, &block) ⇒ Object
34 35 36 37 38 39 40 41 42 |
# File 'lib/redns/support.rb', line 34 def io_nonblock(nb = true, &block) flag = io_nonblock?(io) io_set_nonblock(io, nb) yield(block) ensure io_set_nonblock(io, flag) end |
#io_nonblock?(io) ⇒ Boolean
18 19 20 |
# File 'lib/redns/support.rb', line 18 def io_nonblock?(io) (io.fcntl(Fcntl::F_GETFL) & File::NONBLOCK) != 0 end |
#io_set_nonblock(io, nb = true) ⇒ Object
22 23 24 25 26 27 28 29 30 31 32 |
# File 'lib/redns/support.rb', line 22 def io_set_nonblock(io, nb = true) flags = io.fcntl(Fcntl::F_GETFL) if (nb) flags |= File::NONBLOCK else flags &= ~File::NONBLOCK end io.fcntl(Fcntl::F_SETFL, flags) end |
#is_ip?(address) ⇒ Boolean
48 49 50 |
# File 'lib/redns/support.rb', line 48 def is_ip?(address) address and address.match(/^\d+(\.\d+)+$/) end |