diff --git a/Network/Sendfile/BSD.hsc b/Network/Sendfile/BSD.hsc
--- a/Network/Sendfile/BSD.hsc
+++ b/Network/Sendfile/BSD.hsc
@@ -1,4 +1,5 @@
 {-# LANGUAGE ForeignFunctionInterface #-}
+{-# LANGUAGE CPP #-}
 
 module Network.Sendfile.BSD (
     sendfile
@@ -57,14 +58,17 @@
 -- is sent and bofore waiting the socket to be ready for writing.
 
 sendfileFd :: Socket -> Fd -> FileRange -> IO () -> IO ()
-sendfileFd sock fd range hook =
+sendfileFd sock fd range hook = do
+#if MIN_VERSION_network(3,0,0)
+    dst <- Fd <$> fdSocket sock
+#else
+    let dst = Fd $ fdSocket sock
+#endif
     alloca $ \sentp -> do
         let (off,len) = case range of
                 EntireFile           -> (0, entire)
                 PartOfFile off' len' -> (fromInteger off', fromInteger len')
         sendloop dst fd off len sentp hook
-  where
-    dst = Fd $ fdSocket sock
 
 sendloop :: Fd -> Fd -> COff -> COff -> Ptr COff -> IO () -> IO ()
 sendloop dst src off len sentp hook = do
@@ -123,7 +127,12 @@
 -- is sent and bofore waiting the socket to be ready for writing.
 
 sendfileFdWithHeader :: Socket -> Fd -> FileRange -> IO () -> [ByteString] -> IO ()
-sendfileFdWithHeader sock fd range hook hdr =
+sendfileFdWithHeader sock fd range hook hdr = do
+#if MIN_VERSION_network(3,0,0)
+    dst <- Fd <$> fdSocket sock
+#else
+    let dst = Fd $ fdSocket sock
+#endif
     alloca $ \sentp ->
         if isFreeBSD && hlen >= 8192 then do
             -- If the length of the header is larger than 8191,
@@ -146,7 +155,6 @@
                     threadWaitWrite dst
                     sendloop dst fd newoff newlen sentp hook
   where
-    dst = Fd $ fdSocket sock
     hlen = fromIntegral . sum . map BS.length $ hdr
 
 sendloopHeader :: Fd -> Fd -> COff -> COff -> Ptr COff -> [ByteString] -> COff -> IO (Maybe (COff, COff))
diff --git a/Network/Sendfile/Linux.hsc b/Network/Sendfile/Linux.hsc
--- a/Network/Sendfile/Linux.hsc
+++ b/Network/Sendfile/Linux.hsc
@@ -1,4 +1,5 @@
 {-# LANGUAGE ForeignFunctionInterface #-}
+{-# LANGUAGE CPP #-}
 
 module Network.Sendfile.Linux (
     sendfile
@@ -91,9 +92,13 @@
 -- default) and the file is large. The action is called after a chunk
 -- is sent and bofore waiting the socket to be ready for writing.
 sendfileFd :: Socket -> Fd -> FileRange -> IO () -> IO ()
-sendfileFd sock fd range hook = sendfileFd' dst fd range hook
-  where
-    dst = Fd $ fdSocket sock
+sendfileFd sock fd range hook = do
+#if MIN_VERSION_network(3,0,0)
+    dst <- Fd <$> fdSocket sock
+#else
+    let dst = Fd $ fdSocket sock
+#endif
+    sendfileFd' dst fd range hook
 
 sendfileFd' :: Fd -> Fd -> FileRange -> IO () -> IO ()
 sendfileFd' dst src range hook =
@@ -199,11 +204,15 @@
 
 sendMsgMore :: Socket -> ByteString -> IO ()
 sendMsgMore sock bs = withForeignPtr fptr $ \ptr -> do
+#if MIN_VERSION_network(3,0,0)
+    s <- Fd <$> fdSocket sock
+#else
+    let s = Fd $ fdSocket sock
+#endif
     let buf = castPtr (ptr `plusPtr` off)
         siz = fromIntegral len
     sendloop s buf siz
   where
-    s = Fd $ fdSocket sock
     PS fptr off len = bs
 
 sendloop :: Fd -> Ptr CChar -> CSize -> IO ()
diff --git a/simple-sendfile.cabal b/simple-sendfile.cabal
--- a/simple-sendfile.cabal
+++ b/simple-sendfile.cabal
@@ -1,5 +1,5 @@
 Name:                   simple-sendfile
-Version:                0.2.27
+Version:                0.2.28
 Author:                 Kazu Yamamoto <kazu@iij.ad.jp>
 Maintainer:             Kazu Yamamoto <kazu@iij.ad.jp>
 License:                BSD3
