2 import qualified Data.ByteString.Lazy as LBS
4 import Network.DNS.Message
6 import System.IO.Unsafe
10 messages :: [([Word8], Message)]
11 messages = [ ( [ 0x22, 0x79, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00
12 , 0x00, 0x00, 0x00, 0x00, 0x04, 0x6D, 0x61, 0x69
13 , 0x6C, 0x0A, 0x63, 0x69, 0x65, 0x6C, 0x6F, 0x6E
14 , 0x65, 0x67, 0x72, 0x6F, 0x03, 0x6F, 0x72, 0x67
15 , 0x00, 0x00, 0x05, 0x00, 0x01
20 , hdMessageType = Query
21 , hdOpcode = StandardQuery
22 , hdIsAuthoritativeAnswer = False
23 , hdIsTruncated = False
24 , hdIsRecursionDesired = True
25 , hdIsRecursionAvailable = False
26 , hdResponseCode = NoError
28 , msgQuestions = [ wrapQuestion $
30 qName = mkDomainName "mail.cielonegro.org."
40 , ( [ 0x22, 0x79, 0x85, 0x00, 0x00, 0x01, 0x00, 0x01
41 , 0x00, 0x01, 0x00, 0x01, 0x04, 0x6D, 0x61, 0x69
42 , 0x6C, 0x0A, 0x63, 0x69, 0x65, 0x6C, 0x6F, 0x6E
43 , 0x65, 0x67, 0x72, 0x6F, 0x03, 0x6F, 0x72, 0x67
44 , 0x00, 0x00, 0x05, 0x00, 0x01, 0xC0, 0x0C, 0x00
45 , 0x05, 0x00, 0x01, 0x00, 0x01, 0x51, 0x80, 0x00
46 , 0x06, 0x03, 0x6E, 0x65, 0x6D, 0xC0, 0x11, 0xC0
47 , 0x11, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x0E
48 , 0x10, 0x00, 0x02, 0xC0, 0x31, 0xC0, 0x31, 0x00
49 , 0x01, 0x00, 0x01, 0x00, 0x00, 0x0E, 0x10, 0x00
50 , 0x04, 0xDB, 0x5E, 0x82, 0x8B
55 , hdMessageType = Response
56 , hdOpcode = StandardQuery
57 , hdIsAuthoritativeAnswer = True
58 , hdIsTruncated = False
59 , hdIsRecursionDesired = True
60 , hdIsRecursionAvailable = False
61 , hdResponseCode = NoError
63 , msgQuestions = [ wrapQuestion $
65 qName = mkDomainName "mail.cielonegro.org."
70 , msgAnswers = [ wrapRecord $
72 rrName = mkDomainName "mail.cielonegro.org."
76 , rrData = mkDomainName "nem.cielonegro.org."
79 , msgAuthorities = [ wrapRecord $
81 rrName = mkDomainName "cielonegro.org."
85 , rrData = mkDomainName "nem.cielonegro.org."
88 , msgAdditionals = [ wrapRecord $
90 rrName = mkDomainName "nem.cielonegro.org."
94 , rrData = unsafePerformIO (inet_addr "219.94.130.139")
99 , ( [ 0xED, 0x68, 0x01, 0x00, 0x00, 0x01, 0x00, 0x00
100 , 0x00, 0x00, 0x00, 0x00, 0x0A, 0x63, 0x69, 0x65
101 , 0x6C, 0x6F, 0x6E, 0x65, 0x67, 0x72, 0x6F, 0x03
102 , 0x6F, 0x72, 0x67, 0x00, 0x00, 0x06, 0x00, 0x01
107 , hdMessageType = Query
108 , hdOpcode = StandardQuery
109 , hdIsAuthoritativeAnswer = False
110 , hdIsTruncated = False
111 , hdIsRecursionDesired = True
112 , hdIsRecursionAvailable = False
113 , hdResponseCode = NoError
115 , msgQuestions = [ wrapQuestion $
117 qName = mkDomainName "cielonegro.org."
123 , msgAuthorities = []
124 , msgAdditionals = []
127 , ( [ 0xED, 0x68, 0x85, 0x00, 0x00, 0x01, 0x00, 0x01
128 , 0x00, 0x01, 0x00, 0x01, 0x0A, 0x63, 0x69, 0x65
129 , 0x6C, 0x6F, 0x6E, 0x65, 0x67, 0x72, 0x6F, 0x03
130 , 0x6F, 0x72, 0x67, 0x00, 0x00, 0x06, 0x00, 0x01
131 , 0xC0, 0x0C, 0x00, 0x06, 0x00, 0x01, 0x00, 0x00
132 , 0x0E, 0x10, 0x00, 0x21, 0x03, 0x6E, 0x65, 0x6D
133 , 0xC0, 0x0C, 0x04, 0x72, 0x6F, 0x6F, 0x74, 0xC0
134 , 0x2C, 0x77, 0xAF, 0xFC, 0x84, 0x00, 0x00, 0x0E
135 , 0x10, 0x00, 0x00, 0x03, 0x84, 0x00, 0x36, 0xEE
136 , 0x80, 0x00, 0x00, 0x0E, 0x10, 0xC0, 0x0C, 0x00
137 , 0x02, 0x00, 0x01, 0x00, 0x00, 0x0E, 0x10, 0x00
138 , 0x02, 0xC0, 0x2C, 0xC0, 0x2C, 0x00, 0x01, 0x00
139 , 0x01, 0x00, 0x00, 0x0E, 0x10, 0x00, 0x04, 0xDB
145 , hdMessageType = Response
146 , hdOpcode = StandardQuery
147 , hdIsAuthoritativeAnswer = True
148 , hdIsTruncated = False
149 , hdIsRecursionDesired = True
150 , hdIsRecursionAvailable = False
151 , hdResponseCode = NoError
153 , msgQuestions = [ wrapQuestion $
155 qName = mkDomainName "cielonegro.org."
160 , msgAnswers = [ wrapRecord $
162 rrName = mkDomainName "cielonegro.org."
166 , rrData = SOAFields {
167 soaMasterNameServer = mkDomainName "nem.cielonegro.org."
168 , soaResponsibleMailbox = mkDomainName "root.nem.cielonegro.org."
169 , soaSerialNumber = 2008022148
170 , soaRefreshInterval = 3600
171 , soaRetryInterval = 900
172 , soaExpirationLimit = 3600000
173 , soaMinimumTTL = 3600
177 , msgAuthorities = [ wrapRecord $
179 rrName = mkDomainName "cielonegro.org."
183 , rrData = mkDomainName "nem.cielonegro.org."
186 , msgAdditionals = [ wrapRecord $
188 rrName = mkDomainName "nem.cielonegro.org."
192 , rrData = unsafePerformIO (inet_addr "219.94.130.139")
199 packMsg :: Message -> [Word8]
200 packMsg = LBS.unpack . encode
202 unpackMsg :: [Word8] -> Message
203 unpackMsg = decode . LBS.pack
206 testData = map mkPackTest messages
208 map mkUnpackTest messages
210 mkPackTest :: ([Word8], Message) -> Test
211 mkPackTest (bin, msg) = packMsg msg ~?= bin
213 mkUnpackTest :: ([Word8], Message) -> Test
214 mkUnpackTest (bin, msg) = unpackMsg bin ~?= msg
217 main = runTestTT (test testData) >> return ()