1 module Network.DNS.Message
16 import Data.Binary.BitPut
17 import Data.Binary.Get as G
18 import Data.Binary.Put
19 import Data.Binary.Strict.BitGet as BG
26 , msgQuestions :: ![Question]
27 , msgAnswers :: ![ResourceRecord]
28 , msgAuthorities :: ![ResourceRecord]
29 , msgAdditionals :: ![ResourceRecord]
34 hdMessageID :: !Word16
35 , hdMessageType :: !MessageType
37 , hdIsAuthoritativeAnswer :: !Bool
38 , hdIsTruncated :: !Bool
39 , hdIsRecursionDesired :: !Bool
40 , hdIsRecursionAvailable :: !Bool
41 , hdResponseCode :: !ResponseCode
43 -- These fields are supressed in this data structure:
73 , qType :: !RecordType
74 , qClass :: !RecordClass
78 type DomainName = [[Word8]]
85 | AnyClass -- Only for queries
91 , rrType :: !RecordType
92 , rrClass :: !RecordClass
123 instance Binary Header where
124 put h = do putWord16be $ hdMessageID h
125 putLazyByteString flags
128 do putNBits 1 $ fromEnum $ hdMessageType h
129 putNBits 4 $ fromEnum $ hdOpcode h
130 putBit $ hdIsAuthoritativeAnswer h
131 putBit $ hdIsTruncated h
132 putBit $ hdIsRecursionDesired h
133 putBit $ hdIsRecursionAvailable h
134 putNBits 3 (0 :: Int)
135 putNBits 4 $ fromEnum $ hdResponseCode h
137 get = do mID <- G.getWord16be
138 flags <- getByteString 2
141 do qr <- liftM (toEnum . fromIntegral) $ getAsWord8 1
142 op <- liftM (toEnum . fromIntegral) $ getAsWord8 4
148 rc <- liftM (toEnum . fromIntegral) $ getAsWord8 4
153 , hdIsAuthoritativeAnswer = aa
155 , hdIsRecursionDesired = rd
156 , hdIsRecursionAvailable = ra
157 , hdResponseCode = rc
161 instance Enum MessageType where
163 fromEnum Response = 1
169 instance Enum Opcode where
170 fromEnum StandardQuery = 0
171 fromEnum InverseQuery = 1
172 fromEnum ServerStatusRequest = 2
174 toEnum 0 = StandardQuery
175 toEnum 1 = InverseQuery
176 toEnum 2 = ServerStatusRequest
179 instance Enum ResponseCode where
181 fromEnum FormatError = 1
182 fromEnum ServerFailure = 2
183 fromEnum NameError = 3
184 fromEnum NotImplemented = 4
188 toEnum 1 = FormatError
189 toEnum 2 = ServerFailure
191 toEnum 4 = NotImplemented
195 instance Enum RecordType where
215 fromEnum AnyType = 255
239 instance Enum RecordClass where
244 fromEnum AnyClass = 255
250 toEnum 255 = AnyClass