-
Notifications
You must be signed in to change notification settings - Fork 140
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
Merge pull request #76 from stephanbuys/streaming
Streaming
- Loading branch information
Showing
6 changed files
with
209 additions
and
16 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,39 @@ | ||
extern crate pcap; | ||
extern crate futures; | ||
extern crate tokio_core; | ||
|
||
use pcap::{Capture, Packet, Error, Device}; | ||
use pcap::tokio::PacketCodec; | ||
use tokio_core::reactor::Core; | ||
use futures::stream::Stream; | ||
|
||
pub struct SimpleDumpCodec; | ||
|
||
impl PacketCodec for SimpleDumpCodec{ | ||
type Type = String; | ||
|
||
fn decode<'p>(&mut self, packet: Packet<'p>) -> Result<Self::Type, Error> { | ||
Ok(format!("{:?}", packet)) | ||
|
||
} | ||
} | ||
|
||
fn ma1n() -> Result<(),Error> { | ||
let mut core = Core::new().unwrap(); | ||
let handle = core.handle(); | ||
let cap = Capture::from_device(Device::lookup()?)?.open()?.setnonblock()?; | ||
let s = cap.stream(&handle, SimpleDumpCodec{})?; | ||
let done = s.for_each(move |s| { | ||
println!("{:?}", s); | ||
Ok(()) | ||
}); | ||
core.run(done).unwrap(); | ||
Ok(()) | ||
} | ||
|
||
fn main() { | ||
match ma1n() { | ||
Ok(()) => (), | ||
Err(e) => println!("{:?}", e), | ||
} | ||
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Oops, something went wrong.