本文整理汇总了Java中org.jnetpcap.packet.PcapPacket.getHeader方法的典型用法代码示例。如果您正苦于以下问题:Java PcapPacket.getHeader方法的具体用法?Java PcapPacket.getHeader怎么用?Java PcapPacket.getHeader使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jnetpcap.packet.PcapPacket
的用法示例。
在下文中一共展示了PcapPacket.getHeader方法的7个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: setPacket
import org.jnetpcap.packet.PcapPacket; //导入方法依赖的package包/类
/**
* Set the value of the field packet
* @param packet the new packet to set
*/
public boolean setPacket(final PcapPacket packet) {
boolean unkown = false;
_packet = packet;
eth = packet.getHeader(new Ethernet());
ip = packet.getHeader(new Ip4());
tcp = packet.getHeader(new Tcp());
if (tcp == null) {
udp = packet.getHeader(new Udp());
if (udp == null) {
icmp = packet.getHeader(new Icmp());
if (icmp == null) {
unkown = true;
setProtocol(Protocol.OTHER);
} else {
setProtocol(Protocol.ICMP);
}
} else {
setProtocol(Protocol.UDP);
}
} else {
setProtocol(Protocol.TCP);
}
return !unkown;
}
示例2: meetCriteria
import org.jnetpcap.packet.PcapPacket; //导入方法依赖的package包/类
@Override
public Boolean meetCriteria(PcapPacket itemToCheck)
{
if (!itemToCheck.hasHeader(Ip4.ID))
return false;
Ip4 ipHeader = new Ip4();
ipHeader = itemToCheck.getHeader(ipHeader);
if (direction == null) //direction wasn't set, so any direction
return subnetInfo.isInRange(ipHeader.sourceToInt()) || subnetInfo.isInRange(ipHeader.destinationToInt());
switch(direction)
{
case Incoming: return subnetInfo.isInRange(ipHeader.sourceToInt());
case Outgoing: return subnetInfo.isInRange(ipHeader.destinationToInt());
default: return null; //doesn't get here
}
}
示例3: meetCriteria
import org.jnetpcap.packet.PcapPacket; //导入方法依赖的package包/类
@Override
public Boolean meetCriteria(PcapPacket itemToCheck)
{
if (!itemToCheck.hasHeader(Ethernet.ID))
return false;
Ethernet eth = new Ethernet();
eth = itemToCheck.getHeader(eth);
switch (direction)
{
case Incoming:
return Arrays.equals(ownMAC, eth.destination());
case Outgoing:
return Arrays.equals(ownMAC, eth.source());
default:
return false; //doesn't get here
}
}
示例4: testCompare2SetsOfPackets2
import org.jnetpcap.packet.PcapPacket; //导入方法依赖的package包/类
/**
* Test compare2 sets of packets2.
*
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public void testCompare2SetsOfPackets2() throws IOException {
List<PcapPacket> l1 = getPacketList(L2TP);
List<PcapPacket> l2 = getPacketList(L2TP);
Ip4 ip1 = new Ip4();
Ip4 ip2 = new Ip4();
assertEquals(l1.size(), l2.size());
System.out.println("------------------------------\n");
for (int i = 0; i < l1.size(); i++) {
PcapPacket p1 = l1.get(i);
PcapPacket p2 = l2.get(i);
p1.getHeader(ip1);
p2.getHeader(ip2);
assertTrue("ip1.size() == p2.size()", p1.size() == p2.size());
assertTrue(ip1.toString(), ip1.isChecksumValid());
assertTrue(ip2.toString(), ip2.isChecksumValid());
assertTrue(compareJBuffer(p1, p2));
}
}
示例5: nextPacket
import org.jnetpcap.packet.PcapPacket; //导入方法依赖的package包/类
@Override
public void nextPacket(PcapPacket packet, Void nothing)
{
if (isFirstPacket)
{
if (captureStartListener != null) //notify on first packet captured
captureStartListener.captureStartedNotification();
isFirstPacket = false;
}
if (packet.hasHeader(Ip4.ID) && (protocolsToCount.isEmpty() || isSelectedProtocol(packet))) //only if there's an IP layer, and if any filter is selected, filter it
{
Ip4 ipHeader = new Ip4();
ipHeader = packet.getHeader(ipHeader);
int sourceInt = ipHeader.sourceToInt();
int destInt = ipHeader.destinationToInt();
int key;
if (ownIpInt == sourceInt)
key = destInt;
else
if (ownIpInt == destInt)
key = sourceInt;
else //not relevant to us
return;
Integer repeats = ipToAmountOfRepeats.get(key);
if (repeats == null) //first time we see this ip
ipToAmountOfRepeats.put(key, 1);
else
ipToAmountOfRepeats.put(key, repeats + 1);
}
}
示例6: TCPPacket
import org.jnetpcap.packet.PcapPacket; //导入方法依赖的package包/类
public TCPPacket(PcapPacket packet) {
packetTime = Instant.now();
Ip4 ip4 = packet.getHeader(new Ip4());
Tcp tcp = packet.getHeader(new Tcp());
connectionInfo = new TCPConnectionInfo(ip4.sourceToInt(), tcp.source(), ip4.destinationToInt(), tcp.destination());
seqNumber = tcp.seq();
ackNumber = tcp.ack();
tcpFlags = tcp.flags();
JBuffer storage = new JBuffer(JMemory.Type.POINTER);
JBuffer packetPayload = tcp.peerPayloadTo(storage);
payload = new byte[packetPayload.size()];
packetPayload.getByteArray(0, payload);
}
示例7: testHttpFormattingWithResolveAddressDisabled
import org.jnetpcap.packet.PcapPacket; //导入方法依赖的package包/类
/**
* Test http formatting with resolve address disabled.
*
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public void testHttpFormattingWithResolveAddressDisabled() throws IOException {
PcapPacket packet = TestUtils.getPcapPacket("tests/test-http-jpeg.pcap", 5);
assertTrue("Can't find HTTP header", packet.hasHeader(JProtocol.HTTP_ID));
Html html = packet.getHeader(new Html());
assertNotNull("Can't find HTML header", html);
System.out.printf("link related tags=%s\n", Arrays.asList(html.links())
.toString());
System.out.printf("All tags=%s\n", Arrays.asList(html.tags()).toString());
}