adjustments for windows

This commit is contained in:
Wiktor Mazur
2019-08-10 19:02:57 +02:00
parent 6000a83838
commit f0d3c16c41
2 changed files with 21 additions and 3 deletions
+14 -3
View File
@@ -27,11 +27,22 @@ pub struct UdpPacket {
pub fn receive(tx: Sender<UdpPacket>) {
use pnet::datalink::Channel::Ethernet;
let interfaces = datalink::interfaces();
let interface = interfaces
let up_interface = datalink::interfaces()
.into_iter()
.filter(|i| !i.is_loopback() && !i.is_up())
.next();
let any_interface = datalink::interfaces()
.into_iter()
.filter(|i| !i.is_loopback())
.next()
.unwrap();
.next();
let interface = if up_interface.is_some() {
up_interface.unwrap()
} else {
any_interface.unwrap()
};
// Create a channel to receive on
let (_, mut rx) = match datalink::channel(&interface, Default::default()) {
+7
View File
@@ -10,6 +10,7 @@ static LOG_OUT: u8 = 4;
static SEND_UNRELIABLE: u8 = 7;
static SEND_RELIABLE: u8 = 6;
static REQUEST_CONSTANT: usize = 10000;
static RESPONSE_CONSTANT: usize = 1000;
static MSG_TYPE_REQUEST: u8 = 2;
@@ -77,7 +78,13 @@ fn on_message(cursor: &mut Cursor<&[u8]>, msg_len: u32) -> Option<Message> {
}
}
} else if msg_type == MSG_TYPE_REQUEST {
if let Some(request) = protocol16::deserialize_operation_request(&mut payload) {
let code = request.code as usize + REQUEST_CONSTANT;
let packet = Packet{code, parameters: request.parameters};
debug!("REQUEST: [{}] {:?}", packet.code, packet);
message = packet.decode();
}
} else if msg_type == MSG_TYPE_RESPONSE {
if let Some(response) = protocol16::deserialize_operation_response(&mut payload) {
let code = response.code as usize + RESPONSE_CONSTANT;