{-# LANGUAGE DeriveDataTypeable #-}
{-# LANGUAGE PatternSynonyms #-}
{-# LANGUAGE OverloadedStrings #-}
{-# LANGUAGE CPP #-}
module Network.DNS.Types (
ResourceRecord (..)
, Domain
, CLASS
, classIN
, TTL
, TYPE (
A
, NS
, CNAME
, SOA
, NULL
, PTR
, MX
, TXT
, AAAA
, SRV
, DNAME
, OPT
, DS
, RRSIG
, NSEC
, DNSKEY
, NSEC3
, NSEC3PARAM
, TLSA
, CDS
, CDNSKEY
, CSYNC
, ANY
)
, fromTYPE
, toTYPE
, RData (..)
, DNSMessage (..)
, defaultQuery
, defaultResponse
, DNSFormat
, DNSHeader (..)
, Identifier
, QorR (..)
, DNSFlags (..)
, OPCODE (..)
, RCODE (
NoErr
, FormatErr
, ServFail
, NameErr
, NotImpl
, Refused
, YXDomain
, YXRRSet
, NXRRSet
, NotAuth
, NotZone
, BadOpt
)
, fromRCODE
, toRCODE
, fromRCODEforHeader
, toRCODEforHeader
, Question (..)
, DNSError (..)
, EDNS0
, defaultEDNS0
, maxUdpSize
, minUdpSize
, udpSize
, extRCODE
, dnssecOk
, options
, fromEDNS0
, toEDNS0
, OData (..)
, OptCode (
ClientSubnet
)
, fromOptCode
, toOptCode
, Mailbox
) where
import Control.Exception (Exception, IOException)
import qualified Data.ByteString.Base64 as B64 (encode)
import qualified Data.ByteString.Char8 as BS
import qualified Data.ByteString.Builder as L
import qualified Data.ByteString.Lazy as L
import Data.IP (IP, IPv4, IPv6)
import Network.DNS.Imports
type Domain = ByteString
type Mailbox = ByteString
#if __GLASGOW_HASKELL__ >= 802
newtype TYPE = TYPE {
TYPE -> Word16
fromTYPE :: Word16
} deriving (TYPE -> TYPE -> Bool
(TYPE -> TYPE -> Bool) -> (TYPE -> TYPE -> Bool) -> Eq TYPE
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: TYPE -> TYPE -> Bool
$c/= :: TYPE -> TYPE -> Bool
== :: TYPE -> TYPE -> Bool
$c== :: TYPE -> TYPE -> Bool
Eq, Eq TYPE
Eq TYPE
-> (TYPE -> TYPE -> Ordering)
-> (TYPE -> TYPE -> Bool)
-> (TYPE -> TYPE -> Bool)
-> (TYPE -> TYPE -> Bool)
-> (TYPE -> TYPE -> Bool)
-> (TYPE -> TYPE -> TYPE)
-> (TYPE -> TYPE -> TYPE)
-> Ord TYPE
TYPE -> TYPE -> Bool
TYPE -> TYPE -> Ordering
TYPE -> TYPE -> TYPE
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: TYPE -> TYPE -> TYPE
$cmin :: TYPE -> TYPE -> TYPE
max :: TYPE -> TYPE -> TYPE
$cmax :: TYPE -> TYPE -> TYPE
>= :: TYPE -> TYPE -> Bool
$c>= :: TYPE -> TYPE -> Bool
> :: TYPE -> TYPE -> Bool
$c> :: TYPE -> TYPE -> Bool
<= :: TYPE -> TYPE -> Bool
$c<= :: TYPE -> TYPE -> Bool
< :: TYPE -> TYPE -> Bool
$c< :: TYPE -> TYPE -> Bool
compare :: TYPE -> TYPE -> Ordering
$ccompare :: TYPE -> TYPE -> Ordering
$cp1Ord :: Eq TYPE
Ord)
pattern A :: TYPE
pattern $bA :: TYPE
$mA :: forall r. TYPE -> (Void# -> r) -> (Void# -> r) -> r
A = TYPE 1
pattern NS :: TYPE
pattern $bNS :: TYPE
$mNS :: forall r. TYPE -> (Void# -> r) -> (Void# -> r) -> r
NS = TYPE 2
pattern CNAME :: TYPE
pattern $bCNAME :: TYPE
$mCNAME :: forall r. TYPE -> (Void# -> r) -> (Void# -> r) -> r
CNAME = TYPE 5
pattern SOA :: TYPE
pattern $bSOA :: TYPE
$mSOA :: forall r. TYPE -> (Void# -> r) -> (Void# -> r) -> r
SOA = TYPE 6
pattern NULL :: TYPE
pattern $bNULL :: TYPE
$mNULL :: forall r. TYPE -> (Void# -> r) -> (Void# -> r) -> r
NULL = TYPE 10
pattern PTR :: TYPE
pattern $bPTR :: TYPE
$mPTR :: forall r. TYPE -> (Void# -> r) -> (Void# -> r) -> r
PTR = TYPE 12
pattern MX :: TYPE
pattern $bMX :: TYPE
$mMX :: forall r. TYPE -> (Void# -> r) -> (Void# -> r) -> r
MX = TYPE 15
pattern TXT :: TYPE
pattern $bTXT :: TYPE
$mTXT :: forall r. TYPE -> (Void# -> r) -> (Void# -> r) -> r
TXT = TYPE 16
pattern AAAA :: TYPE
pattern $bAAAA :: TYPE
$mAAAA :: forall r. TYPE -> (Void# -> r) -> (Void# -> r) -> r
AAAA = TYPE 28
pattern SRV :: TYPE
pattern $bSRV :: TYPE
$mSRV :: forall r. TYPE -> (Void# -> r) -> (Void# -> r) -> r
SRV = TYPE 33
pattern DNAME :: TYPE
pattern $bDNAME :: TYPE
$mDNAME :: forall r. TYPE -> (Void# -> r) -> (Void# -> r) -> r
DNAME = TYPE 39
pattern OPT :: TYPE
pattern $bOPT :: TYPE
$mOPT :: forall r. TYPE -> (Void# -> r) -> (Void# -> r) -> r
OPT = TYPE 41
pattern DS :: TYPE
pattern $bDS :: TYPE
$mDS :: forall r. TYPE -> (Void# -> r) -> (Void# -> r) -> r
DS = TYPE 43
pattern RRSIG :: TYPE
pattern $bRRSIG :: TYPE
$mRRSIG :: forall r. TYPE -> (Void# -> r) -> (Void# -> r) -> r
RRSIG = TYPE 46
pattern NSEC :: TYPE
pattern $bNSEC :: TYPE
$mNSEC :: forall r. TYPE -> (Void# -> r) -> (Void# -> r) -> r
NSEC = TYPE 47
pattern DNSKEY :: TYPE
pattern $bDNSKEY :: TYPE
$mDNSKEY :: forall r. TYPE -> (Void# -> r) -> (Void# -> r) -> r
DNSKEY = TYPE 48
pattern NSEC3 :: TYPE
pattern $bNSEC3 :: TYPE
$mNSEC3 :: forall r. TYPE -> (Void# -> r) -> (Void# -> r) -> r
NSEC3 = TYPE 50
pattern NSEC3PARAM :: TYPE
pattern $bNSEC3PARAM :: TYPE
$mNSEC3PARAM :: forall r. TYPE -> (Void# -> r) -> (Void# -> r) -> r
NSEC3PARAM = TYPE 51
pattern TLSA :: TYPE
pattern $bTLSA :: TYPE
$mTLSA :: forall r. TYPE -> (Void# -> r) -> (Void# -> r) -> r
TLSA = TYPE 52
pattern CDS :: TYPE
pattern $bCDS :: TYPE
$mCDS :: forall r. TYPE -> (Void# -> r) -> (Void# -> r) -> r
CDS = TYPE 59
pattern CDNSKEY :: TYPE
pattern $bCDNSKEY :: TYPE
$mCDNSKEY :: forall r. TYPE -> (Void# -> r) -> (Void# -> r) -> r
CDNSKEY = TYPE 60
pattern CSYNC :: TYPE
pattern $bCSYNC :: TYPE
$mCSYNC :: forall r. TYPE -> (Void# -> r) -> (Void# -> r) -> r
CSYNC = TYPE 62
pattern ANY :: TYPE
pattern $bANY :: TYPE
$mANY :: forall r. TYPE -> (Void# -> r) -> (Void# -> r) -> r
ANY = TYPE 255
instance Show TYPE where
show :: TYPE -> String
show TYPE
A = String
"A"
show TYPE
NS = String
"NS"
show TYPE
CNAME = String
"CNAME"
show TYPE
SOA = String
"SOA"
show TYPE
NULL = String
"NULL"
show TYPE
PTR = String
"PTR"
show TYPE
MX = String
"MX"
show TYPE
TXT = String
"TXT"
show TYPE
AAAA = String
"AAAA"
show TYPE
SRV = String
"SRV"
show TYPE
DNAME = String
"DNAME"
show TYPE
OPT = String
"OPT"
show TYPE
DS = String
"DS"
show TYPE
RRSIG = String
"RRSIG"
show TYPE
NSEC = String
"NSEC"
show TYPE
DNSKEY = String
"DNSKEY"
show TYPE
NSEC3 = String
"NSEC3"
show TYPE
NSEC3PARAM = String
"NSEC3PARAM"
show TYPE
TLSA = String
"TLSA"
show TYPE
CDS = String
"CDS"
show TYPE
CDNSKEY = String
"CDNSKEY"
show TYPE
CSYNC = String
"CSYNC"
show TYPE
ANY = String
"ANY"
show TYPE
x = String
"TYPE " String -> ShowS
forall a. [a] -> [a] -> [a]
++ (Word16 -> String
forall a. Show a => a -> String
show (Word16 -> String) -> Word16 -> String
forall a b. (a -> b) -> a -> b
$ TYPE -> Word16
fromTYPE TYPE
x)
toTYPE :: Word16 -> TYPE
toTYPE :: Word16 -> TYPE
toTYPE = Word16 -> TYPE
TYPE
#else
data TYPE = A
| NS
| CNAME
| SOA
| NULL
| PTR
| MX
| TXT
| AAAA
| SRV
| DNAME
| OPT
| DS
| RRSIG
| NSEC
| DNSKEY
| NSEC3
| NSEC3PARAM
| TLSA
| CDS
| CDNSKEY
| CSYNC
| ANY
| UnknownTYPE Word16
deriving (Eq, Ord, Show, Read)
fromTYPE :: TYPE -> Word16
fromTYPE A = 1
fromTYPE NS = 2
fromTYPE CNAME = 5
fromTYPE SOA = 6
fromTYPE NULL = 10
fromTYPE PTR = 12
fromTYPE MX = 15
fromTYPE TXT = 16
fromTYPE AAAA = 28
fromTYPE SRV = 33
fromTYPE DNAME = 39
fromTYPE OPT = 41
fromTYPE DS = 43
fromTYPE RRSIG = 46
fromTYPE NSEC = 47
fromTYPE DNSKEY = 48
fromTYPE NSEC3 = 50
fromTYPE NSEC3PARAM = 51
fromTYPE TLSA = 52
fromTYPE CDS = 59
fromTYPE CDNSKEY = 60
fromTYPE CSYNC = 62
fromTYPE ANY = 255
fromTYPE (UnknownTYPE x) = x
toTYPE :: Word16 -> TYPE
toTYPE 1 = A
toTYPE 2 = NS
toTYPE 5 = CNAME
toTYPE 6 = SOA
toTYPE 10 = NULL
toTYPE 12 = PTR
toTYPE 15 = MX
toTYPE 16 = TXT
toTYPE 28 = AAAA
toTYPE 33 = SRV
toTYPE 39 = DNAME
toTYPE 41 = OPT
toTYPE 43 = DS
toTYPE 46 = RRSIG
toTYPE 47 = NSEC
toTYPE 48 = DNSKEY
toTYPE 50 = NSEC3
toTYPE 51 = NSEC3PARAM
toTYPE 52 = TLSA
toTYPE 59 = CDS
toTYPE 60 = CDNSKEY
toTYPE 62 = CSYNC
toTYPE 255 = ANY
toTYPE x = UnknownTYPE x
#endif
data DNSError =
SequenceNumberMismatch
| RetryLimitExceeded
| TimeoutExpired
| UnexpectedRDATA
| IllegalDomain
| FormatError
| ServerFailure
| NameError
| NotImplemented
| OperationRefused
| BadOptRecord
| BadConfiguration
| NetworkFailure IOException
| DecodeError String
| UnknownDNSError
deriving (DNSError -> DNSError -> Bool
(DNSError -> DNSError -> Bool)
-> (DNSError -> DNSError -> Bool) -> Eq DNSError
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DNSError -> DNSError -> Bool
$c/= :: DNSError -> DNSError -> Bool
== :: DNSError -> DNSError -> Bool
$c== :: DNSError -> DNSError -> Bool
Eq, Int -> DNSError -> ShowS
[DNSError] -> ShowS
DNSError -> String
(Int -> DNSError -> ShowS)
-> (DNSError -> String) -> ([DNSError] -> ShowS) -> Show DNSError
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DNSError] -> ShowS
$cshowList :: [DNSError] -> ShowS
show :: DNSError -> String
$cshow :: DNSError -> String
showsPrec :: Int -> DNSError -> ShowS
$cshowsPrec :: Int -> DNSError -> ShowS
Show, Typeable)
instance Exception DNSError
data DNSMessage = DNSMessage {
:: DNSHeader
, DNSMessage -> [Question]
question :: [Question]
, DNSMessage -> [ResourceRecord]
answer :: [ResourceRecord]
, DNSMessage -> [ResourceRecord]
authority :: [ResourceRecord]
, DNSMessage -> [ResourceRecord]
additional :: [ResourceRecord]
} deriving (DNSMessage -> DNSMessage -> Bool
(DNSMessage -> DNSMessage -> Bool)
-> (DNSMessage -> DNSMessage -> Bool) -> Eq DNSMessage
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DNSMessage -> DNSMessage -> Bool
$c/= :: DNSMessage -> DNSMessage -> Bool
== :: DNSMessage -> DNSMessage -> Bool
$c== :: DNSMessage -> DNSMessage -> Bool
Eq, Int -> DNSMessage -> ShowS
[DNSMessage] -> ShowS
DNSMessage -> String
(Int -> DNSMessage -> ShowS)
-> (DNSMessage -> String)
-> ([DNSMessage] -> ShowS)
-> Show DNSMessage
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DNSMessage] -> ShowS
$cshowList :: [DNSMessage] -> ShowS
show :: DNSMessage -> String
$cshow :: DNSMessage -> String
showsPrec :: Int -> DNSMessage -> ShowS
$cshowsPrec :: Int -> DNSMessage -> ShowS
Show)
{-# DEPRECATED DNSFormat "Use DNSMessage instead" #-}
type DNSFormat = DNSMessage
type Identifier = Word16
data = {
DNSHeader -> Word16
identifier :: Identifier
, DNSHeader -> DNSFlags
flags :: DNSFlags
} deriving (DNSHeader -> DNSHeader -> Bool
(DNSHeader -> DNSHeader -> Bool)
-> (DNSHeader -> DNSHeader -> Bool) -> Eq DNSHeader
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DNSHeader -> DNSHeader -> Bool
$c/= :: DNSHeader -> DNSHeader -> Bool
== :: DNSHeader -> DNSHeader -> Bool
$c== :: DNSHeader -> DNSHeader -> Bool
Eq, Int -> DNSHeader -> ShowS
[DNSHeader] -> ShowS
DNSHeader -> String
(Int -> DNSHeader -> ShowS)
-> (DNSHeader -> String)
-> ([DNSHeader] -> ShowS)
-> Show DNSHeader
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DNSHeader] -> ShowS
$cshowList :: [DNSHeader] -> ShowS
show :: DNSHeader -> String
$cshow :: DNSHeader -> String
showsPrec :: Int -> DNSHeader -> ShowS
$cshowsPrec :: Int -> DNSHeader -> ShowS
Show)
data DNSFlags = DNSFlags {
DNSFlags -> QorR
qOrR :: QorR
, DNSFlags -> OPCODE
opcode :: OPCODE
, DNSFlags -> Bool
authAnswer :: Bool
, DNSFlags -> Bool
trunCation :: Bool
, DNSFlags -> Bool
recDesired :: Bool
, DNSFlags -> Bool
recAvailable :: Bool
, DNSFlags -> RCODE
rcode :: RCODE
, DNSFlags -> Bool
authenData :: Bool
} deriving (DNSFlags -> DNSFlags -> Bool
(DNSFlags -> DNSFlags -> Bool)
-> (DNSFlags -> DNSFlags -> Bool) -> Eq DNSFlags
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: DNSFlags -> DNSFlags -> Bool
$c/= :: DNSFlags -> DNSFlags -> Bool
== :: DNSFlags -> DNSFlags -> Bool
$c== :: DNSFlags -> DNSFlags -> Bool
Eq, Int -> DNSFlags -> ShowS
[DNSFlags] -> ShowS
DNSFlags -> String
(Int -> DNSFlags -> ShowS)
-> (DNSFlags -> String) -> ([DNSFlags] -> ShowS) -> Show DNSFlags
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [DNSFlags] -> ShowS
$cshowList :: [DNSFlags] -> ShowS
show :: DNSFlags -> String
$cshow :: DNSFlags -> String
showsPrec :: Int -> DNSFlags -> ShowS
$cshowsPrec :: Int -> DNSFlags -> ShowS
Show)
data QorR = QR_Query
| QR_Response
deriving (QorR -> QorR -> Bool
(QorR -> QorR -> Bool) -> (QorR -> QorR -> Bool) -> Eq QorR
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: QorR -> QorR -> Bool
$c/= :: QorR -> QorR -> Bool
== :: QorR -> QorR -> Bool
$c== :: QorR -> QorR -> Bool
Eq, Int -> QorR -> ShowS
[QorR] -> ShowS
QorR -> String
(Int -> QorR -> ShowS)
-> (QorR -> String) -> ([QorR] -> ShowS) -> Show QorR
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [QorR] -> ShowS
$cshowList :: [QorR] -> ShowS
show :: QorR -> String
$cshow :: QorR -> String
showsPrec :: Int -> QorR -> ShowS
$cshowsPrec :: Int -> QorR -> ShowS
Show, Int -> QorR
QorR -> Int
QorR -> [QorR]
QorR -> QorR
QorR -> QorR -> [QorR]
QorR -> QorR -> QorR -> [QorR]
(QorR -> QorR)
-> (QorR -> QorR)
-> (Int -> QorR)
-> (QorR -> Int)
-> (QorR -> [QorR])
-> (QorR -> QorR -> [QorR])
-> (QorR -> QorR -> [QorR])
-> (QorR -> QorR -> QorR -> [QorR])
-> Enum QorR
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: QorR -> QorR -> QorR -> [QorR]
$cenumFromThenTo :: QorR -> QorR -> QorR -> [QorR]
enumFromTo :: QorR -> QorR -> [QorR]
$cenumFromTo :: QorR -> QorR -> [QorR]
enumFromThen :: QorR -> QorR -> [QorR]
$cenumFromThen :: QorR -> QorR -> [QorR]
enumFrom :: QorR -> [QorR]
$cenumFrom :: QorR -> [QorR]
fromEnum :: QorR -> Int
$cfromEnum :: QorR -> Int
toEnum :: Int -> QorR
$ctoEnum :: Int -> QorR
pred :: QorR -> QorR
$cpred :: QorR -> QorR
succ :: QorR -> QorR
$csucc :: QorR -> QorR
Enum, QorR
QorR -> QorR -> Bounded QorR
forall a. a -> a -> Bounded a
maxBound :: QorR
$cmaxBound :: QorR
minBound :: QorR
$cminBound :: QorR
Bounded)
data OPCODE
= OP_STD
| OP_INV
| OP_SSR
deriving (OPCODE -> OPCODE -> Bool
(OPCODE -> OPCODE -> Bool)
-> (OPCODE -> OPCODE -> Bool) -> Eq OPCODE
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: OPCODE -> OPCODE -> Bool
$c/= :: OPCODE -> OPCODE -> Bool
== :: OPCODE -> OPCODE -> Bool
$c== :: OPCODE -> OPCODE -> Bool
Eq, Int -> OPCODE -> ShowS
[OPCODE] -> ShowS
OPCODE -> String
(Int -> OPCODE -> ShowS)
-> (OPCODE -> String) -> ([OPCODE] -> ShowS) -> Show OPCODE
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [OPCODE] -> ShowS
$cshowList :: [OPCODE] -> ShowS
show :: OPCODE -> String
$cshow :: OPCODE -> String
showsPrec :: Int -> OPCODE -> ShowS
$cshowsPrec :: Int -> OPCODE -> ShowS
Show, Int -> OPCODE
OPCODE -> Int
OPCODE -> [OPCODE]
OPCODE -> OPCODE
OPCODE -> OPCODE -> [OPCODE]
OPCODE -> OPCODE -> OPCODE -> [OPCODE]
(OPCODE -> OPCODE)
-> (OPCODE -> OPCODE)
-> (Int -> OPCODE)
-> (OPCODE -> Int)
-> (OPCODE -> [OPCODE])
-> (OPCODE -> OPCODE -> [OPCODE])
-> (OPCODE -> OPCODE -> [OPCODE])
-> (OPCODE -> OPCODE -> OPCODE -> [OPCODE])
-> Enum OPCODE
forall a.
(a -> a)
-> (a -> a)
-> (Int -> a)
-> (a -> Int)
-> (a -> [a])
-> (a -> a -> [a])
-> (a -> a -> [a])
-> (a -> a -> a -> [a])
-> Enum a
enumFromThenTo :: OPCODE -> OPCODE -> OPCODE -> [OPCODE]
$cenumFromThenTo :: OPCODE -> OPCODE -> OPCODE -> [OPCODE]
enumFromTo :: OPCODE -> OPCODE -> [OPCODE]
$cenumFromTo :: OPCODE -> OPCODE -> [OPCODE]
enumFromThen :: OPCODE -> OPCODE -> [OPCODE]
$cenumFromThen :: OPCODE -> OPCODE -> [OPCODE]
enumFrom :: OPCODE -> [OPCODE]
$cenumFrom :: OPCODE -> [OPCODE]
fromEnum :: OPCODE -> Int
$cfromEnum :: OPCODE -> Int
toEnum :: Int -> OPCODE
$ctoEnum :: Int -> OPCODE
pred :: OPCODE -> OPCODE
$cpred :: OPCODE -> OPCODE
succ :: OPCODE -> OPCODE
$csucc :: OPCODE -> OPCODE
Enum, OPCODE
OPCODE -> OPCODE -> Bounded OPCODE
forall a. a -> a -> Bounded a
maxBound :: OPCODE
$cmaxBound :: OPCODE
minBound :: OPCODE
$cminBound :: OPCODE
Bounded)
#if __GLASGOW_HASKELL__ >= 802
newtype RCODE = RCODE {
RCODE -> Word16
fromRCODE :: Word16
} deriving (RCODE -> RCODE -> Bool
(RCODE -> RCODE -> Bool) -> (RCODE -> RCODE -> Bool) -> Eq RCODE
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RCODE -> RCODE -> Bool
$c/= :: RCODE -> RCODE -> Bool
== :: RCODE -> RCODE -> Bool
$c== :: RCODE -> RCODE -> Bool
Eq)
instance Enum RCODE where
fromEnum :: RCODE -> Int
fromEnum = Word16 -> Int
forall a b. (Integral a, Num b) => a -> b
fromIntegral (Word16 -> Int) -> (RCODE -> Word16) -> RCODE -> Int
forall b c a. (b -> c) -> (a -> b) -> a -> c
. RCODE -> Word16
fromRCODE
toEnum :: Int -> RCODE
toEnum = Word16 -> RCODE
RCODE (Word16 -> RCODE) -> (Int -> Word16) -> Int -> RCODE
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Int -> Word16
forall a b. (Integral a, Num b) => a -> b
fromIntegral
pattern NoErr :: RCODE
pattern $bNoErr :: RCODE
$mNoErr :: forall r. RCODE -> (Void# -> r) -> (Void# -> r) -> r
NoErr = RCODE 0
pattern FormatErr :: RCODE
pattern $bFormatErr :: RCODE
$mFormatErr :: forall r. RCODE -> (Void# -> r) -> (Void# -> r) -> r
FormatErr = RCODE 1
pattern ServFail :: RCODE
pattern $bServFail :: RCODE
$mServFail :: forall r. RCODE -> (Void# -> r) -> (Void# -> r) -> r
ServFail = RCODE 2
pattern NameErr :: RCODE
pattern $bNameErr :: RCODE
$mNameErr :: forall r. RCODE -> (Void# -> r) -> (Void# -> r) -> r
NameErr = RCODE 3
pattern NotImpl :: RCODE
pattern $bNotImpl :: RCODE
$mNotImpl :: forall r. RCODE -> (Void# -> r) -> (Void# -> r) -> r
NotImpl = RCODE 4
pattern Refused :: RCODE
pattern $bRefused :: RCODE
$mRefused :: forall r. RCODE -> (Void# -> r) -> (Void# -> r) -> r
Refused = RCODE 5
pattern YXDomain :: RCODE
pattern $bYXDomain :: RCODE
$mYXDomain :: forall r. RCODE -> (Void# -> r) -> (Void# -> r) -> r
YXDomain = RCODE 6
pattern YXRRSet :: RCODE
pattern $bYXRRSet :: RCODE
$mYXRRSet :: forall r. RCODE -> (Void# -> r) -> (Void# -> r) -> r
YXRRSet = RCODE 7
pattern NXRRSet :: RCODE
pattern $bNXRRSet :: RCODE
$mNXRRSet :: forall r. RCODE -> (Void# -> r) -> (Void# -> r) -> r
NXRRSet = RCODE 8
pattern NotAuth :: RCODE
pattern $bNotAuth :: RCODE
$mNotAuth :: forall r. RCODE -> (Void# -> r) -> (Void# -> r) -> r
NotAuth = RCODE 9
pattern NotZone :: RCODE
pattern $bNotZone :: RCODE
$mNotZone :: forall r. RCODE -> (Void# -> r) -> (Void# -> r) -> r
NotZone = RCODE 10
pattern BadOpt :: RCODE
pattern $bBadOpt :: RCODE
$mBadOpt :: forall r. RCODE -> (Void# -> r) -> (Void# -> r) -> r
BadOpt = RCODE 16
instance Show RCODE where
show :: RCODE -> String
show RCODE
NoErr = String
"NoError"
show RCODE
FormatErr = String
"FormErr"
show RCODE
ServFail = String
"ServFail"
show RCODE
NameErr = String
"NXDomain"
show RCODE
NotImpl = String
"NotImp"
show RCODE
Refused = String
"Refused"
show RCODE
YXDomain = String
"YXDomain"
show RCODE
YXRRSet = String
"YXRRSet"
show RCODE
NotAuth = String
"NotAuth"
show RCODE
NotZone = String
"NotZone"
show RCODE
BadOpt = String
"BADVERS"
show RCODE
x = String
"RCODE " String -> ShowS
forall a. [a] -> [a] -> [a]
++ (Word16 -> String
forall a. Show a => a -> String
show (Word16 -> String) -> Word16 -> String
forall a b. (a -> b) -> a -> b
$ RCODE -> Word16
fromRCODE RCODE
x)
toRCODE :: Word16 -> RCODE
toRCODE :: Word16 -> RCODE
toRCODE = Word16 -> RCODE
RCODE
fromRCODEforHeader :: RCODE -> Word16
(RCODE Word16
w) = Word16
w Word16 -> Word16 -> Word16
forall a. Bits a => a -> a -> a
.&. Word16
0x0f
toRCODEforHeader :: Word16 -> RCODE
Word16
w = Word16 -> RCODE
RCODE (Word16
w Word16 -> Word16 -> Word16
forall a. Bits a => a -> a -> a
.&. Word16
0x0f)
#else
data RCODE
= NoErr
| FormatErr
| ServFail
| NameErr
| NotImpl
| Refused
| YXDomain
| YXRRSet
| NXRRSet
| NotAuth
| NotZone
| BadOpt
| UnknownRCODE Word16
deriving (Eq, Ord, Show)
fromRCODE :: RCODE -> Word16
fromRCODE NoErr = 0
fromRCODE FormatErr = 1
fromRCODE ServFail = 2
fromRCODE NameErr = 3
fromRCODE NotImpl = 4
fromRCODE Refused = 5
fromRCODE YXDomain = 6
fromRCODE YXRRSet = 7
fromRCODE NXRRSet = 8
fromRCODE NotAuth = 9
fromRCODE NotZone = 10
fromRCODE BadOpt = 16
fromRCODE (UnknownRCODE x) = x
toRCODE :: Word16 -> RCODE
toRCODE 0 = NoErr
toRCODE 1 = FormatErr
toRCODE 2 = ServFail
toRCODE 3 = NameErr
toRCODE 4 = NotImpl
toRCODE 5 = Refused
toRCODE 6 = YXDomain
toRCODE 7 = YXRRSet
toRCODE 8 = NXRRSet
toRCODE 9 = NotAuth
toRCODE 10 = NotZone
toRCODE 16 = BadOpt
toRCODE x = UnknownRCODE x
fromRCODEforHeader :: RCODE -> Word16
fromRCODEforHeader rc = fromRCODE rc .&. 0x0f
toRCODEforHeader :: Word16 -> RCODE
toRCODEforHeader w = toRCODE (w .&. 0x0f)
#endif
data Question = Question {
Question -> Domain
qname :: Domain
, Question -> TYPE
qtype :: TYPE
} deriving (Question -> Question -> Bool
(Question -> Question -> Bool)
-> (Question -> Question -> Bool) -> Eq Question
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: Question -> Question -> Bool
$c/= :: Question -> Question -> Bool
== :: Question -> Question -> Bool
$c== :: Question -> Question -> Bool
Eq, Int -> Question -> ShowS
[Question] -> ShowS
Question -> String
(Int -> Question -> ShowS)
-> (Question -> String) -> ([Question] -> ShowS) -> Show Question
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [Question] -> ShowS
$cshowList :: [Question] -> ShowS
show :: Question -> String
$cshow :: Question -> String
showsPrec :: Int -> Question -> ShowS
$cshowsPrec :: Int -> Question -> ShowS
Show)
type CLASS = Word16
classIN :: CLASS
classIN :: Word16
classIN = Word16
1
type TTL = Word32
data ResourceRecord = ResourceRecord {
ResourceRecord -> Domain
rrname :: Domain
, ResourceRecord -> TYPE
rrtype :: TYPE
, ResourceRecord -> Word16
rrclass :: CLASS
, ResourceRecord -> TTL
rrttl :: TTL
, ResourceRecord -> RData
rdata :: RData
} deriving (ResourceRecord -> ResourceRecord -> Bool
(ResourceRecord -> ResourceRecord -> Bool)
-> (ResourceRecord -> ResourceRecord -> Bool) -> Eq ResourceRecord
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: ResourceRecord -> ResourceRecord -> Bool
$c/= :: ResourceRecord -> ResourceRecord -> Bool
== :: ResourceRecord -> ResourceRecord -> Bool
$c== :: ResourceRecord -> ResourceRecord -> Bool
Eq,Int -> ResourceRecord -> ShowS
[ResourceRecord] -> ShowS
ResourceRecord -> String
(Int -> ResourceRecord -> ShowS)
-> (ResourceRecord -> String)
-> ([ResourceRecord] -> ShowS)
-> Show ResourceRecord
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [ResourceRecord] -> ShowS
$cshowList :: [ResourceRecord] -> ShowS
show :: ResourceRecord -> String
$cshow :: ResourceRecord -> String
showsPrec :: Int -> ResourceRecord -> ShowS
$cshowsPrec :: Int -> ResourceRecord -> ShowS
Show)
data RData = RD_A IPv4
| RD_NS Domain
| RD_CNAME Domain
| RD_SOA Domain Mailbox Word32 Word32 Word32 Word32 Word32
| RD_NULL
| RD_PTR Domain
| RD_MX Word16 Domain
| RD_TXT ByteString
| RD_AAAA IPv6
| RD_SRV Word16 Word16 Word16 Domain
| RD_DNAME Domain
| RD_OPT [OData]
| RD_DS Word16 Word8 Word8 ByteString
| RD_DNSKEY Word16 Word8 Word8 ByteString
| RD_NSEC3PARAM Word8 Word8 Word16 ByteString
| RD_TLSA Word8 Word8 Word8 ByteString
| UnknownRData ByteString
deriving (RData -> RData -> Bool
(RData -> RData -> Bool) -> (RData -> RData -> Bool) -> Eq RData
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: RData -> RData -> Bool
$c/= :: RData -> RData -> Bool
== :: RData -> RData -> Bool
$c== :: RData -> RData -> Bool
Eq, Eq RData
Eq RData
-> (RData -> RData -> Ordering)
-> (RData -> RData -> Bool)
-> (RData -> RData -> Bool)
-> (RData -> RData -> Bool)
-> (RData -> RData -> Bool)
-> (RData -> RData -> RData)
-> (RData -> RData -> RData)
-> Ord RData
RData -> RData -> Bool
RData -> RData -> Ordering
RData -> RData -> RData
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: RData -> RData -> RData
$cmin :: RData -> RData -> RData
max :: RData -> RData -> RData
$cmax :: RData -> RData -> RData
>= :: RData -> RData -> Bool
$c>= :: RData -> RData -> Bool
> :: RData -> RData -> Bool
$c> :: RData -> RData -> Bool
<= :: RData -> RData -> Bool
$c<= :: RData -> RData -> Bool
< :: RData -> RData -> Bool
$c< :: RData -> RData -> Bool
compare :: RData -> RData -> Ordering
$ccompare :: RData -> RData -> Ordering
$cp1Ord :: Eq RData
Ord)
instance Show RData where
show :: RData -> String
show (RD_NS Domain
dom) = Domain -> String
BS.unpack Domain
dom
show (RD_MX Word16
prf Domain
dom) = Word16 -> String
forall a. Show a => a -> String
show Word16
prf String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Domain -> String
BS.unpack Domain
dom
show (RD_CNAME Domain
dom) = Domain -> String
BS.unpack Domain
dom
show (RD_DNAME Domain
dom) = Domain -> String
BS.unpack Domain
dom
show (RD_A IPv4
a) = IPv4 -> String
forall a. Show a => a -> String
show IPv4
a
show (RD_AAAA IPv6
aaaa) = IPv6 -> String
forall a. Show a => a -> String
show IPv6
aaaa
show (RD_TXT Domain
txt) = Domain -> String
BS.unpack Domain
txt
show (RD_SOA Domain
mn Domain
mr TTL
serial TTL
refresh TTL
retry TTL
expire TTL
mi) = Domain -> String
BS.unpack Domain
mn String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Domain -> String
BS.unpack Domain
mr String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" " String -> ShowS
forall a. [a] -> [a] -> [a]
++
TTL -> String
forall a. Show a => a -> String
show TTL
serial String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" " String -> ShowS
forall a. [a] -> [a] -> [a]
++ TTL -> String
forall a. Show a => a -> String
show TTL
refresh String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" " String -> ShowS
forall a. [a] -> [a] -> [a]
++
TTL -> String
forall a. Show a => a -> String
show TTL
retry String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" " String -> ShowS
forall a. [a] -> [a] -> [a]
++ TTL -> String
forall a. Show a => a -> String
show TTL
expire String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" " String -> ShowS
forall a. [a] -> [a] -> [a]
++ TTL -> String
forall a. Show a => a -> String
show TTL
mi
show (RD_PTR Domain
dom) = Domain -> String
BS.unpack Domain
dom
show (RD_SRV Word16
pri Word16
wei Word16
prt Domain
dom) = Word16 -> String
forall a. Show a => a -> String
show Word16
pri String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Word16 -> String
forall a. Show a => a -> String
show Word16
wei String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Word16 -> String
forall a. Show a => a -> String
show Word16
prt String -> ShowS
forall a. [a] -> [a] -> [a]
++ Domain -> String
BS.unpack Domain
dom
show (RD_OPT [OData]
od) = [OData] -> String
forall a. Show a => a -> String
show [OData]
od
show (UnknownRData Domain
is) = Domain -> String
forall a. Show a => a -> String
show Domain
is
show (RD_TLSA Word8
use Word8
sel Word8
mtype Domain
dgst) = Word8 -> String
forall a. Show a => a -> String
show Word8
use String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Word8 -> String
forall a. Show a => a -> String
show Word8
sel String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Word8 -> String
forall a. Show a => a -> String
show Word8
mtype String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Domain -> String
hexencode Domain
dgst
show (RD_DS Word16
t Word8
a Word8
dt Domain
dv) = Word16 -> String
forall a. Show a => a -> String
show Word16
t String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Word8 -> String
forall a. Show a => a -> String
show Word8
a String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Word8 -> String
forall a. Show a => a -> String
show Word8
dt String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Domain -> String
hexencode Domain
dv
show RData
RD_NULL = String
"NULL"
show (RD_DNSKEY Word16
f Word8
p Word8
a Domain
k) = Word16 -> String
forall a. Show a => a -> String
show Word16
f String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Word8 -> String
forall a. Show a => a -> String
show Word8
p String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Word8 -> String
forall a. Show a => a -> String
show Word8
a String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Domain -> String
b64encode Domain
k
show (RD_NSEC3PARAM Word8
h Word8
f Word16
i Domain
s) = Word8 -> String
forall a. Show a => a -> String
show Word8
h String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Word8 -> String
forall a. Show a => a -> String
show Word8
f String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Word16 -> String
forall a. Show a => a -> String
show Word16
i String -> ShowS
forall a. [a] -> [a] -> [a]
++ String
" " String -> ShowS
forall a. [a] -> [a] -> [a]
++ Domain -> String
showSalt Domain
s
where
showSalt :: Domain -> String
showSalt Domain
"" = String
"-"
showSalt Domain
salt = Domain -> String
hexencode Domain
salt
hexencode :: ByteString -> String
hexencode :: Domain -> String
hexencode = Domain -> String
BS.unpack (Domain -> String) -> (Domain -> Domain) -> Domain -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. ByteString -> Domain
L.toStrict (ByteString -> Domain)
-> (Domain -> ByteString) -> Domain -> Domain
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Builder -> ByteString
L.toLazyByteString (Builder -> ByteString)
-> (Domain -> Builder) -> Domain -> ByteString
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Domain -> Builder
L.byteStringHex
b64encode :: ByteString -> String
b64encode :: Domain -> String
b64encode = Domain -> String
BS.unpack (Domain -> String) -> (Domain -> Domain) -> Domain -> String
forall b c a. (b -> c) -> (a -> b) -> a -> c
. Domain -> Domain
B64.encode
defaultQuery :: DNSMessage
defaultQuery :: DNSMessage
defaultQuery = DNSMessage :: DNSHeader
-> [Question]
-> [ResourceRecord]
-> [ResourceRecord]
-> [ResourceRecord]
-> DNSMessage
DNSMessage {
header :: DNSHeader
header = DNSHeader :: Word16 -> DNSFlags -> DNSHeader
DNSHeader {
identifier :: Word16
identifier = Word16
0
, flags :: DNSFlags
flags = DNSFlags :: QorR
-> OPCODE
-> Bool
-> Bool
-> Bool
-> Bool
-> RCODE
-> Bool
-> DNSFlags
DNSFlags {
qOrR :: QorR
qOrR = QorR
QR_Query
, opcode :: OPCODE
opcode = OPCODE
OP_STD
, authAnswer :: Bool
authAnswer = Bool
False
, trunCation :: Bool
trunCation = Bool
False
, recDesired :: Bool
recDesired = Bool
True
, recAvailable :: Bool
recAvailable = Bool
False
, rcode :: RCODE
rcode = RCODE
NoErr
, authenData :: Bool
authenData = Bool
False
}
}
, question :: [Question]
question = []
, answer :: [ResourceRecord]
answer = []
, authority :: [ResourceRecord]
authority = []
, additional :: [ResourceRecord]
additional = []
}
defaultResponse :: DNSMessage
defaultResponse :: DNSMessage
defaultResponse =
let hd :: DNSHeader
hd = DNSMessage -> DNSHeader
header DNSMessage
defaultQuery
flg :: DNSFlags
flg = DNSHeader -> DNSFlags
flags DNSHeader
hd
in DNSMessage
defaultQuery {
header :: DNSHeader
header = DNSHeader
hd {
flags :: DNSFlags
flags = DNSFlags
flg {
qOrR :: QorR
qOrR = QorR
QR_Response
, authAnswer :: Bool
authAnswer = Bool
True
, recAvailable :: Bool
recAvailable = Bool
True
, authenData :: Bool
authenData = Bool
False
}
}
}
data EDNS0 = EDNS0 {
EDNS0 -> Word16
udpSize :: Word16
, EDNS0 -> RCODE
extRCODE :: RCODE
, EDNS0 -> Bool
dnssecOk :: Bool
, EDNS0 -> [OData]
options :: [OData]
} deriving (EDNS0 -> EDNS0 -> Bool
(EDNS0 -> EDNS0 -> Bool) -> (EDNS0 -> EDNS0 -> Bool) -> Eq EDNS0
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: EDNS0 -> EDNS0 -> Bool
$c/= :: EDNS0 -> EDNS0 -> Bool
== :: EDNS0 -> EDNS0 -> Bool
$c== :: EDNS0 -> EDNS0 -> Bool
Eq, Int -> EDNS0 -> ShowS
[EDNS0] -> ShowS
EDNS0 -> String
(Int -> EDNS0 -> ShowS)
-> (EDNS0 -> String) -> ([EDNS0] -> ShowS) -> Show EDNS0
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [EDNS0] -> ShowS
$cshowList :: [EDNS0] -> ShowS
show :: EDNS0 -> String
$cshow :: EDNS0 -> String
showsPrec :: Int -> EDNS0 -> ShowS
$cshowsPrec :: Int -> EDNS0 -> ShowS
Show)
#if __GLASGOW_HASKELL__ >= 802
#else
#endif
defaultEDNS0 :: EDNS0
defaultEDNS0 :: EDNS0
defaultEDNS0 = Word16 -> RCODE -> Bool -> [OData] -> EDNS0
EDNS0 Word16
4096 RCODE
NoErr Bool
False []
maxUdpSize :: Word16
maxUdpSize :: Word16
maxUdpSize = Word16
16384
minUdpSize :: Word16
minUdpSize :: Word16
minUdpSize = Word16
512
fromEDNS0 :: EDNS0 -> ResourceRecord
fromEDNS0 :: EDNS0 -> ResourceRecord
fromEDNS0 EDNS0
edns = Domain -> TYPE -> Word16 -> TTL -> RData -> ResourceRecord
ResourceRecord Domain
name' TYPE
type' Word16
class' TTL
ttl' RData
rdata'
where
name' :: Domain
name' = Domain
"."
type' :: TYPE
type' = TYPE
OPT
class' :: Word16
class' = Word16
maxUdpSize Word16 -> Word16 -> Word16
forall a. Ord a => a -> a -> a
`min` (Word16
minUdpSize Word16 -> Word16 -> Word16
forall a. Ord a => a -> a -> a
`max` EDNS0 -> Word16
udpSize EDNS0
edns)
ttl0' :: TTL
ttl0' = Word16 -> TTL
forall a b. (Integral a, Num b) => a -> b
fromIntegral (RCODE -> Word16
fromRCODE (EDNS0 -> RCODE
extRCODE EDNS0
edns) Word16 -> Word16 -> Word16
forall a. Bits a => a -> a -> a
.&. Word16
0x0ff0) TTL -> Int -> TTL
forall a. Bits a => a -> Int -> a
`shiftL` Int
20
ttl' :: TTL
ttl'
| EDNS0 -> Bool
dnssecOk EDNS0
edns = TTL
ttl0' TTL -> Int -> TTL
forall a. Bits a => a -> Int -> a
`setBit` Int
15
| Bool
otherwise = TTL
ttl0'
rdata' :: RData
rdata' = [OData] -> RData
RD_OPT ([OData] -> RData) -> [OData] -> RData
forall a b. (a -> b) -> a -> b
$ EDNS0 -> [OData]
options EDNS0
edns
toEDNS0 :: DNSFlags -> ResourceRecord -> Maybe EDNS0
toEDNS0 :: DNSFlags -> ResourceRecord -> Maybe EDNS0
toEDNS0 DNSFlags
flgs (ResourceRecord Domain
"." TYPE
OPT Word16
udpsiz TTL
ttl' (RD_OPT [OData]
opts)) =
EDNS0 -> Maybe EDNS0
forall a. a -> Maybe a
Just (EDNS0 -> Maybe EDNS0) -> EDNS0 -> Maybe EDNS0
forall a b. (a -> b) -> a -> b
$ Word16 -> RCODE -> Bool -> [OData] -> EDNS0
EDNS0 Word16
udpsiz (Word16 -> RCODE
toRCODE Word16
erc) Bool
secok [OData]
opts
where
lp :: Word16
lp = RCODE -> Word16
fromRCODEforHeader (RCODE -> Word16) -> RCODE -> Word16
forall a b. (a -> b) -> a -> b
$ DNSFlags -> RCODE
rcode DNSFlags
flgs
up :: TTL
up = TTL -> Int -> TTL
forall a. Bits a => a -> Int -> a
shiftR (TTL
ttl' TTL -> TTL -> TTL
forall a. Bits a => a -> a -> a
.&. TTL
0xff000000) Int
20
erc :: Word16
erc = TTL -> Word16
forall a b. (Integral a, Num b) => a -> b
fromIntegral TTL
up Word16 -> Word16 -> Word16
forall a. Bits a => a -> a -> a
.|. Word16
lp
secok :: Bool
secok = TTL
ttl' TTL -> Int -> Bool
forall a. Bits a => a -> Int -> Bool
`testBit` Int
15
toEDNS0 DNSFlags
_ ResourceRecord
_ = Maybe EDNS0
forall a. Maybe a
Nothing
#if __GLASGOW_HASKELL__ >= 802
newtype OptCode = OptCode {
OptCode -> Word16
fromOptCode :: Word16
} deriving (OptCode -> OptCode -> Bool
(OptCode -> OptCode -> Bool)
-> (OptCode -> OptCode -> Bool) -> Eq OptCode
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: OptCode -> OptCode -> Bool
$c/= :: OptCode -> OptCode -> Bool
== :: OptCode -> OptCode -> Bool
$c== :: OptCode -> OptCode -> Bool
Eq,Eq OptCode
Eq OptCode
-> (OptCode -> OptCode -> Ordering)
-> (OptCode -> OptCode -> Bool)
-> (OptCode -> OptCode -> Bool)
-> (OptCode -> OptCode -> Bool)
-> (OptCode -> OptCode -> Bool)
-> (OptCode -> OptCode -> OptCode)
-> (OptCode -> OptCode -> OptCode)
-> Ord OptCode
OptCode -> OptCode -> Bool
OptCode -> OptCode -> Ordering
OptCode -> OptCode -> OptCode
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: OptCode -> OptCode -> OptCode
$cmin :: OptCode -> OptCode -> OptCode
max :: OptCode -> OptCode -> OptCode
$cmax :: OptCode -> OptCode -> OptCode
>= :: OptCode -> OptCode -> Bool
$c>= :: OptCode -> OptCode -> Bool
> :: OptCode -> OptCode -> Bool
$c> :: OptCode -> OptCode -> Bool
<= :: OptCode -> OptCode -> Bool
$c<= :: OptCode -> OptCode -> Bool
< :: OptCode -> OptCode -> Bool
$c< :: OptCode -> OptCode -> Bool
compare :: OptCode -> OptCode -> Ordering
$ccompare :: OptCode -> OptCode -> Ordering
$cp1Ord :: Eq OptCode
Ord)
pattern ClientSubnet :: OptCode
pattern $bClientSubnet :: OptCode
$mClientSubnet :: forall r. OptCode -> (Void# -> r) -> (Void# -> r) -> r
ClientSubnet = OptCode 8
instance Show OptCode where
show :: OptCode -> String
show OptCode
ClientSubnet = String
"ClientSubnet"
show OptCode
x = String
"OptCode " String -> ShowS
forall a. [a] -> [a] -> [a]
++ (Word16 -> String
forall a. Show a => a -> String
show (Word16 -> String) -> Word16 -> String
forall a b. (a -> b) -> a -> b
$ OptCode -> Word16
fromOptCode OptCode
x)
toOptCode :: Word16 -> OptCode
toOptCode :: Word16 -> OptCode
toOptCode = Word16 -> OptCode
OptCode
#else
data OptCode = ClientSubnet
| UnknownOptCode Word16
deriving (Eq, Ord, Show)
fromOptCode :: OptCode -> Word16
fromOptCode ClientSubnet = 8
fromOptCode (UnknownOptCode x) = x
toOptCode :: Word16 -> OptCode
toOptCode 8 = ClientSubnet
toOptCode x = UnknownOptCode x
#endif
data OData = OD_ClientSubnet Word8 Word8 IP
| UnknownOData OptCode ByteString
deriving (OData -> OData -> Bool
(OData -> OData -> Bool) -> (OData -> OData -> Bool) -> Eq OData
forall a. (a -> a -> Bool) -> (a -> a -> Bool) -> Eq a
/= :: OData -> OData -> Bool
$c/= :: OData -> OData -> Bool
== :: OData -> OData -> Bool
$c== :: OData -> OData -> Bool
Eq,Int -> OData -> ShowS
[OData] -> ShowS
OData -> String
(Int -> OData -> ShowS)
-> (OData -> String) -> ([OData] -> ShowS) -> Show OData
forall a.
(Int -> a -> ShowS) -> (a -> String) -> ([a] -> ShowS) -> Show a
showList :: [OData] -> ShowS
$cshowList :: [OData] -> ShowS
show :: OData -> String
$cshow :: OData -> String
showsPrec :: Int -> OData -> ShowS
$cshowsPrec :: Int -> OData -> ShowS
Show,Eq OData
Eq OData
-> (OData -> OData -> Ordering)
-> (OData -> OData -> Bool)
-> (OData -> OData -> Bool)
-> (OData -> OData -> Bool)
-> (OData -> OData -> Bool)
-> (OData -> OData -> OData)
-> (OData -> OData -> OData)
-> Ord OData
OData -> OData -> Bool
OData -> OData -> Ordering
OData -> OData -> OData
forall a.
Eq a
-> (a -> a -> Ordering)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> Bool)
-> (a -> a -> a)
-> (a -> a -> a)
-> Ord a
min :: OData -> OData -> OData
$cmin :: OData -> OData -> OData
max :: OData -> OData -> OData
$cmax :: OData -> OData -> OData
>= :: OData -> OData -> Bool
$c>= :: OData -> OData -> Bool
> :: OData -> OData -> Bool
$c> :: OData -> OData -> Bool
<= :: OData -> OData -> Bool
$c<= :: OData -> OData -> Bool
< :: OData -> OData -> Bool
$c< :: OData -> OData -> Bool
compare :: OData -> OData -> Ordering
$ccompare :: OData -> OData -> Ordering
$cp1Ord :: Eq OData
Ord)