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 = [ Question {
29 qName = mkDomainName "mail.cielonegro.org."
30 , qType = wrapQueryType CNAME
39 , ( [ 0x22, 0x79, 0x85, 0x00, 0x00, 0x01, 0x00, 0x01
40 , 0x00, 0x01, 0x00, 0x01, 0x04, 0x6D, 0x61, 0x69
41 , 0x6C, 0x0A, 0x63, 0x69, 0x65, 0x6C, 0x6F, 0x6E
42 , 0x65, 0x67, 0x72, 0x6F, 0x03, 0x6F, 0x72, 0x67
43 , 0x00, 0x00, 0x05, 0x00, 0x01, 0xC0, 0x0C, 0x00
44 , 0x05, 0x00, 0x01, 0x00, 0x01, 0x51, 0x80, 0x00
45 , 0x06, 0x03, 0x6E, 0x65, 0x6D, 0xC0, 0x11, 0xC0
46 , 0x11, 0x00, 0x02, 0x00, 0x01, 0x00, 0x00, 0x0E
47 , 0x10, 0x00, 0x02, 0xC0, 0x31, 0xC0, 0x31, 0x00
48 , 0x01, 0x00, 0x01, 0x00, 0x00, 0x0E, 0x10, 0x00
49 , 0x04, 0xDB, 0x5E, 0x82, 0x8B
54 , hdMessageType = Response
55 , hdOpcode = StandardQuery
56 , hdIsAuthoritativeAnswer = True
57 , hdIsTruncated = False
58 , hdIsRecursionDesired = True
59 , hdIsRecursionAvailable = False
60 , hdResponseCode = NoError
62 , msgQuestions = [ Question {
63 qName = mkDomainName "mail.cielonegro.org."
64 , qType = wrapQueryType CNAME
68 , msgAnswers = [ wrapRecord $
70 rrName = mkDomainName "mail.cielonegro.org."
74 , rrData = mkDomainName "nem.cielonegro.org."
77 , msgAuthorities = [ wrapRecord $
79 rrName = mkDomainName "cielonegro.org."
83 , rrData = mkDomainName "nem.cielonegro.org."
86 , msgAdditionals = [ wrapRecord $
88 rrName = mkDomainName "nem.cielonegro.org."
92 , rrData = unsafePerformIO (inet_addr "219.94.130.139")
99 packMsg :: Message -> [Word8]
100 packMsg = LBS.unpack . encode
102 unpackMsg :: [Word8] -> Message
103 unpackMsg = decode . LBS.pack
106 testData = map mkPackTest messages
108 map mkUnpackTest messages
110 mkPackTest :: ([Word8], Message) -> Test
111 mkPackTest (bin, msg) = packMsg msg ~?= bin
113 mkUnpackTest :: ([Word8], Message) -> Test
114 mkUnpackTest (bin, msg) = unpackMsg bin ~?= msg
117 main = runTestTT (test testData) >> return ()