当前位置: 首页>>代码示例>>Java>>正文


Java PcapPacket.getHeader方法代码示例

本文整理汇总了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;
}
 
开发者ID:leolewis,项目名称:openvisualtraceroute,代码行数:29,代码来源:JNetCapPacketPoint.java

示例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
	}
}
 
开发者ID:ck3ck3,项目名称:WhoWhatWhere,代码行数:20,代码来源:CriteriaIP.java

示例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
	}
}
 
开发者ID:ck3ck3,项目名称:WhoWhatWhere,代码行数:20,代码来源:CriteriaPacketDirection.java

示例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));

	}

}
 
开发者ID:pvenne,项目名称:jgoose,代码行数:32,代码来源:TestTcpIp.java

示例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);
	}
}
 
开发者ID:ck3ck3,项目名称:WhoWhatWhere,代码行数:38,代码来源:AppearanceCounterPacketHandler.java

示例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);
}
 
开发者ID:vincentzhang96,项目名称:HearthCaptureLib,代码行数:14,代码来源:TCPPacket.java

示例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());

}
 
开发者ID:pvenne,项目名称:jgoose,代码行数:21,代码来源:TestHtml.java


注:本文中的org.jnetpcap.packet.PcapPacket.getHeader方法示例由纯净天空整理自Github/MSDocs等开源代码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。