diff options
author | Kazu Yamamoto <kazu@iij.ad.jp> | 2012-07-12 23:22:31 -0700 |
---|---|---|
committer | Kazu Yamamoto <kazu@iij.ad.jp> | 2012-07-12 23:22:31 -0700 |
commit | 503304747f5b2f2ec5a648ddc08fd66fa185f0a5 (patch) | |
tree | 140133a5251645aa6f559aa2d1030cbdb0c0bec7 | |
parent | 163f05707ca2650b2a88847422819ff19d9447e6 (diff) | |
parent | 78eae6c6b3550fa3ad3a4289ddd385de6e75a996 (diff) |
Merge pull request #6 from larskuhtz/master
Set rdlen field on serialization. Fix compilation on Windows.
-rw-r--r-- | Network/DNS/Encode.hs | 11 | ||||
-rw-r--r-- | Network/DNS/Resolver.hs | 14 |
2 files changed, 23 insertions, 2 deletions
diff --git a/Network/DNS/Encode.hs b/Network/DNS/Encode.hs index c3457f2..e685f51 100644 --- a/Network/DNS/Encode.hs +++ b/Network/DNS/Encode.hs @@ -4,6 +4,7 @@ module Network.DNS.Encode ( , composeQuery ) where +import qualified Blaze.ByteString.Builder as BB (toByteString, fromWrite, writeInt16be) import qualified Data.ByteString.Lazy.Char8 as BL (ByteString) import qualified Data.ByteString.Char8 as BS (length, null, break, drop) import Network.DNS.StateBinary @@ -104,9 +105,15 @@ encodeRR ResourceRecord{..} = , putInt16 (typeToInt rrtype) , put16 1 , putInt32 rrttl - , putInt16 rdlen - , encodeRDATA rdata + , rlenRDATA ] + where + rlenRDATA = do + addPositionW 2 -- "simulate" putInt16 + rDataWrite <- encodeRDATA rdata + let rdataLength = fromIntegral . BS.length . BB.toByteString . BB.fromWrite $ rDataWrite + let rlenWrite = BB.writeInt16be rdataLength + return rlenWrite +++ return rDataWrite encodeRDATA :: RDATA -> SPut encodeRDATA rd = case rd of diff --git a/Network/DNS/Resolver.hs b/Network/DNS/Resolver.hs index 7cfb6d3..f040383 100644 --- a/Network/DNS/Resolver.hs +++ b/Network/DNS/Resolver.hs @@ -1,3 +1,4 @@ +{-# LANGUAGE CPP #-} {-| DNS Resolver and lookup functions. @@ -41,6 +42,11 @@ import Prelude hiding (lookup) import System.Random import System.Timeout +#if mingw32_HOST_OS == 1 +import Network.Socket (send) +import qualified Data.ByteString.Lazy.Char8 as LB +import Control.Monad (when) +#endif ---------------------------------------------------------------- {-| @@ -180,3 +186,11 @@ lookupRaw rlv dom typ = do if identifier hdr == seqno then Just res else Nothing + +#if mingw32_HOST_OS == 1 + -- Windows does not support sendAll in Network.ByteString.Lazy. + -- This implements sendAll with Haskell Strings. + sendAll sock bs = do + sent <- send sock (LB.unpack bs) + when (sent < fromIntegral (LB.length bs)) $ sendAll sock (LB.drop (fromIntegral sent) bs) +#endif |