module Hans.Device.Pcap (pcapOpen, pcapSend, pcapReceiveLoop) where
import Prelude (String, IO, Bool(..), const, (.))
import Hans.Layer.Ethernet (EthernetHandle, queueEthernet)
import Control.Monad (void)
import Data.ByteString.Lazy (ByteString, toStrict)
import Network.Pcap (PcapHandle, openLive, loopBS, sendPacketBS)
pcapOpen :: String -> IO PcapHandle
pcapOpen s = openLive s 1514 True 0
pcapSend :: PcapHandle -> ByteString -> IO ()
pcapSend dev = sendPacketBS dev . toStrict
pcapReceiveLoop :: PcapHandle -> EthernetHandle -> IO ()
pcapReceiveLoop dev = void . loopBS dev (1) . const . queueEthernet