sawp-gre 0.8.0

SAWP Protocol Parser for GRE
Documentation

A Generic Routing Encapsulation (GRE) protocol parser. Given bytes and a [sawp::parser::Direction], it will attempt to parse the bytes and return a [Message]. The parser will inform the caller about what went wrong if no message is returned (see [sawp::parser::Parse] for details on possible return types).

The following protocol references were used to create this module:

[CURRENT GRE RFC2784] https://tools.ietf.org/html/rfc2784 [DEPRECATED GRE RFC1701] https://tools.ietf.org/html/rfc1701 [POINT TO POINT TUNNELING RFC2637] https://tools.ietf.org/html/rfc2637

Example

use sawp::parser::{Direction, Parse};
use sawp::error::Error;
use sawp::error::ErrorKind;
use sawp_gre::{Gre, Message};

fn parse_bytes(input: &[u8]) -> std::result::Result<&[u8], Error> {
let gre = Gre {};
let mut bytes = input;
while bytes.len() > 0 {
match gre.parse(bytes, Direction::Unknown) {
// The parser succeeded and returned the remaining bytes and the parsed gre message.
Ok((rest, Some(message))) => {
println!("Gre message: {:?}", message);
bytes = rest;
}
// The parser recognized that this might be gre and made some progress,
// but more bytes are needed.
Ok((rest, None)) => return Ok(rest),
// The parser was unable to determine whether this was gre or not and more bytes are
// needed.
Err(Error { kind: ErrorKind::Incomplete(_) }) => return Ok(bytes),
// The parser determined that this was not gre
Err(e) => return Err(e)
}
}

Ok(bytes)
}