tungd / elixir-dns

DNS library for Elixir
BSD 3-Clause "New" or "Revised" License
114 stars 37 forks source link

Example usage for other query types #25

Closed martinlevesque closed 5 years ago

martinlevesque commented 5 years ago

Hey,

I am wondering how to respond with other query types than the ones provided in the server example:

result =
      case query.type do
        :a -> {127, 0, 0, 1}
        :cname -> 'your.domain.com'
        :txt -> ['your txt value']
        _ -> nil
      end
...
resource = %DNS.Resource{
      domain: query.domain,
      class: query.class,
      type: query.type,
      ttl: 0,
      data: result
    }

For instance, I am looking to how to respond with :aaaa and :mx. Any idea/pointer? Couldn't find the erlang documentation.

Thanks

tungd commented 5 years ago

Hi, so sorry it's been a long time. The Erlang DNS module (hence this library) only provide the building block for running DNS client/server, specifically packet encoding and TCP server. You have the full freedom to construct the DNS packet yourself. To be able to work with it you'll need to take a look at the records definition in the module (https://github.com/blackberry/Erlang-OTP/blob/master/lib/kernel/src/inet_dns.hrl#L176), or consult the DNS specification. In your case, you'll need to change the %DNS.Resource type field to "aaaa" or "mx".

bortzmeyer commented 2 years ago

For AAAA, see an example in #44