1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
extern crate lib_sendpacket;
extern crate pnet;
extern crate pnet_datalink;
use *;
use ;
use env;
use ;
use MutableEthernetPacket;
use EtherTypes;
use MutableIpv4Packet;
use ;
//fn send_l2_packet(interface: NetworkInterface,
// source_mac: MacAddr,
// target_mac: MacAddr,
// payload: &[u8]) {
// let(mut tx, _) = match pnet::datalink::channel(&interface, Default::default()) {
// Ok(Channel::Ethernet(tx, rx)) => (tx, rx),
// Ok(_) => panic!("Unknown channel type"),
// Err(e) => panic!("Error happened {}", e),
// };
//
// let mut ethernet_buffer = [0u8; 42];
// let mut ethernet_packet = MutableEthernetPacket::new(&mut ethernet_buffer).unwrap();
//
// ethernet_packet.set_destination(target_mac);
// ethernet_packet.set_source(source_mac);
// ethernet_packet.set_ethertype(EtherTypes::Arp);
//
// ethernet_packet.set_payload(payload);
//
// tx.send_to(ethernet_packet.packet(), Some(interface));
//}
//
//fn send_ip_packet(interface: NetworkInterface,
// source_mac: MacAddr,
// target_mac: MacAddr,
// source_ip: Ipv4Addr,
// target_ip: Ipv4Addr,
// payload: &[u8]) {
//
//
// let mut ethernet_buffer = [0u8; 200];
// let mut ethernet_packet = MutableEthernetPacket::new(&mut ethernet_buffer).unwrap();
//
// ethernet_packet.set_destination(target_mac);
// ethernet_packet.set_source(source_mac);
// ethernet_packet.set_ethertype(EtherTypes::Ipv4);
//
// let mut ipv4_buffer = [0u8; 100];
// let mut ipv4_packet = MutableIpv4Packet::new(&mut ipv4_buffer).unwrap();
//
// ipv4_packet.set_source(source_ip);
// ipv4_packet.set_destination(target_ip);
// ipv4_packet.set_ttl(45);
// ipv4_packet.set_version(4);
// ipv4_packet.set_total_length(100);
// ipv4_packet.set_header_length(24);
//
// ipv4_packet.set_payload(payload);
//
// ethernet_packet.set_payload(ipv4_packet.packet_mut());
//
// tx.send_to(ethernet_packet.packet(), Some(interface));
//}