streaming-pcap (empty) → 1.0.0
raw patch · 7 files changed
+148/−0 lines, 7 filesdep +basedep +bytestringdep +pcapsetup-changed
Dependencies added: base, bytestring, pcap, streaming, streaming-pcap, tasty, tasty-hunit
Files
- LICENSE +30/−0
- Network/Pcap/Streaming.hs +41/−0
- README.md +5/−0
- Setup.hs +2/−0
- streaming-pcap.cabal +54/−0
- test/Test.hs +16/−0
- test/test.pcap too large to diff
+ LICENSE view
@@ -0,0 +1,30 @@+Copyright Author name here (c) 2018++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 Author name here 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/Streaming.hs view
@@ -0,0 +1,41 @@+-- |+-- Module : Network.Pcap.Streaming+-- Copyright : (c) Colin Woodbury, 2018+-- License : BSD3+-- Maintainer: Colin Woodbury <colingw@gmail.com>+--+-- A streaming interface to the <http://hackage.haskell.org/package/pcap-0.4.5.2 pcap>+-- Haskell library, which itself is a binding to /libpcap/. Humbly adapted from+-- <http://hackage.haskell.org/package/pcap-conduit pcap-conduit> by Austin Seipp.++module Network.Pcap.Streaming+ ( Packet(..)+ , offline+ , online+ ) where++import qualified Data.ByteString as BS+import Data.Int (Int64)+import Network.Pcap+import Streaming+import qualified Streaming.Prelude as P++---++-- | A <https://en.wikipedia.org/wiki/Pcap pcap> packet. Assumes nothing about+-- the contents or structure of the `bytes` value.+data Packet = Packet { header :: PktHdr, bytes :: BS.ByteString } deriving (Eq, Show)++-- | Read `Packet`s from some file dump. See also `Network.Pcap.openOffline`.+offline :: FilePath -> Stream (Of Packet) IO ()+offline path = lift (openOffline path) >>= packets++-- | Read `Packet`s from some network device. See `Network.Pcap.openLive`+-- for a description of each argument.+online :: String -> Int -> Bool -> Int64 -> Stream (Of Packet) IO ()+online n s p t = lift (openLive n s p t) >>= packets++packets :: PcapHandle -> Stream (Of Packet) IO ()+packets h = do+ (hdr,bs) <- lift (nextBS h)+ if hdrCaptureLength hdr == 0 then pure () else P.yield (Packet hdr bs) *> packets h
+ README.md view
@@ -0,0 +1,5 @@+# streaming-pcap++A streaming interface to the [pcap](http://hackage.haskell.org/package/pcap-0.4.5.2)+Haskell library, which itself is a binding to *libpcap*. Humbly adapted from+[pcap-conduit](http://hackage.haskell.org/package/pcap-conduit) by Austin Seipp.
+ Setup.hs view
@@ -0,0 +1,2 @@+import Distribution.Simple+main = defaultMain
+ streaming-pcap.cabal view
@@ -0,0 +1,54 @@+-- This file has been generated from package.yaml by hpack version 0.20.0.+--+-- see: https://github.com/sol/hpack+--+-- hash: c37ffea4ae53bdbe6e7f8ec6c8834974fadb48711722864ed540a2e2753fb5c0++name: streaming-pcap+version: 1.0.0+synopsis: Stream packets via libpcap.+description: Stream packets via libpcap.+category: Web+homepage: https://github.com/fosskers/streaming-pcap+author: Colin Woodbury+maintainer: colingw@gmail.com+copyright: 2018 Colin Woodbury+license: BSD3+license-file: LICENSE+build-type: Simple+cabal-version: >= 1.10++extra-source-files:+ README.md+ test/test.pcap++library+ hs-source-dirs:+ ./.+ ghc-options: -fwarn-unused-imports -fwarn-unused-binds -fwarn-name-shadowing -fwarn-unused-matches -fwarn-incomplete-patterns -fwarn-incomplete-uni-patterns+ build-depends:+ base >=4.7 && <5+ , bytestring+ , pcap >=0.4 && <0.5+ , streaming >=0.2 && <0.3+ exposed-modules:+ Network.Pcap.Streaming+ default-language: Haskell2010++test-suite streaming-pcap-test+ type: exitcode-stdio-1.0+ main-is: Test.hs+ hs-source-dirs:+ test+ ghc-options: -fwarn-unused-imports -fwarn-unused-binds -fwarn-name-shadowing -fwarn-unused-matches -fwarn-incomplete-patterns -fwarn-incomplete-uni-patterns -threaded+ build-depends:+ base >=4.7 && <5+ , bytestring+ , pcap >=0.4 && <0.5+ , streaming >=0.2 && <0.3+ , streaming-pcap+ , tasty >=0.11 && <1.1+ , tasty-hunit >=0.9 && <0.11+ other-modules:+ Paths_streaming_pcap+ default-language: Haskell2010
+ test/Test.hs view
@@ -0,0 +1,16 @@+module Main ( main ) where++import Network.Pcap.Streaming+import qualified Streaming.Prelude as P+import Test.Tasty+import Test.Tasty.HUnit++---++main :: IO ()+main = defaultMain suite++suite :: TestTree+suite = testGroup "Unit Tests"+ [ testCase "Packet Quantity" $ P.length_ (offline "test/test.pcap") >>= (@?= 21273)+ ]
+ test/test.pcap view
file too large to diff