summaryrefslogtreecommitdiffhomepage
path: root/Network
diff options
context:
space:
mode:
authorGravatar Kazu Yamamoto <kazu@iij.ad.jp>2010-03-18 12:05:07 +0900
committerGravatar Kazu Yamamoto <kazu@iij.ad.jp>2010-03-18 12:05:07 +0900
commit5bcd3435c5332376f7a33f91dfebd3a104043200 (patch)
treee30093ba3f5ba8380b29df379aabe1c18d2fd077 /Network
parentc28ccc6c8bf8354654b6828e75390d721c8b635e (diff)
documentation.
Diffstat (limited to 'Network')
-rw-r--r--Network/DNS.hs17
-rw-r--r--Network/DNS/Internal.hs93
-rw-r--r--Network/DNS/Types.hs18
3 files changed, 88 insertions, 40 deletions
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