From d126d8fe4159b68feadd4145f0e2a1f90d7ca502 Mon Sep 17 00:00:00 2001 From: huangyi Date: Sun, 23 Oct 2011 13:22:18 +0800 Subject: make encoder and decoder invertable, and tests to ensure that. --- Network/DNS/Internal.hs | 46 +++++++++++++++++++++++++++++++++++++++++++++- 1 file changed, 45 insertions(+), 1 deletion(-) (limited to 'Network/DNS/Internal.hs') diff --git a/Network/DNS/Internal.hs b/Network/DNS/Internal.hs index 8274afe..0368bd4 100644 --- a/Network/DNS/Internal.hs +++ b/Network/DNS/Internal.hs @@ -151,7 +151,15 @@ defaultQuery :: DNSFormat defaultQuery = DNSFormat { header = DNSHeader { identifier = 0 - , flags = undefined + , flags = DNSFlags { + qOrR = QR_Query + , opcode = OP_STD + , authAnswer = False + , trunCation = False + , recDesired = True + , recAvailable = False + , rcode = NoErr + } , qdCount = 0 , anCount = 0 , nsCount = 0 @@ -162,3 +170,39 @@ defaultQuery = DNSFormat { , authority = [] , additional = [] } + +defaultResponse :: DNSFormat +defaultResponse = + let hd = header defaultQuery + flg = flags hd + in defaultQuery { + header = hd { + flags = flg { + qOrR = QR_Response + , authAnswer = True + , recAvailable = True + } + } + } + +responseA :: Int -> Question -> IPv4 -> DNSFormat +responseA ident q ip = + let hd = header defaultResponse + dom = qname q + an = ResourceRecord dom A 300 4 (RD_A ip) + in defaultResponse { + header = hd { identifier=ident, qdCount = 1, anCount = 1 } + , question = [q] + , answer = [an] + } + +responseAAAA :: Int -> Question -> IPv6 -> DNSFormat +responseAAAA ident q ip = + let hd = header defaultResponse + dom = qname q + an = ResourceRecord dom AAAA 300 16 (RD_AAAA ip) + in defaultResponse { + header = hd { identifier=ident, qdCount = 1, anCount = 1 } + , question = [q] + , answer = [an] + } -- cgit v1.2.3