本文整理汇总了Java中org.pcap4j.packet.IpV4Packet类的典型用法代码示例。如果您正苦于以下问题:Java IpV4Packet类的具体用法?Java IpV4Packet怎么用?Java IpV4Packet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
IpV4Packet类属于org.pcap4j.packet包,在下文中一共展示了IpV4Packet类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: getIpV4Packet_pppoe
import org.pcap4j.packet.IpV4Packet; //导入依赖的package包/类
IpV4Packet getIpV4Packet_pppoe(EthernetPacket packet_eth) throws IllegalRawDataException{
IpV4Packet ipV4Packet=null;
byte[] pppData=packet_eth.getPayload().getRawData();
if(pppData.length>8&&pppData[8]==0x45){
byte[] b2=new byte[2];
System.arraycopy(pppData, 4, b2, 0, 2);
short len=(short) ByteShortConvert.toShort(b2, 0);
int ipLength=toUnsigned(len)-2;
byte[] ipData=new byte[ipLength];
//设置ppp参数
PacketUtils.pppHead_static[2]=pppData[2];
PacketUtils.pppHead_static[3]=pppData[3];
if(ipLength==(pppData.length-8)){
System.arraycopy(pppData, 8, ipData, 0, ipLength);
ipV4Packet=IpV4Packet.newPacket(ipData, 0, ipData.length);
}else {
MLog.println("长度不符!");
}
}
return ipV4Packet;
}
开发者ID:gmirr,项目名称:finalspeed-91yun,代码行数:22,代码来源:CapEnv.java
示例2: getIpV4Packet_pppoe
import org.pcap4j.packet.IpV4Packet; //导入依赖的package包/类
IpV4Packet getIpV4Packet_pppoe(EthernetPacket packet_eth) throws IllegalRawDataException{
IpV4Packet ipV4Packet=null;
byte[] pppData=packet_eth.getPayload().getRawData();
if(pppData.length>8&&pppData[8]==0x45){
byte[] b2=new byte[2];
System.arraycopy(pppData, 4, b2, 0, 2);
short len=(short) ByteShortConvert.toShort(b2, 0);
int ipLength=toUnsigned(len)-2;
byte[] ipData=new byte[ipLength];
//设置ppp参数
PacketUtils.pppHead_static[2]=pppData[2];
PacketUtils.pppHead_static[3]=pppData[3];
if(ipLength==(pppData.length-8)){
System.arraycopy(pppData, 8, ipData, 0, ipLength);
ipV4Packet=IpV4Packet.newPacket(ipData, 0, ipData.length);
}else {
MLog.println("Length don't match!");
}
}
return ipV4Packet;
}
开发者ID:RCD-Y,项目名称:FinalSpeed-X,代码行数:22,代码来源:CapEnv.java
示例3: validatePacket
import org.pcap4j.packet.IpV4Packet; //导入依赖的package包/类
/**
* Validate packet
*
* @param packet
* @return
*/
public boolean validatePacket(Packet packet) {
validPacket = true;
if(packet.get(IpV4Packet.class) == null){
validPacket = false;
}else if (defaultSrcAddress == null) {
return true;
} else if (!packet.get(IpV4Packet.class).getHeader().getProtocol().name().equals(protocolType)) {
validPacket = false;
} else {
// check src/dst port combination
currentSrcAddressPort = packet.get(IpV4Packet.class).getHeader().getSrcAddr().getHostAddress() + ":" + getSrcPort(packet);
currentDstAddressPort = packet.get(IpV4Packet.class).getHeader().getDstAddr().getHostAddress() + ":" + getDstPort(packet);
if ((!currentSrcAddressPort.equals(defaultSrcAddressPort) && !currentSrcAddressPort.equals(defaultDstAddressPort))
|| (!currentDstAddressPort.equals(defaultSrcAddressPort) && !currentDstAddressPort.equals(defaultDstAddressPort))) {
validPacket = false;
}
}
return validPacket;
}
开发者ID:exalt-tech,项目名称:trex-stateless-gui,代码行数:26,代码来源:PacketUpdater.java
示例4: updateSrcAddress
import org.pcap4j.packet.IpV4Packet; //导入依赖的package包/类
/**
* 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;
}
开发者ID:exalt-tech,项目名称:trex-stateless-gui,代码行数:22,代码来源:PacketUpdater.java
示例5: updateDstAddress
import org.pcap4j.packet.IpV4Packet; //导入依赖的package包/类
/**
* 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;
}
开发者ID:exalt-tech,项目名称:trex-stateless-gui,代码行数:21,代码来源:PacketUpdater.java
示例6: buildIPV4Packet
import org.pcap4j.packet.IpV4Packet; //导入依赖的package包/类
/**
* Build IPV4 packet
*
* @param packetData
* @return
* @throws IOException
* @throws InterruptedException
* @throws PcapNativeException
* @throws NotOpenException
* @throws java.net.URISyntaxException
*/
public TrexEthernetPacket buildIPV4Packet(PacketData packetData) throws IOException, InterruptedException, PcapNativeException, NotOpenException, URISyntaxException {
LOG.info("create ethernet packet");
int packetLength = PacketBuilderHelper.getPacketLength(packetData.getPacketLength().getLengthType(), packetData.getPacketLength().getFrameLength(), packetData.getPacketLength().getMaxLength());
Payload payload = packetUtil.getPayload(packetData.getPayload());
TrexEthernetPacket ethernetPacket = packetUtil.prepareEthernetPacket(packetData, packetLength, payload);
// define VLAN
IpV4Packet.Builder ipV4Packet = getIPV4PacketBuilder(PacketBuilderHelper.getIPV4TotalLength(packetData.isTaggedVlan()), packetLength, payload, packetData);
if (!packetData.isTaggedVlan()) {
LOG.info("Add IPV4 packet");
ethernetPacket.buildPacket(ipV4Packet);
} else {
packetUtil.addVlanToPacket(ethernetPacket, ipV4Packet);
}
return ethernetPacket;
}
开发者ID:exalt-tech,项目名称:trex-stateless-gui,代码行数:30,代码来源:AbstractIPV4Test.java
示例7: matchesDestination
import org.pcap4j.packet.IpV4Packet; //导入依赖的package包/类
public static boolean matchesDestination(
Packet packet, Inet4Address addr, Inet4Address subnetmask
) {
IpV4Packet ipv4Packet = packet.get(IpV4Packet.class);
if (ipv4Packet == null) {
throw new IllegalArgumentException(packet.toString());
}
Inet4Address dstAddr = ipv4Packet.getHeader().getDstAddr();
if (dstAddr.equals(addr)) {
return true;
}
if (!isSameNetwork(addr, dstAddr, subnetmask)) {
return false;
}
return isBroadcastAddr(dstAddr, subnetmask);
}
开发者ID:kaitoy,项目名称:sneo,代码行数:20,代码来源:IpV4Helper.java
示例8: gotPacket
import org.pcap4j.packet.IpV4Packet; //导入依赖的package包/类
public void gotPacket(Packet packet) {
NetworkInterface getter = nifs.get(ifName);
if (packet.contains(IpV4Packet.class)) {
handleIpV4(packet, getter);
}
if (packet.contains(IpV6Packet.class)) {
if (packet.contains(IcmpV6NeighborSolicitationPacket.class)) {
handleIcmpV6Ns(packet, getter);
}
else if (packet.contains(IcmpV6NeighborAdvertisementPacket.class)) {
handleIcmpV6Na(packet, getter);
}
else {
handleIpV6(packet, getter);
}
}
else if (packet.contains(ArpPacket.class)) {
handleArp(packet, getter);
}
}
开发者ID:kaitoy,项目名称:sneo,代码行数:21,代码来源:Node.java
示例9: onEvent
import org.pcap4j.packet.IpV4Packet; //导入依赖的package包/类
@Override
public void onEvent(PacketContainer container, long sequence, boolean endOfBatch) throws Exception {
IpV4Packet ipV4Packet = container.getIpV4Packet();
if (ipV4Packet == null) {
return;
}
IpV4Packet.IpV4Header ipV4Header = ipV4Packet.getHeader();
if (!ipV4Header.getMoreFragmentFlag() && ipV4Header.getFragmentOffset() == 0) {
return;
}
int identification = ipV4Header.getIdentificationAsInt();
if (shouldSkipEvent(identification, order, total)) {
return;
}
// It seems to be the best place to call 'checkExpired()'...
checkExpired();
FragmentedPackets fragmentedPackets = accumulator.computeIfAbsent(identification, i -> new FragmentedPackets());
fragmentedPackets.addPacket(ipV4Packet);
if (fragmentedPackets.isAllPacketsReceived()) {
try {
container.setIpV4Packet(IpV4Helper.defragment(fragmentedPackets.getPackets()));
} finally {
accumulator.remove(identification);
}
} else {
container.setIpV4Packet(null);
}
}
开发者ID:sip3io,项目名称:tapir,代码行数:33,代码来源:PacketDefragmentator.java
示例10: isAllPacketsReceived
import org.pcap4j.packet.IpV4Packet; //导入依赖的package包/类
public boolean isAllPacketsReceived() {
if (!isLastPacketReceived) {
return false;
}
int expectedOffset = 0;
for (Map.Entry<Integer, IpV4Packet> entry : packets.entrySet()) {
int offset = entry.getKey();
if (offset != expectedOffset) {
return false;
}
IpV4Packet p = entry.getValue();
expectedOffset = offset + p.getHeader().getTotalLength() - 4 * p.getHeader().getIhl();
}
return true;
}
开发者ID:sip3io,项目名称:tapir,代码行数:16,代码来源:FragmentedPackets.java
示例11: addFragment
import org.pcap4j.packet.IpV4Packet; //导入依赖的package包/类
public void addFragment(int identification, IpV4Packet fragment) {
List<IpV4Packet> collected = fragments.get(identification);
if (collected == null) {
collected = new LinkedList<IpV4Packet>();
}
collected.add(fragment);
fragments.put(identification, collected);
}
开发者ID:rmcnew,项目名称:LiquidFortressPacketAnalyzer,代码行数:9,代码来源:IpDefragmenter.java
示例12: defragment
import org.pcap4j.packet.IpV4Packet; //导入依赖的package包/类
public IpV4Packet defragment(int identification) {
List<IpV4Packet> collected = fragments.get(identification);
if (collected == null) {
throw new IllegalArgumentException("No fragments collected for ID: " + identification);
}
fragments.remove(identification);
return IpV4Helper.defragment(collected);
}
开发者ID:rmcnew,项目名称:LiquidFortressPacketAnalyzer,代码行数:9,代码来源:IpDefragmenter.java
示例13: handleDnsResponse
import org.pcap4j.packet.IpV4Packet; //导入依赖的package包/类
/**
* Handles a responsePayload from an upstream DNS server
*
* @param requestPacket The original request packet
* @param responsePayload The payload of the response
*/
void handleDnsResponse(IpPacket requestPacket, byte[] responsePayload) {
UdpPacket udpOutPacket = (UdpPacket) requestPacket.getPayload();
UdpPacket.Builder payLoadBuilder = new UdpPacket.Builder(udpOutPacket)
.srcPort(udpOutPacket.getHeader().getDstPort())
.dstPort(udpOutPacket.getHeader().getSrcPort())
.srcAddr(requestPacket.getHeader().getDstAddr())
.dstAddr(requestPacket.getHeader().getSrcAddr())
.correctChecksumAtBuild(true)
.correctLengthAtBuild(true)
.payloadBuilder(
new UnknownPacket.Builder()
.rawData(responsePayload)
);
IpPacket ipOutPacket;
if (requestPacket instanceof IpV4Packet) {
ipOutPacket = new IpV4Packet.Builder((IpV4Packet) requestPacket)
.srcAddr((Inet4Address) requestPacket.getHeader().getDstAddr())
.dstAddr((Inet4Address) requestPacket.getHeader().getSrcAddr())
.correctChecksumAtBuild(true)
.correctLengthAtBuild(true)
.payloadBuilder(payLoadBuilder)
.build();
} else {
ipOutPacket = new IpV6Packet.Builder((IpV6Packet) requestPacket)
.srcAddr((Inet6Address) requestPacket.getHeader().getDstAddr())
.dstAddr((Inet6Address) requestPacket.getHeader().getSrcAddr())
.correctLengthAtBuild(true)
.payloadBuilder(payLoadBuilder)
.build();
}
eventLoop.queueDeviceWrite(ipOutPacket);
}
开发者ID:julian-klode,项目名称:dns66,代码行数:43,代码来源:DnsPacketProxy.java
示例14: testHandleDnsRequestNotUdpPacket
import org.pcap4j.packet.IpV4Packet; //导入依赖的package包/类
@Test
public void testHandleDnsRequestNotUdpPacket() throws Exception {
TcpPacket.Builder payLoadBuilder = new TcpPacket.Builder()
.srcPort(TcpPort.HTTP)
.dstPort(TcpPort.HTTP)
.srcAddr(InetAddress.getByAddress(new byte[]{8, 8, 4, 4}))
.dstAddr(InetAddress.getByAddress(new byte[]{8, 8, 8, 8}))
.correctChecksumAtBuild(true)
.correctLengthAtBuild(true)
.payloadBuilder(
new UnknownPacket.Builder()
.rawData(new byte[0])
);
IpPacket ipOutPacket = new IpV4Packet.Builder()
.version(IpVersion.IPV4)
.tos(IpV4Rfc791Tos.newInstance((byte) 0))
.protocol(IpNumber.UDP)
.srcAddr((Inet4Address) Inet4Address.getByAddress(new byte[]{8, 8, 4, 4}))
.dstAddr((Inet4Address) Inet4Address.getByAddress(new byte[]{8, 8, 8, 8}))
.correctChecksumAtBuild(true)
.correctLengthAtBuild(true)
.payloadBuilder(payLoadBuilder)
.build();
dnsPacketProxy.handleDnsRequest(ipOutPacket.getRawData());
assertNull(mockEventLoop.lastOutgoing);
assertNull(mockEventLoop.lastResponse);
}
开发者ID:julian-klode,项目名称:dns66,代码行数:30,代码来源:DnsPacketProxyTest.java
示例15: testHandleDnsRequestNotDnsPacket
import org.pcap4j.packet.IpV4Packet; //导入依赖的package包/类
@Test
public void testHandleDnsRequestNotDnsPacket() throws Exception {
UdpPacket.Builder payLoadBuilder = new UdpPacket.Builder()
.srcPort(UdpPort.HTTP)
.dstPort(UdpPort.HTTP)
.srcAddr(InetAddress.getByAddress(new byte[]{8, 8, 4, 4}))
.dstAddr(InetAddress.getByAddress(new byte[]{8, 8, 8, 8}))
.correctChecksumAtBuild(true)
.correctLengthAtBuild(true)
.payloadBuilder(
new UnknownPacket.Builder()
.rawData(new byte[]{1, 2, 3, 4, 5})
);
IpPacket ipOutPacket = new IpV4Packet.Builder()
.version(IpVersion.IPV4)
.tos(IpV4Rfc791Tos.newInstance((byte) 0))
.protocol(IpNumber.UDP)
.srcAddr((Inet4Address) Inet4Address.getByAddress(new byte[]{8, 8, 4, 4}))
.dstAddr((Inet4Address) Inet4Address.getByAddress(new byte[]{8, 8, 8, 8}))
.correctChecksumAtBuild(true)
.correctLengthAtBuild(true)
.payloadBuilder(payLoadBuilder)
.build();
dnsPacketProxy.handleDnsRequest(ipOutPacket.getRawData());
assertNull(mockEventLoop.lastOutgoing);
assertNull(mockEventLoop.lastResponse);
}
开发者ID:julian-klode,项目名称:dns66,代码行数:30,代码来源:DnsPacketProxyTest.java
示例16: testDnsQuery
import org.pcap4j.packet.IpV4Packet; //导入依赖的package包/类
@Test
public void testDnsQuery() throws Exception {
Message message = Message.newQuery(new ARecord(new Name("notblocked.example.com."),
0x01,
3600,
Inet4Address.getByAddress(new byte[]{0, 0, 0, 0})
));
UdpPacket.Builder payLoadBuilder = new UdpPacket.Builder()
.srcPort(UdpPort.DOMAIN)
.dstPort(UdpPort.DOMAIN)
.srcAddr(InetAddress.getByAddress(new byte[]{8, 8, 4, 4}))
.dstAddr(InetAddress.getByAddress(new byte[]{8, 8, 8, 8}))
.correctChecksumAtBuild(true)
.correctLengthAtBuild(true)
.payloadBuilder(
new UnknownPacket.Builder()
.rawData(message.toWire())
);
IpPacket ipOutPacket = new IpV4Packet.Builder()
.version(IpVersion.IPV4)
.tos(IpV4Rfc791Tos.newInstance((byte) 0))
.protocol(IpNumber.UDP)
.srcAddr((Inet4Address) Inet4Address.getByAddress(new byte[]{8, 8, 4, 4}))
.dstAddr((Inet4Address) Inet4Address.getByAddress(new byte[]{8, 8, 8, 8}))
.correctChecksumAtBuild(true)
.correctLengthAtBuild(true)
.payloadBuilder(payLoadBuilder)
.build();
dnsPacketProxy.handleDnsRequest(ipOutPacket.getRawData());
assertNull(mockEventLoop.lastResponse);
assertNotNull(mockEventLoop.lastOutgoing);
assertEquals(Inet4Address.getByAddress(new byte[]{8, 8, 8, 8}), mockEventLoop.lastOutgoing.getAddress());
}
开发者ID:julian-klode,项目名称:dns66,代码行数:38,代码来源:DnsPacketProxyTest.java
示例17: testNoQueryDnsQuery
import org.pcap4j.packet.IpV4Packet; //导入依赖的package包/类
@Test
public void testNoQueryDnsQuery() throws Exception {
Message message = new Message();
UdpPacket.Builder payLoadBuilder = new UdpPacket.Builder()
.srcPort(UdpPort.DOMAIN)
.dstPort(UdpPort.DOMAIN)
.srcAddr(InetAddress.getByAddress(new byte[]{8, 8, 4, 4}))
.dstAddr(InetAddress.getByAddress(new byte[]{8, 8, 8, 8}))
.correctChecksumAtBuild(true)
.correctLengthAtBuild(true)
.payloadBuilder(
new UnknownPacket.Builder()
.rawData(message.toWire())
);
IpPacket ipOutPacket = new IpV4Packet.Builder()
.version(IpVersion.IPV4)
.tos(IpV4Rfc791Tos.newInstance((byte) 0))
.protocol(IpNumber.UDP)
.srcAddr((Inet4Address) Inet4Address.getByAddress(new byte[]{8, 8, 4, 4}))
.dstAddr((Inet4Address) Inet4Address.getByAddress(new byte[]{8, 8, 8, 8}))
.correctChecksumAtBuild(true)
.correctLengthAtBuild(true)
.payloadBuilder(payLoadBuilder)
.build();
dnsPacketProxy.handleDnsRequest(ipOutPacket.getRawData());
assertNull(mockEventLoop.lastResponse);
assertNull(mockEventLoop.lastOutgoing);
dnsPacketProxy.handleDnsRequest(ipOutPacket.getRawData());
}
开发者ID:julian-klode,项目名称:dns66,代码行数:34,代码来源:DnsPacketProxyTest.java
示例18: createSyncAck
import org.pcap4j.packet.IpV4Packet; //导入依赖的package包/类
static Packet createSyncAck(
MacAddress srcAddress_mac,
MacAddress dstAddrress_mac,
Inet4Address srcAddress,short srcPort,
Inet4Address dstAddress,short dstPort,
int ack_sequence,int sequence,short ident){
TcpPacket.Builder builder_tcp=new TcpPacket.Builder();
//builder_tcp.payloadBuilder(new UnknownPacket.Builder().rawData(new byte[0]));
builder_tcp.correctChecksumAtBuild(true);
builder_tcp.correctLengthAtBuild(true);
builder_tcp.paddingAtBuild(true);
builder_tcp.ack(true);
builder_tcp.acknowledgmentNumber(ack_sequence);
//builder_tcp.checksum(tcpHeader.getChecksum());
//builder_tcp.dataOffset((byte) 8);
builder_tcp.dstAddr(dstAddress);
builder_tcp.dstPort(new TcpPort(dstPort,""));
//builder_tcp.fin(tcpHeader.getFin());
ArrayList<TcpOption> tcp_options=new ArrayList<TcpOption>();
TcpNoOperationOption nop=TcpNoOperationOption.getInstance();
TcpMaximumSegmentSizeOption seg_option=new TcpMaximumSegmentSizeOption.Builder().maxSegSize(mtu).correctLengthAtBuild(true).build();
tcp_options.add(seg_option);
tcp_options.add(nop);
tcp_options.add(nop);
TcpSackPermittedOption sack_permit_option=TcpSackPermittedOption.getInstance();
tcp_options.add(sack_permit_option);
tcp_options.add(nop);
TcpWindowScaleOption win_option=new TcpWindowScaleOption.Builder().shiftCount(shiftCount).correctLengthAtBuild(true).build();
tcp_options.add(win_option);
builder_tcp.options(tcp_options);
//builder_tcp.padding(tcpHeader.getPadding());
builder_tcp.psh(false);
builder_tcp.reserved((byte) 0);
builder_tcp.rst(false);
builder_tcp.sequenceNumber(sequence);
builder_tcp.srcAddr(srcAddress);
builder_tcp.srcPort(new TcpPort(srcPort,""));
builder_tcp.syn(true);
builder_tcp.urg(false);
//builder_tcp.urgentPointer(tcpHeader.getUrgentPointer());
builder_tcp.window( window);
IpV4Packet.Builder builder_ipv4=new IpV4Packet.Builder();
builder_ipv4.correctChecksumAtBuild(true);
builder_ipv4.correctLengthAtBuild(true);
builder_ipv4.paddingAtBuild(true);
builder_ipv4.dstAddr(dstAddress);
builder_ipv4.dontFragmentFlag(true);
builder_ipv4.fragmentOffset((short)0);
//builder_ipv4.headerChecksum(ipV4Header.getHeaderChecksum());
// short identification= Math.abs(random.nextInt(Short.MAX_VALUE));
builder_ipv4.identification(ident);
builder_ipv4.ihl((byte) 5);
//builder_ipv4.moreFragmentFlag(ipV4Header.getMoreFragmentFlag());
//builder_ipv4.options(ipV4Header.getOptions());
//builder_ipv4.padding(ipV4Header.getPadding());
builder_ipv4.protocol(IpNumber.TCP);
// builder_ipv4.reservedFlag(ipV4Header.getReservedFlag());
builder_ipv4.srcAddr(srcAddress);
builder_ipv4.tos(IpV4Rfc1349Tos.newInstance((byte) 0));
//builder_ipv4.totalLength( 52);
builder_ipv4.ttl(ttl);
builder_ipv4.version(IpVersion.IPV4);
builder_ipv4.payloadBuilder(builder_tcp);
//
Packet p = buildIpV4(srcAddress_mac,dstAddrress_mac,builder_ipv4);
return p;
}
开发者ID:RCD-Y,项目名称:FinalSpeed-X,代码行数:82,代码来源:PacketUtils.java
示例19: buildPacket
import org.pcap4j.packet.IpV4Packet; //导入依赖的package包/类
/**
*
* @param builder
* @param protocol
*/
public void buildPacket(AbstractPacket.AbstractBuilder builder, IpNumber protocol) {
byte[] pad = new byte[1];
String payloadPattern = payload.getPayloadPattern();
String payloadString = payload.getPayloadType().getPadPayloadString(payloadPattern, (totalLength - 20) * 2);
if (packetLength > DEFAULT_PACKET_LENGTH) {
payloadString = payload.getPayloadType().getPadPayloadString(payloadPattern, payloadString.length() + ((packetLength - DEFAULT_PACKET_LENGTH) * 2));
this.totalLength = (short) ((int) totalLength + (packetLength - DEFAULT_PACKET_LENGTH));
}
pad = payload.getPayloadPad(payloadString, totalLength - 20);
ipV4Builder = new IpV4Packet.Builder();
ipV4Builder.version(version)
.ihl(ihl)
.tos(tos)
.totalLength(totalLength)
.identification(identification)
.reservedFlag(reservedFlag)
.ttl(ttl)
.fragmentOffset((short) 0)
.protocol(protocol)
.headerChecksum(headerChecksum)
.srcAddr(srcAddr)
.dstAddr(dstAddr)
.protocol(protocol)
.correctChecksumAtBuild(true)
// .correctLengthAtBuild(true)
.payloadBuilder(builder);
if (protocol != IpNumber.TCP && protocol != IpNumber.UDP) {
ipV4Builder.paddingAtBuild(false)
.padding(pad);
} else {
ipV4Builder.paddingAtBuild(true).correctLengthAtBuild(true);
}
this.packet1 = ipV4Builder.build();
}
开发者ID:exalt-tech,项目名称:trex-stateless-gui,代码行数:45,代码来源:TrexIpV4Packet.java
示例20: updatePacketSrcDst
import org.pcap4j.packet.IpV4Packet; //导入依赖的package包/类
/**
* Update packet source/destination address
*
* @param packet
* @return
*/
public Packet updatePacketSrcDst(Packet packet) {
// initialze default src/dst address and protocol type
if (packet.get(IpV4Packet.class) != null) {
if (defaultSrcAddress == null && defaultDstAddress == null) {
initializeUpdater(packet);
}
packet = updateSrcAddress(packet);
packet = updateDstAddress(packet);
}
return packet;
}
开发者ID:exalt-tech,项目名称:trex-stateless-gui,代码行数:19,代码来源:PacketUpdater.java
注:本文中的org.pcap4j.packet.IpV4Packet类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论