summaryrefslogtreecommitdiffhomepage
path: root/Network/DNS/Internal.hs
diff options
context:
space:
mode:
Diffstat (limited to 'Network/DNS/Internal.hs')
-rw-r--r--Network/DNS/Internal.hs93
1 files changed, 60 insertions, 33 deletions
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 {