Giter Site home page Giter Site logo

Host-unreachable replies about multi-ping HOT 1 OPEN

romana avatar romana commented on July 24, 2024 1
Host-unreachable replies

from multi-ping.

Comments (1)

sheffieldnikki avatar sheffieldnikki commented on July 24, 2024

Agreed! treating "host unreachable" reply packets as a non-reply is essential. Based on the above, this is my version which also does a better check to distinguish IPv4 from IPv6 packets:

# Some offsets we use when extracting data from the header
_ICMP_VER_OFFSET       = 0

                try:
                    pkt_id = None
                    pkt_ident = None
                    pkt_ver = pkt[_ICMP_VER_OFFSET] >> 4
                    if pkt_ver == 6 and \
                       pkt[_ICMPV6_HDR_OFFSET] == _ICMPV6_ECHO_REPLY:

                        pkt_id = (pkt[_ICMPV6_ID_OFFSET] << 8) + \
                            pkt[_ICMPV6_ID_OFFSET + 1]
                        pkt_ident = (pkt[_ICMPV6_IDENT_OFFSET] << 8) + \
                            pkt[_ICMPV6_IDENT_OFFSET + 1]
                        payload = pkt[_ICMPV6_PAYLOAD_OFFSET:]

                    elif pkt_ver == 4 and \
                       pkt[_ICMP_HDR_OFFSET] == _ICMP_ECHO_REPLY:

                        pkt_id = (pkt[_ICMP_ID_OFFSET] << 8) + \
                            pkt[_ICMP_ID_OFFSET + 1]
                        pkt_ident = (pkt[_ICMP_IDENT_OFFSET] << 8) + \
                            pkt[_ICMP_IDENT_OFFSET + 1]
                        payload = pkt[_ICMP_PAYLOAD_OFFSET:]
                    
                    else:
                        # Silently ignore other ICMP packet types (not _ECHO_REPLY)
                        pass

Possibly could be improved further by extracting the pkt_id/pkt_ident for other ICMP packet types, and removing those from self._remaining_ids without setting the results dict? That would allow the function to return sooner in the event of non-ECHO_REPLY packets, instead of waiting for timeout.

from multi-ping.

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.