pcap-conduit (empty) → 0.1
raw patch · 8 files changed
+204/−0 lines, 8 filesdep +basedep +bytestringdep +conduitsetup-changed
Dependencies added: base, bytestring, conduit, pcap, transformers
Files
- AUTHORS.txt +3/−0
- LICENSE.txt +31/−0
- Network/Pcap/Conduit.hs +49/−0
- README.md +41/−0
- Setup.hs +2/−0
- examples/IfaceToFile.hs +20/−0
- examples/makefile +5/−0
- pcap-conduit.cabal +53/−0
+ AUTHORS.txt view
@@ -0,0 +1,3 @@+Author, target of blame:++Austin Seipp <mad [dot] one [@at] gmail [dot] com>
+ LICENSE.txt view
@@ -0,0 +1,31 @@+Copyright (c) 2012, Austin Seipp++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 Austin Seipp nor the names of other+ 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+OWNER 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.
+ Network/Pcap/Conduit.hs view
@@ -0,0 +1,49 @@+-- |+-- Module : Network.Pcap.Conduit+-- Copyright : (c) Austin Seipp 2012+-- License : BSD3+--+-- Maintainer : mad.one@gmail.com+-- Stability : experimental+-- Portability : GHC probably+--+-- This package provides conduit 'Sources' for pcap data ( captured by+-- wireshark, tcpdump, etc.) You can enumerate pcap files and live+-- interfaces.+--+-- Based on @pcap-enumerator@.+--+module Network.Pcap.Conduit+ ( Packet -- :: *+ , sourceOffline -- :: MonadIO m => FilePath -> Source m Packet+ , sourceLive -- :: MonadIO m => String -> Int -> Bool -> Int64 -> Source m Packet+ ) where++import Control.Monad.IO.Class (liftIO, MonadIO)+import Data.ByteString (ByteString)+import Data.Conduit (Source, yield)+import Data.Int (Int64)+import Network.Pcap++-- | Convenient alias.+type Packet = (PktHdr, ByteString)++-- | Create a conduit 'Source' from a pcap data file.+sourceOffline :: MonadIO m => FilePath -> Source m Packet+sourceOffline path = (liftIO $ openOffline path) >>= sourcePcap1++-- | Create a conduit 'Source' from a live interface.+sourceLive :: MonadIO m+ => String -- ^ Device name+ -> Int -- ^ Snapshot length in bytes+ -> Bool -- ^ Promiscuous mode?+ -> Int64 -- ^ Timeout (in microseconds)+ -> Source m Packet+sourceLive n s p t = (liftIO $ openLive n s p t) >>= sourcePcap1++sourcePcap1 :: MonadIO m => PcapHandle -> Source m Packet+sourcePcap1 h = do+ pkt@(hdr,_) <- liftIO (nextBS h)+ if (hdrCaptureLength hdr == 0)+ then return ()+ else yield pkt >> sourcePcap1 h
+ README.md view
@@ -0,0 +1,41 @@+# Conduit <-> Pcap++`pcap-conduit` lets you use the Conduit package to iterate over network data, using+the `libpcap` API. It allows you to stream in both offline pcap dump files and live+network interfaces into a conduit `Source`.++[travis-ci.org](http://travis-ci.org) results: [](http://travis-ci.org/thoughtpolice/pcap-conduit)++# Installation++It's just a `cabal install` away:++```+$ cabal install pcap-conduit+```++# Join in++File bugs in the GitHub [issue tracker][].++Master [git repository][gh]:++* `git clone https://github.com/thoughtpolice/pcap-conduit.git`++There's also a [BitBucket mirror][bb]:++* `git clone https://bitbucket.org/thoughtpolice/pcap-conduit.git`++# Authors++See [AUTHORS.txt](https://raw.github.com/thoughtpolice/pcap-conduit/master/AUTHORS.txt).++# License++BSD3. See [LICENSE.txt](https://raw.github.com/thoughtpolice/pcap-conduit/master/LICENSE.txt) for terms of copyright and redistribution.++[CityHash]: http://cityhash.googlecode.com+[main page]: http://thoughtpolice.github.com/pcap-conduit+[issue tracker]: http://github.com/thoughtpolice/pcap-conduit/issues+[gh]: http://github.com/thoughtpolice/pcap-conduit+[bb]: http://bitbucket.org/thoughtpolice/pcap-conduit
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ examples/IfaceToFile.hs view
@@ -0,0 +1,20 @@+module Main+ ( main -- :: IO ()+ ) where++import System.Environment (getArgs)+import Control.Applicative++import Data.Conduit+import Data.Conduit.List as CL+import Data.Conduit.Binary++import Control.Monad.Trans.Resource++import Network.Pcap.Conduit++main :: IO ()+main = do+ [i] <- getArgs+ runResourceT $ sourceLive i 1024 False (10*1000000) $= CL.map snd+ $$ sinkFile (i++".txt")
+ examples/makefile view
@@ -0,0 +1,5 @@+all:+ ghc IfaceToFile+clean:+ rm -f *.txt *~ *.o *.hi IfaceToFile+
+ pcap-conduit.cabal view
@@ -0,0 +1,53 @@+name: pcap-conduit+version: 0.1+synopsis: Conduit <-> libpcap+description:+ Provides a conduit source for reading from pcap files or live network+ devices.+homepage: http://github.com/thoughtpolice/pcap-conduit+bug-reports: https://github.com/thoughtpolice/pcap-conduit/issues+license: BSD3+license-file: LICENSE.txt+author: Austin Seipp <mad.one@gmail.com>+maintainer: Austin Seipp <mad.one@gmail.com>+category: Network, Development+build-type: Simple+cabal-version: >=1.10+tested-with: GHC==7.0.4, GHC==7.2.1, GHC==7.4.2++extra-source-files:+ AUTHORS.txt, README.md+ examples/makefile, examples/*.hs++source-repository head+ type: git+ location: https://github.com/thoughtpolice/pcap-conduit.git++library+ exposed-modules:+ Network.Pcap.Conduit+ build-depends:+ base >= 3 && < 5,+ bytestring,+ transformers,+ pcap,+ conduit++ ghc-options: -Wall -O2 -fwarn-tabs+ default-language: Haskell98++-- test-suite properties+-- hs-source-dirs: tests+-- main-is: Properties.hs+-- type: exitcode-stdio-1.0+--+-- build-depends:+-- base >= 3 && < 5,+-- transformers,+-- bytestring,+-- pcap,+-- conduit,+-- pcap-conduit+--+-- ghc-options: -fno-cse -fno-warn-orphans+-- default-language: Haskell98