@Test public void createPacketFromPcapTest(){ ReflectionTestUtils.setField(service, "pcapngHelper", helper); byte[] data = new byte[64]; data[0] = 0; data[1] = 0; data[2] = 0; data[3] = 0; data[4] = 12; data[5] = 15; Packet packet = service.createPacketFromPcap(13, 1, 1, 1, data, "abcde"); assertNotNull(packet); assertEquals(packet.getData()[5], 15); }
@Override public Packet createPacketFromPcap(int datalink, long seconds, long microSeconds, int len, byte[] data, String pcapfile) { short network = 0; int hdrLen = 0; ByteBuffer bytes = ByteBuffer.wrap(data); try { switch (datalink) { case DLT_RAW: network = IPV4; break; case DLT_EN10MB: network = bytes.getShort(12); hdrLen = 14; break; case DLT_LINUX_SLL: network = bytes.getShort(14); hdrLen = 16; break; default: if (pcapfile != null) { try { if (pcapngHelper.isApplePcapng(pcapfile) || pcapngHelper.isNoLinkLayer(pcapfile)) { network = IPV4; hdrLen = 4; } } catch (IOException e) { LOGGER.error(e.getMessage()); } } break; } } catch (IndexOutOfBoundsException e) { LOGGER.error(e.getMessage()); } return createPacket(network, seconds, microSeconds, len, hdrLen, data); }
PacketServiceImpl implements IPacketService { @Override public Packet createPacketFromPcap(int datalink, long seconds, long microSeconds, int len, byte[] data, String pcapfile) { short network = 0; int hdrLen = 0; ByteBuffer bytes = ByteBuffer.wrap(data); try { switch (datalink) { case DLT_RAW: network = IPV4; break; case DLT_EN10MB: network = bytes.getShort(12); hdrLen = 14; break; case DLT_LINUX_SLL: network = bytes.getShort(14); hdrLen = 16; break; default: if (pcapfile != null) { try { if (pcapngHelper.isApplePcapng(pcapfile) || pcapngHelper.isNoLinkLayer(pcapfile)) { network = IPV4; hdrLen = 4; } } catch (IOException e) { LOGGER.error(e.getMessage()); } } break; } } catch (IndexOutOfBoundsException e) { LOGGER.error(e.getMessage()); } return createPacket(network, seconds, microSeconds, len, hdrLen, data); } }
PacketServiceImpl implements IPacketService { @Override public Packet createPacketFromPcap(int datalink, long seconds, long microSeconds, int len, byte[] data, String pcapfile) { short network = 0; int hdrLen = 0; ByteBuffer bytes = ByteBuffer.wrap(data); try { switch (datalink) { case DLT_RAW: network = IPV4; break; case DLT_EN10MB: network = bytes.getShort(12); hdrLen = 14; break; case DLT_LINUX_SLL: network = bytes.getShort(14); hdrLen = 16; break; default: if (pcapfile != null) { try { if (pcapngHelper.isApplePcapng(pcapfile) || pcapngHelper.isNoLinkLayer(pcapfile)) { network = IPV4; hdrLen = 4; } } catch (IOException e) { LOGGER.error(e.getMessage()); } } break; } } catch (IndexOutOfBoundsException e) { LOGGER.error(e.getMessage()); } return createPacket(network, seconds, microSeconds, len, hdrLen, data); }  }
PacketServiceImpl implements IPacketService { @Override public Packet createPacketFromPcap(int datalink, long seconds, long microSeconds, int len, byte[] data, String pcapfile) { short network = 0; int hdrLen = 0; ByteBuffer bytes = ByteBuffer.wrap(data); try { switch (datalink) { case DLT_RAW: network = IPV4; break; case DLT_EN10MB: network = bytes.getShort(12); hdrLen = 14; break; case DLT_LINUX_SLL: network = bytes.getShort(14); hdrLen = 16; break; default: if (pcapfile != null) { try { if (pcapngHelper.isApplePcapng(pcapfile) || pcapngHelper.isNoLinkLayer(pcapfile)) { network = IPV4; hdrLen = 4; } } catch (IOException e) { LOGGER.error(e.getMessage()); } } break; } } catch (IndexOutOfBoundsException e) { LOGGER.error(e.getMessage()); } return createPacket(network, seconds, microSeconds, len, hdrLen, data); }  @Override Packet createPacketFromPcap(int datalink, long seconds, long microSeconds, int len, byte[] data, String pcapfile); @Override Packet createPacketFromNetmon(int datalink, long seconds, long microSeconds, int len, byte[] data); @Override Packet createPacket(short network, long seconds, long microSeconds, int len, int datalinkHdrLen, byte[] data); }
PacketServiceImpl implements IPacketService { @Override public Packet createPacketFromPcap(int datalink, long seconds, long microSeconds, int len, byte[] data, String pcapfile) { short network = 0; int hdrLen = 0; ByteBuffer bytes = ByteBuffer.wrap(data); try { switch (datalink) { case DLT_RAW: network = IPV4; break; case DLT_EN10MB: network = bytes.getShort(12); hdrLen = 14; break; case DLT_LINUX_SLL: network = bytes.getShort(14); hdrLen = 16; break; default: if (pcapfile != null) { try { if (pcapngHelper.isApplePcapng(pcapfile) || pcapngHelper.isNoLinkLayer(pcapfile)) { network = IPV4; hdrLen = 4; } } catch (IOException e) { LOGGER.error(e.getMessage()); } } break; } } catch (IndexOutOfBoundsException e) { LOGGER.error(e.getMessage()); } return createPacket(network, seconds, microSeconds, len, hdrLen, data); }  @Override Packet createPacketFromPcap(int datalink, long seconds, long microSeconds, int len, byte[] data, String pcapfile); @Override Packet createPacketFromNetmon(int datalink, long seconds, long microSeconds, int len, byte[] data); @Override Packet createPacket(short network, long seconds, long microSeconds, int len, int datalinkHdrLen, byte[] data);  }