Java Code Examples for org.pcap4j.packet.Packet#Builder
The following examples show how to use
org.pcap4j.packet.Packet#Builder .
You can vote up the ones you like or vote down the ones you don't like,
and go to the original project or source file by following the links above each example. You may check out the related API usage on the sidebar.
Example 1
Source File: PacketUpdater.java From trex-stateless-gui with Apache License 2.0 | 7 votes |
private Packet fixL3L4Checksums(Packet packet) { Packet.Builder builder = packet.getBuilder(); builder.get(IpV4Packet.Builder.class).correctChecksumAtBuild(true); TcpPacket.Builder tcpBuilder = builder.get(TcpPacket.Builder.class); if (tcpBuilder != null) { tcpBuilder.srcAddr(packet.get(IpV4Packet.class).getHeader().getSrcAddr()); tcpBuilder.dstAddr(packet.get(IpV4Packet.class).getHeader().getDstAddr()); tcpBuilder.correctChecksumAtBuild(true); } UdpPacket.Builder udpBuilder = builder.get(UdpPacket.Builder.class); if (udpBuilder != null) { udpBuilder.srcAddr(packet.get(IpV4Packet.class).getHeader().getSrcAddr()); udpBuilder.dstAddr(packet.get(IpV4Packet.class).getHeader().getDstAddr()); udpBuilder.correctChecksumAtBuild(true); } return builder.build(); }
Example 2
Source File: PacketUpdater.java From trex-stateless-gui with Apache License 2.0 | 6 votes |
/** * Update source IP address */ private Packet updateSrcAddress(Packet packet) { try { if (importedProperties.isSourceEnabled()) { Inet4Address modifiedAddress = (Inet4Address) Inet4Address.getByAddress(convertIPToByte(importedProperties.getSrcAddress())); Packet.Builder builder = packet.getBuilder(); if (packet.get(IpV4Packet.class).getHeader().getSrcAddr().getHostAddress().equals(defaultSrcAddress)) { builder.get(IpV4Packet.Builder.class).srcAddr(modifiedAddress); } else { builder.get(IpV4Packet.Builder.class).dstAddr(modifiedAddress); } packet = builder.build(); } } catch (Exception ex) { LOG.error("Error updating source IP", ex); } return packet; }
Example 3
Source File: PacketUpdater.java From trex-stateless-gui with Apache License 2.0 | 6 votes |
/** * Update destination IP address */ private Packet updateDstAddress(Packet packet) { try { if (importedProperties.isDestinationEnabled()) { Inet4Address modifiedAddress = (Inet4Address) Inet4Address.getByAddress(convertIPToByte(importedProperties.getDstAddress())); Packet.Builder builder = packet.getBuilder(); if (packet.get(IpV4Packet.class).getHeader().getDstAddr().getHostAddress().equals(defaultDstAddress)) { builder.get(IpV4Packet.Builder.class).dstAddr(modifiedAddress); } else { builder.get(IpV4Packet.Builder.class).srcAddr(modifiedAddress); } packet = builder.build(); } } catch (Exception ex) { LOG.error("Error updating destination IP", ex); } return packet; }