Giter Site home page Giter Site logo

Comments (4)

mkeeter avatar mkeeter commented on June 2, 2024

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.

rikonaka avatar rikonaka commented on June 2, 2024

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.

mkeeter avatar mkeeter commented on June 2, 2024

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.

rikonaka avatar rikonaka commented on June 2, 2024

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)

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo 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.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google âĪïļ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.