@Test public void getArpFromTest() throws Exception { Arp arp = new Arp(); byte[] sha = HexEncode.bytesFromHexString("00:00:00:00:00:01"); byte[] spa = InetAddress.getByName("192.168.0.1").getAddress(); byte[] tha = HexEncode.bytesFromHexString("00:00:00:00:00:02"); byte[] tpa = InetAddress.getByName("192.168.0.2").getAddress(); int htype = 1; int ptype = EtherTypes.IPv4.intValue(); short hlen = 6; short plen = 4; int operation = 1; arp.setSenderHardwareAddress(sha); arp.setSenderProtocolAddress(spa); arp.setTargetHardwareAddress(tha); arp.setTargetProtocolAddress(tpa); arp.setOperation(operation); arp.setHardwareLength(hlen); arp.setProtocolLength(plen); arp.setHardwareType(htype); arp.setProtocolType(ptype); Ethernet arpFrame = new Ethernet().setSourceMACAddress(sha) .setDestinationMACAddress(tha) .setEtherType(EtherTypes.ARP.shortValue()); arpFrame.setPayload(arp); PacketReceived packet = new PacketReceivedBuilder().setPayload(arpFrame.serialize()).build(); Arp arpOut = ArpResolverUtils.getArpFrom(packet); Assert.assertEquals(arp, arpOut); }
public static Arp getArpFrom(PacketReceived potentialArp) throws PacketException { byte[] payload = potentialArp.getPayload(); Ethernet ethPkt = new Ethernet(); ethPkt.deserialize(payload, 0, payload.length * NetUtils.NumBitsInAByte); if (ethPkt.getPayload() instanceof Arp) { return (Arp) ethPkt.getPayload(); } throw new PacketException("Packet is not ARP: " + potentialArp); }
ArpResolverUtils { public static Arp getArpFrom(PacketReceived potentialArp) throws PacketException { byte[] payload = potentialArp.getPayload(); Ethernet ethPkt = new Ethernet(); ethPkt.deserialize(payload, 0, payload.length * NetUtils.NumBitsInAByte); if (ethPkt.getPayload() instanceof Arp) { return (Arp) ethPkt.getPayload(); } throw new PacketException("Packet is not ARP: " + potentialArp); } }
ArpResolverUtils { public static Arp getArpFrom(PacketReceived potentialArp) throws PacketException { byte[] payload = potentialArp.getPayload(); Ethernet ethPkt = new Ethernet(); ethPkt.deserialize(payload, 0, payload.length * NetUtils.NumBitsInAByte); if (ethPkt.getPayload() instanceof Arp) { return (Arp) ethPkt.getPayload(); } throw new PacketException("Packet is not ARP: " + potentialArp); }  }
ArpResolverUtils { public static Arp getArpFrom(PacketReceived potentialArp) throws PacketException { byte[] payload = potentialArp.getPayload(); Ethernet ethPkt = new Ethernet(); ethPkt.deserialize(payload, 0, payload.length * NetUtils.NumBitsInAByte); if (ethPkt.getPayload() instanceof Arp) { return (Arp) ethPkt.getPayload(); } throw new PacketException("Packet is not ARP: " + potentialArp); }  static Arp getArpFrom(PacketReceived potentialArp); }
ArpResolverUtils { public static Arp getArpFrom(PacketReceived potentialArp) throws PacketException { byte[] payload = potentialArp.getPayload(); Ethernet ethPkt = new Ethernet(); ethPkt.deserialize(payload, 0, payload.length * NetUtils.NumBitsInAByte); if (ethPkt.getPayload() instanceof Arp) { return (Arp) ethPkt.getPayload(); } throw new PacketException("Packet is not ARP: " + potentialArp); }  static Arp getArpFrom(PacketReceived potentialArp);  }