1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34
|
-- | DNS message encoder.
--
-- Note: 'Nework.DNS' is a client library, and its focus is on /sending/
-- /queries/, and /receiving/ /replies/. Thefore, while this module is
-- reasonably adept at query generation, building a DNS server with this
-- module requires additional work to handle message size limits, correct UDP
-- truncation, proper EDNS negotiation, and so on. Support for server-side DNS
-- is at best rudimentary.
--
-- For sending queries, in most cases you should be using one of the functions
-- from 'Network.DNS.Lookup' and 'Network.DNS.LookupRaw', or lastly, if you
-- want to handle the network reads and writes for yourself (with your own code
-- for UDP retries, TCP fallback, EDNS fallback, ...), then perhaps
-- 'Network.DNS.IO.encodeQuestion' (letting 'Network.DNS' do the lookups for
-- you in an @async@ thread is likely much simpler).
--
module Network.DNS.Encode (
-- * Encode a DNS query (or response).
encode
) where
import Network.DNS.Imports
import Network.DNS.StateBinary
import Network.DNS.Types.Internal
import Network.DNS.Encode.Builders
-- | Encode a 'DNSMessage' for transmission over UDP. For transmission over
-- TCP encapsulate the result via 'Network.DNS.IO.encodeVC', or use
-- 'Network.DNS.IO.sendVC', which handles this internally. If any
-- 'ResourceRecord' in the message contains incorrectly encoded 'Domain' name
-- ByteStrings, this function may raise a 'DecodeError'.
--
encode :: DNSMessage -> ByteString
encode = runSPut . putDNSMessage
|