def buildArpRequest(srcMac, srcIp, dstIp): arpPkt = Arp() arpPkt.hwsrc = srcMac arpPkt.hwlen = 6 arpPkt.protolen = 4 arpPkt.opcode = Arp.REQUEST arpPkt.protosrc = srcIp arpPkt.protodst = dstIp arpPkt.parsed = True ethPkt = Ethernet() ethPkt.src = srcMac ethPkt.dst = ETHER_BROADCAST ethPkt.type = Ethernet.ARP_TYPE ethPkt.set_payload(arpPkt) ethPkt.parsed = True return ethPkt
def buildArpResponse(packet, mac): if not isinstance(packet, Arp): packet = base.extract(packet, Arp) if packet is None: return None resp = Arp() resp.hwdst = packet.hwsrc resp.protodst = packet.protosrc resp.hwsrc = mac resp.protosrc = packet.protodst resp.hwtype = Arp.HW_TYPE_ETHERNET resp.hwlen = 6 resp.prototype = Arp.PROTO_TYPE_IP resp.protolen = 4 resp.opcode = Arp.REPLY return resp