Module: RubyDNS
- Defined in:
- lib/rubydns/version.rb,
lib/rubydns.rb,
lib/rubydns/server.rb,
lib/rubydns/handler.rb,
lib/rubydns/transaction.rb
Overview
Copyright © 2009, 2011 Samuel G. D. Williams. <www.oriontransfer.co.nz>
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the “Software”), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED “AS IS”, WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
Defined Under Namespace
Modules: TCPHandler, UDPHandler, VERSION Classes: LengthError, Server, Transaction
Class Method Summary collapse
-
.run_server(options = {}, &block) ⇒ Object
Run a server with the given rules.
Class Method Details
.run_server(options = {}, &block) ⇒ Object
Run a server with the given rules. A number of options can be supplied:
:interfaces
-
A set of sockets or addresses as defined below.
One important feature of DNS is the port it runs on. The options[:listen]
allows you to specify a set of network interfaces and ports to run the server on. This must be a list of [protocol, interface address, port]
.
INTERFACES = [[:udp, "0.0.0.0", 5300]]
RubyDNS::run_server(:listen => INTERFACES) do
...
end
You can specify already connected sockets if need be:
socket = UDPSocket.new; socket.bind("0.0.0.0", 53)
Process::Sys.setuid(server_uid)
INTERFACES = [socket]
The default interface is [[:udp, "0.0.0.0", 53]]
. The server typically needs to run as root for this to work, since port 53 is privileged.
64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 |
# File 'lib/rubydns.rb', line 64 def self.run_server ( = {}, &block) server = RubyDNS::Server.new(&block) server.logger.info "Starting RubyDNS server (v#{RubyDNS::VERSION::STRING})..." [:listen] ||= [[:udp, "0.0.0.0", 53], [:tcp, "0.0.0.0", 53]] EventMachine.run do server.fire(:setup) # Setup server sockets [:listen].each do |spec| server.logger.info "Listening on #{spec.join(':')}" if spec[0] == :udp EventMachine.open_datagram_socket(spec[1], spec[2], UDPHandler, server) elsif spec[0] == :tcp EventMachine.start_server(spec[1], spec[2], TCPHandler, server) end end server.fire(:start) end server.fire(:stop) end |