Commit 94958e03 authored by Nawasan Wisitsingkhon's avatar Nawasan Wisitsingkhon

add get_ip and arp to network

parent e17a2926
...@@ -77,3 +77,19 @@ pub enum Network { ...@@ -77,3 +77,19 @@ pub enum Network {
ARP(ARP), ARP(ARP),
Unparsable(u16, Vec<u8>), Unparsable(u16, Vec<u8>),
} }
impl Network {
pub fn get_ip(&self) -> Option<IP> {
match self {
Network::IP(ip) => Some(ip.clone()),
_ => None,
}
}
pub fn get_arp(&self) -> Option<ARP> {
if let Network::ARP(arp) = self {
Some(arp.clone())
} else {
None
}
}
}
...@@ -2,12 +2,14 @@ use std::io::Cursor; ...@@ -2,12 +2,14 @@ use std::io::Cursor;
use byteorder::{BigEndian, ReadBytesExt}; use byteorder::{BigEndian, ReadBytesExt};
#[derive(Clone)]
pub enum ArpOperation { pub enum ArpOperation {
Query = 0x0001, Query = 0x0001,
Reply = 0x0002, Reply = 0x0002,
Unparse, Unparse,
} }
#[derive(Clone)]
pub struct ARP { pub struct ARP {
pub hardware_type: u16, pub hardware_type: u16,
pub protocol_type: u16, pub protocol_type: u16,
......
...@@ -2,6 +2,7 @@ use std::io::{BufRead, Cursor}; ...@@ -2,6 +2,7 @@ use std::io::{BufRead, Cursor};
use byteorder::{BigEndian, ReadBytesExt}; use byteorder::{BigEndian, ReadBytesExt};
#[derive(Clone)]
pub struct ICMP { pub struct ICMP {
pub typ: u8, pub typ: u8,
pub code: u8, pub code: u8,
......
...@@ -2,6 +2,7 @@ use super::{tcp::TCP, udp::UDP, ICMP}; ...@@ -2,6 +2,7 @@ use super::{tcp::TCP, udp::UDP, ICMP};
use byteorder::{BigEndian, ReadBytesExt}; use byteorder::{BigEndian, ReadBytesExt};
use std::io::{BufRead, Cursor, Read}; use std::io::{BufRead, Cursor, Read};
#[derive(Clone)]
pub struct Flags { pub struct Flags {
pub dont_flagment: bool, pub dont_flagment: bool,
pub more_fragments: bool, pub more_fragments: bool,
...@@ -13,6 +14,7 @@ pub enum IpProtocol { ...@@ -13,6 +14,7 @@ pub enum IpProtocol {
UDP = 0x11, UDP = 0x11,
} }
#[derive(Clone)]
pub struct IP { pub struct IP {
pub version: u8, pub version: u8,
pub ihl: u8, pub ihl: u8,
...@@ -103,9 +105,10 @@ impl IP { ...@@ -103,9 +105,10 @@ impl IP {
} }
} }
#[derive(Clone)]
pub enum EtherData { pub enum EtherData {
ICMP(ICMP), ICMP(ICMP),
TCP(TCP), TCP(TCP),
UDP(UDP), UDP(UDP),
Unparse(u8, Vec<u8>), Unparse(u8, Vec<u8>),
} }
\ No newline at end of file
...@@ -2,6 +2,7 @@ use crate::etherparser::tools::bits::bit_bool; ...@@ -2,6 +2,7 @@ use crate::etherparser::tools::bits::bit_bool;
use byteorder::{BigEndian, ReadBytesExt}; use byteorder::{BigEndian, ReadBytesExt};
use std::io::{BufRead, Cursor}; use std::io::{BufRead, Cursor};
#[derive(Clone)]
pub struct TCP { pub struct TCP {
pub src_port: u16, pub src_port: u16,
pub des_port: u16, pub des_port: u16,
...@@ -49,6 +50,8 @@ impl TCP { ...@@ -49,6 +50,8 @@ impl TCP {
} }
} }
#[derive(Clone)]
pub struct TcpFlags { pub struct TcpFlags {
pub ns: bool, pub ns: bool,
pub cwr: bool, pub cwr: bool,
......
...@@ -2,6 +2,7 @@ use std::io::{BufRead, Cursor}; ...@@ -2,6 +2,7 @@ use std::io::{BufRead, Cursor};
use byteorder::{BigEndian, ReadBytesExt}; use byteorder::{BigEndian, ReadBytesExt};
#[derive(Clone)]
pub struct UDP { pub struct UDP {
pub src_port: u16, pub src_port: u16,
pub des_port: u16, pub des_port: u16,
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment