Exemple #1
0
def _buildEcho(req):
    if not isinstance(req, Icmp):
        req = base.extract(req, Icmp)
        if req is None:
            return None

    resp = Icmp()
    resp.type = TYPE_ECHO_REPLY
    resp.code = req.code
    resp.set_payload(req.next)
    resp.csum = 0
    resp.csum = computeChecksum(resp.pack(), 0)

    return resp
Exemple #2
0
def checksum(pkt):
    icmpPkt = base.extract(pkt, Icmp)
    if not icmpPkt:
        return 0

    s = icmpPkt.hdr()
    h = icmpPkt.next

    while h is not None:
        m = getattr(h, "hdr", None)
        if m is None:
            s = "%s%s" % (s, str(h))
            break
        s = "%s%s" % (s, h.hdr())
        m = getattr(h, "next", None)
        if m is None:
            break
        h = m

    return computeChecksum(s, 0)