Comments (4)
I've run into similar issues, and found that opening an unused dummy socket will prevent the OS from automatically replying:
// Open a bogus socket to listen on port 2000, which prevents the OS from
// replying with ICMPv6 messages about the port being unreachable.
let _socket = std::net::UdpSocket::bind(format!("[::]:{SOURCE_PORT}"))?;
This is for IPv6 + UDP, but you might be able to do something similar for IPv4 + TCP.
from libpnet.
I've run into similar issues, and found that opening an unused dummy socket will prevent the OS from automatically replying:
// Open a bogus socket to listen on port 2000, which prevents the OS from // replying with ICMPv6 messages about the port being unreachable. let _socket = std::net::UdpSocket::bind(format!("[::]:{SOURCE_PORT}"))?;This is for IPv6 + UDP, but you might be able to do something similar for IPv4 + TCP.
Thank you very much for your reply ð, I haven't tested it yet, but I have a stupid question, will this socket conflict with libpnet?
from libpnet.
In my testing, it didn't interfere. I was using pnet::datalink::channel
to build a (tx, rx)
pair, which gives you every packet on the interface; then, you have to deconstruct + filter them manually. For my code, it looked like this:
let start = Instant::now();
while Instant::now() - start < timeout {
let Ok(rx) = self.receiver.next() else { continue; };
let packet = EthernetPacket::new(rx).unwrap();
if EtherTypes::Ipv6 == packet.get_ethertype() {
let header = Ipv6Packet::new(packet.payload()).unwrap();
if IpNextHeaderProtocols::Udp == header.get_next_header() {
let udp = UdpPacket::new(header.payload()).unwrap();
if udp.get_destination() == SOURCE_PORT {
return Some(udp.payload().to_owned());
}
}
}
}
from libpnet.
In my testing, it didn't interfere. I was using
pnet::datalink::channel
to build a(tx, rx)
pair, which gives you every packet on the interface; then, you have to deconstruct + filter them manually. For my code, it looked like this:let start = Instant::now(); while Instant::now() - start < timeout { let Ok(rx) = self.receiver.next() else { continue; }; let packet = EthernetPacket::new(rx).unwrap(); if EtherTypes::Ipv6 == packet.get_ethertype() { let header = Ipv6Packet::new(packet.payload()).unwrap(); if IpNextHeaderProtocols::Udp == header.get_next_header() { let udp = UdpPacket::new(header.payload()).unwrap(); if udp.get_destination() == SOURCE_PORT { return Some(udp.payload().to_owned()); } } } }
Thank you very much for your patience in replying, it seems that this is an unfixable bug that can only be remedied with a few tricks. ðĪŠ
from libpnet.
Related Issues (20)
- Struct packet_mreq requires repr(C) in rustc versions >= 1.67 HOT 1
- UdpPacket reports incorrect source port HOT 1
- Panicked at 'index out of bounds When using pnet_datalink to send arp request
- how to convert MutableArpPacket to &[u8] , so that it can be set_payload to MutableEthernetPacket HOT 5
- [Question] what is the correct way to change source/destination IP address for TCP/UDP packets? HOT 1
- Duplicate processing
- RARP Example HOT 4
- Can libpnet run in an asynchronous non-blocking environment?
- TCP segment structure flags should be `u8` not `u9be`.
- How to statically link WinPcap? HOT 1
- Thinking of contributing - is project still active? HOT 2
- [BUG] TCP header get_flags() function wired return of value
- libpnet cannot execute asynchronously HOT 1
- `packet_size` may or may not include payload, depending on type
- Why pnet::transport does not have ipv6_packet_iter?
- panicked at 'index out of bounds: the len is 16 but the index is 22',
- MacOS `misaligned pointer dereference` in `DataLinkReceiver` with invalid interface HOT 2
- rDNS packet support
- Methods to calculate and verify checksums
Recommend Projects
-
React
A declarative, efficient, and flexible JavaScript library for building user interfaces.
-
Vue.js
ð Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.
-
Typescript
TypeScript is a superset of JavaScript that compiles to clean JavaScript output.
-
TensorFlow
An Open Source Machine Learning Framework for Everyone
-
Django
The Web framework for perfectionists with deadlines.
-
Laravel
A PHP framework for web artisans
-
D3
Bring data to life with SVG, Canvas and HTML. ððð
-
Recommend Topics
-
javascript
JavaScript (JS) is a lightweight interpreted programming language with first-class functions.
-
web
Some thing interesting about web. New door for the world.
-
server
A server is a program made to process requests and deliver data to clients.
-
Machine learning
Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.
-
Visualization
Some thing interesting about visualization, use data art
-
Game
Some thing interesting about game, make everyone happy.
Recommend Org
-
Facebook
We are working to build community through open source technology. NB: members must have two-factor auth.
-
Microsoft
Open source projects and samples from Microsoft.
-
Google
Google âĪïļ Open Source for everyone.
-
Alibaba
Alibaba Open Source for everyone
-
D3
Data-Driven Documents codes.
-
Tencent
China tencent open source team.
from libpnet.