summaryrefslogtreecommitdiffhomepage
path: root/Network/DNS/Internal.hs
diff options
context:
space:
mode:
authorGravatar Kazu Yamamoto <kazu@iij.ad.jp>2011-10-23 21:32:59 -0700
committerGravatar Kazu Yamamoto <kazu@iij.ad.jp>2011-10-23 21:32:59 -0700
commit04c4afa6f7af8be5bd9ac0871ac42510350ac2f0 (patch)
treec368ba3b3664fbfe9b2be45353d07e1e0960adea /Network/DNS/Internal.hs
parent1cc2f6a8882ce9e1a79ab8789b50a79b2d021d14 (diff)
parent89d6ab583274e7e10a69bc915b0e48cfdbc6207a (diff)
Merge pull request #3 from yihuang/master
Make this library full capable of decoding and encoding.
Diffstat (limited to 'Network/DNS/Internal.hs')
-rw-r--r--Network/DNS/Internal.hs46
1 files changed, 45 insertions, 1 deletions
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]
+ }