From 5bcd3435c5332376f7a33f91dfebd3a104043200 Mon Sep 17 00:00:00 2001 From: Kazu Yamamoto Date: Thu, 18 Mar 2010 12:05:07 +0900 Subject: documentation. --- Network/DNS.hs | 17 +++++++++ Network/DNS/Internal.hs | 93 +++++++++++++++++++++++++++++++------------------ Network/DNS/Types.hs | 18 ++++++---- 3 files changed, 88 insertions(+), 40 deletions(-) (limited to 'Network') diff --git a/Network/DNS.hs b/Network/DNS.hs index 9f5653b..7c027f7 100644 --- a/Network/DNS.hs +++ b/Network/DNS.hs @@ -1,3 +1,20 @@ +{-| + DNS library written in Haskell. + + Currently, only resolver side is supported. This code is written in + Haskell, not using FFI. So, the \"-threaded\" option for GHC is not + necessary. + + Sample code: + +@ + import qualified Network.DNS as DNS (lookup) + import Network.DNS hiding (lookup) + main :: IO () + main = makeDefaultResolver >>= DNS.lookup "www.iij.ad.jp" A >>= print +@ +-} + module Network.DNS ( module Network.DNS.Types , module Network.DNS.Resolver diff --git a/Network/DNS/Internal.hs b/Network/DNS/Internal.hs index f29ed3e..ff1b6d7 100644 --- a/Network/DNS/Internal.hs +++ b/Network/DNS/Internal.hs @@ -6,6 +6,16 @@ import Data.Maybe ---------------------------------------------------------------- +{-| + Type for domain. +-} +type Domain = String + +---------------------------------------------------------------- + +{-| + Types for resource records. +-} data TYPE = A | AAAA | NS | TXT | MX | CNAME | SOA | UNKNOWN Int deriving (Eq, Show, Read) @@ -37,28 +47,71 @@ toType = read . map toUpper ---------------------------------------------------------------- -data QorR = QR_Query | QR_Response deriving (Eq, Show) +{-| + Raw data format for DNS Query and Response. +-} +data DNSFormat = DNSFormat { + header :: DNSHeader + , question :: [Question] + , answer :: [ResourceRecord] + , authority :: [ResourceRecord] + , additional :: [ResourceRecord] + } deriving (Eq, Show) -data OPCODE = OP_STD | OP_INV | OP_SSR deriving (Eq, Show, Enum) +{-| + Raw data format for the header of DNS Query and Response. +-} +data DNSHeader = DNSHeader { + identifier :: Int + , flags :: DNSFlags + , qdCount :: Int + , anCount :: Int + , nsCount :: Int + , arCount :: Int + } deriving (Eq, Show) -data RCODE = NoErr | FormatErr | ServFail | NameErr | NotImpl | Refused deriving (Eq, Show, Enum) +{-| + Raw data format for the flags of DNS Query and Response. +-} +data DNSFlags = DNSFlags { + qOrR :: QorR + , opcode :: OPCODE + , authAnswer :: Bool + , trunCation :: Bool + , recDesired :: Bool + , recAvailable :: Bool + , rcode :: RCODE + } deriving (Eq, Show) ---------------------------------------------------------------- -type Domain = String +data QorR = QR_Query | QR_Response deriving (Eq, Show) + +data OPCODE = OP_STD | OP_INV | OP_SSR deriving (Eq, Show, Enum) + +data RCODE = NoErr | FormatErr | ServFail | NameErr | NotImpl | Refused deriving (Eq, Show, Enum) ---------------------------------------------------------------- +{-| + Raw data format for DNS questions. +-} data Question = Question { qname :: Domain , qtype :: TYPE } deriving (Eq, Show) +{-| + Making "Question". +-} makeQuestion :: Domain -> TYPE -> Question makeQuestion dom typ = Question dom typ ---------------------------------------------------------------- +{-| + Raw data format for resource records. +-} data ResourceRecord = ResourceRecord { rrname :: Domain , rrtype :: TYPE @@ -67,6 +120,9 @@ data ResourceRecord = ResourceRecord { , rdata :: RDATA } deriving (Eq, Show) +{-| + Raw data format for each type. +-} data RDATA = RD_NS Domain | RD_CNAME Domain | RD_MX Int Domain | RD_SOA Domain Domain Int Int Int Int Int | RD_A IPv4 | RD_AAAA IPv6 @@ -83,35 +139,6 @@ instance Show RDATA where ---------------------------------------------------------------- -data DNSFlags = DNSFlags { - qOrR :: QorR - , opcode :: OPCODE - , authAnswer :: Bool - , trunCation :: Bool - , recDesired :: Bool - , recAvailable :: Bool - , rcode :: RCODE - } deriving (Eq, Show) - -data DNSHeader = DNSHeader { - identifier :: Int - , flags :: DNSFlags - , qdCount :: Int - , anCount :: Int - , nsCount :: Int - , arCount :: Int - } deriving (Eq, Show) - -data DNSFormat = DNSFormat { - header :: DNSHeader - , question :: [Question] - , answer :: [ResourceRecord] - , authority :: [ResourceRecord] - , additional :: [ResourceRecord] - } deriving (Eq, Show) - ----------------------------------------------------------------- - defaultQuery :: DNSFormat defaultQuery = DNSFormat { header = DNSHeader { diff --git a/Network/DNS/Types.hs b/Network/DNS/Types.hs index 906fc08..8b1fc7f 100644 --- a/Network/DNS/Types.hs +++ b/Network/DNS/Types.hs @@ -1,15 +1,19 @@ +{-| + Data types for DNS Query and Response. +-} + module Network.DNS.Types ( - TYPE (..), intToType, typeToInt, toType + Domain + , TYPE (..), intToType, typeToInt, toType + , DNSFormat, header, question, answer, authority, additional + , DNSHeader, identifier, flags, qdCount, anCount, nsCount, arCount + , DNSFlags, qOrR, opcode, authAnswer, trunCation, recDesired, recAvailable, rcode , QorR (..) , OPCODE (..) , RCODE (..) - , Domain - , Question (qname,qtype), makeQuestion - , ResourceRecord (rrname,rrtype,rrttl,rdlen,rdata) + , ResourceRecord, rrname, rrtype, rrttl, rdlen, rdata + , Question, qname, qtype, makeQuestion , RDATA (..) - , DNSFlags (qOrR,opcode,authAnswer,trunCation,recDesired,recAvailable,rcode) - , DNSHeader (identifier,flags,qdCount,anCount,nsCount,arCount) - , DNSFormat (header,question,answer,authority,additional) ) where import Network.DNS.Internal -- cgit v1.2.3