Merge pull request #23 from Frky/master

Clean a few commented lines
This commit is contained in:
Pierre 2021-12-23 15:19:54 +01:00 committed by GitHub
commit f28e0770f6
No known key found for this signature in database
GPG key ID: 4AEE18F83AFDEB23
2 changed files with 0 additions and 159 deletions

View file

@ -24,7 +24,6 @@ edition = "2018"
pcap = "0.7.0"
pcap-file = "1.1.1"
pnet = "0.26.0"
# pnet = { path = "libpnet" }
clap = "2.33.3"
log = "0.4.11"
stderrlog = "0.5.0"

View file

@ -257,107 +257,6 @@ impl Into<Vec<u8>> for &StunAttribute {
}
}
/*
struct StunPacket {
class: u8,
method: u16,
length: u16,
magic: u32,
id: u128,
data: Vec<u8>,
attributes: Vec<StunAttribute>,
}
impl StunPacket {
fn new(data: &[u8]) -> Result<Self, io::Error> {
if data.len() < 20 {
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
"not enough data",
));
}
let class: u8 = ((data[0] & 0x01) << 1) | ((data[1] & 0x10) >> 4);
let method: u16 = (((data[0] & 0b00111110) << 7) as u16) | ((data[1] & 0b11101111) as u16);
let length: u16 = BigEndian::read_u16(&data[2..4]);
let magic: u32 = BigEndian::read_u32(&data[4..8]);
let id: u128 = ((BigEndian::read_u64(&data[8..16]) as u128) << 32)
| (BigEndian::read_u32(&data[16..20]) as u128);
if data.len() < 20 + length as usize {
return Err(io::Error::new(
io::ErrorKind::InvalidInput,
"not enough data",
));
}
let data: Vec<u8> = data[20..(20 + length) as usize].to_vec();
let mut stun = StunPacket {
class,
method,
length,
magic,
id,
data,
attributes: Vec::<StunAttribute>::new(),
};
stun.attributes = stun.get_attributes();
Ok(stun)
}
fn empty() -> Self {
StunPacket {
class: 0,
method: 0,
length: 0,
magic: 0,
id: 0,
data: Vec::new(),
attributes: Vec::new(),
}
}
fn get_attributes(&self) -> Vec<StunAttribute> {
let mut i = 0;
let mut attributes = Vec::<StunAttribute>::new();
while i + 4 < self.data.len() {
let attr = StunAttribute::from(self.data[i..].to_vec());
i += 4 + attr.len() as usize;
attributes.push(attr);
}
attributes
}
fn set_length(&mut self) {
self.length = 0;
for attr in &self.attributes {
self.length += 4 + attr.len();
}
}
}
impl Into<Vec<u8>> for StunPacket {
fn into(self) -> Vec<u8> {
let mut v = Vec::<u8>::new();
// first cocktail with class and method bits
v.push(
TryInto::<u8>::try_into((self.method >> 7) & 0b00111110).unwrap()
| TryInto::<u8>::try_into((self.class & 0b10) >> 1).unwrap(),
);
// second cocktail with class and method bits
v.push(
TryInto::<u8>::try_into((self.method & 0b01110000) << 1).unwrap()
| TryInto::<u8>::try_into((self.class & 0b01) << 4).unwrap()
| TryInto::<u8>::try_into(self.method & 0b00001111).unwrap(),
);
v.append(&mut self.length.to_be_bytes().to_vec());
v.append(&mut self.magic.to_be_bytes().to_vec());
v.append(&mut self.id.to_be_bytes()[4..].to_vec());
for attr in &self.attributes {
v.append(&mut attr.into());
}
v
}
}
*/
struct StunPacket {
class: u8,
method: u16,
@ -451,63 +350,6 @@ impl Into<Vec<u8>> for StunPacket {
}
}
/*
pub fn repl<'a>(
data: &'a [u8],
_masscanned: &Masscanned,
client_info: ClientInfo,
) -> Option<Vec<u8>> {
debug!("receiving STUN data");
let stun_req: StunPacket = if let Ok(s) = StunPacket::new(&data) {
s
} else {
return None;
};
if stun_req.class != STUN_CLASS_REQUEST {
info!(
"STUN packet not handled (class unknown: 0b{:b})",
stun_req.class
);
return None;
}
if stun_req.method != STUN_METHOD_BINDING {
info!(
"STUN packet not handled (method unknown: 0x{:03x})",
stun_req.method
);
return None;
}
/*
* To be compatible with RFC3489: ignore magic
if stun_req.magic != STUN_MAGIC {
info!(
"STUN packet not handled (magic unknown: 0x{:04x})",
stun_req.magic
);
return None;
}
*/
if client_info.ip.src == None {
error!("STUN packet not handled (expected client ip address not found)");
return None;
}
if client_info.port.src == None {
error!("STUN packet not handled (expected client port address not found)");
return None;
}
let mut stun_resp: StunPacket = StunPacket::empty();
stun_resp.class = STUN_CLASS_SUCCESS_RESPONSE;
stun_resp.method = STUN_METHOD_BINDING;
stun_resp.id = stun_req.id;
stun_resp.attributes = Vec::<StunAttribute>::new();
stun_resp.attributes.push(StunAttribute::MappedAddress(
StunMappedAddressAttribute::new(client_info.ip.src.unwrap(), client_info.port.src.unwrap()),
));
stun_resp.set_length();
return Some(stun_resp.into());
}
*/
pub fn repl<'a>(
data: &'a [u8],
_masscanned: &Masscanned,