Skip to content

HTTPS clone URL

Subversion checkout URL

You can clone with
or
.
Download ZIP
Browse files

Commit initial work done on project, as submitted to Hackage as versi…

…on 0.0.1
  • Loading branch information...
commit 413217e4a77d153df5f5690cbc67afc3181c05bd 0 parents
@A1kmm authored
3  .gitignore
@@ -0,0 +1,3 @@
+*~
+dist
+\#*\#
14 LICENSE
@@ -0,0 +1,14 @@
+The author permanently and irrevocably places this work (the network-interfacerequest) in the public domain.
+
+In the event that the above attempt to place the document in the public domain is ineffective, the author grants a license use the software under the following terms:
+
+Copyright (c) 2012, Andrew Miller and Lanthaps Limited
+All rights reserved.
+
+Redistribution and use in source and binary forms, with or without modification, are permitted provided that the following conditions are met:
+
+ Redistributions of source code must retain the above copyright notice, this list of conditions and the following disclaimer.
+ Redistributions in binary form must reproduce the above copyright notice, this list of conditions and the following disclaimer in the documentation and/or other materials provided with the distribution.
+ Neither the name of the <ORGANIZATION> nor the names of its contributors may be used to endorse or promote products derived from this software without specific prior written permission.
+
+THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
2  Setup.hs
@@ -0,0 +1,2 @@
+import Distribution.Simple
+main = defaultMain
65 hssrc/Network/Socket/InterfaceRequest.hsc
@@ -0,0 +1,65 @@
+{-# LANGUAGE FlexibleInstances, MultiParamTypeClasses #-}
+module Network.Socket.InterfaceRequest
+where
+
+import Foreign.Storable
+import Foreign.C.Types
+import Network.Socket
+import Network.Socket.IOCtl
+import Data.Bits
+import Foreign.Ptr
+import Foreign.C.String
+import Control.Applicative
+import Foreign.Marshal
+
+#include <netinet/in.h>
+#include <linux/if.h>
+
+data InterfaceRequest a = InterfaceRequest { irIface :: String, irValue :: a }
+data InterfaceFlags = InterfaceFlags {
+ ifaceUp :: Bool,
+ ifaceRunning :: Bool
+ }
+ifaceDefaultFlags = InterfaceFlags True True
+
+instance Storable InterfaceFlags where
+ sizeOf _ = sizeOf (undefined :: CShort)
+ alignment _ = alignment (undefined :: CShort)
+ peek p = fmap (\i -> InterfaceFlags (i .&. 0x1 /= 0) (i .&. 0x40 /= 0))
+ (peek ((castPtr p) :: Ptr CShort))
+ poke p (InterfaceFlags ifaceUp ifaceRunning) =
+ poke ((castPtr p) :: Ptr CShort) $
+ (if ifaceUp then 0x1 else 0) .|.
+ (if ifaceRunning then 0x40 else 0)
+
+instance Storable a => Storable (InterfaceRequest a) where
+ sizeOf _ = #size struct ifreq
+ alignment _ = alignment (undefined :: CInt)
+ peek p = InterfaceRequest <$> (peekCString (castPtr p)) <*>
+ peek (plusPtr p 16)
+ poke p (InterfaceRequest n f) = do
+ let pchar = (castPtr p) :: CString
+ withCStringLen n $ \(s, l) -> do
+ let l' = min l 15
+ copyBytes pchar s l'
+ pokeByteOff pchar l' (0 :: CChar)
+ pokeByteOff (castPtr p) 16 (0 :: CULLong)
+ pokeByteOff (castPtr p) 24 (0 :: CULLong)
+ poke (plusPtr p 16) f
+
+data SetInterfaceFlags = SetInterfaceFlags
+data SetInterfaceMTU = SetInterfaceMTU
+data SetNoCSum = SetNoCSum
+
+instance IOControl SetInterfaceFlags (InterfaceRequest InterfaceFlags) where
+ ioctlReq _ = 0x8914
+instance IOControl SetInterfaceMTU (InterfaceRequest CInt) where
+ ioctlReq _ = 0x8922
+
+setInterfaceFlags :: Socket -> String -> InterfaceFlags -> IO ()
+setInterfaceFlags s n iflags =
+ ioctlsocket_ s SetInterfaceFlags (InterfaceRequest n iflags)
+
+setInterfaceMTU :: Socket -> String -> Int -> IO ()
+setInterfaceMTU s n mtu =
+ ioctlsocket_ s SetInterfaceMTU (InterfaceRequest n ((fromIntegral mtu) :: CInt))
23 network-interfacerequest.cabal
@@ -0,0 +1,23 @@
+Name: network-interfacerequest
+Synopsis: Haskell bindings for the ifreq structure
+Description: Haskell bindings for the ifreq structure used to query network status using ioctl
+License: BSD3
+License-File: LICENSE
+Category: Network
+Maintainer: Andrew Miller (andrew.miller@lanthaps.com)
+Cabal-Version: >= 1.6
+Build-Type: Simple
+
+Version: 0.0.1
+Library
+ Build-tools: hsc2hs
+ HS-Source-Dirs: hssrc
+ Exposed-Modules: Network.Socket.InterfaceRequest
+ Build-depends: network >= 2 && < 3,
+ ioctl < 0.1,
+ base >= 4 && < 5,
+ bytestring < 0.10
+
+Source-Repository head
+ type: git
+ location: https://github.com/A1kmm/network-interfacerequest
Please sign in to comment.
Something went wrong with that request. Please try again.