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


Java Ethernet.source方法代码示例

本文整理汇总了Java中org.jnetpcap.protocol.lan.Ethernet.source方法的典型用法代码示例。如果您正苦于以下问题:Java Ethernet.source方法的具体用法?Java Ethernet.source怎么用?Java Ethernet.source使用的例子?那么恭喜您, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在org.jnetpcap.protocol.lan.Ethernet的用法示例。


在下文中一共展示了Ethernet.source方法的3个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。

示例1: creatPacket

import org.jnetpcap.protocol.lan.Ethernet; //导入方法依赖的package包/类
private JMemoryPacket creatPacket(final InetAddress destIp, final InetAddress sourceIP) {
	final int packetSize = 500;
	final JMemoryPacket packet = new JMemoryPacket(packetSize);
	packet.order(ByteOrder.BIG_ENDIAN);
	packet.setUShort(0 + 12, 0x800); // ethernet.type field
	packet.scan(Ethernet.ID);

	final Ethernet ethernet = packet.getHeader(new Ethernet());
	ethernet.destination(destIp.getAddress());
	ethernet.source(sourceIP.getAddress());

	packet.setUByte(14, 0x04 | 0x05); // ip v4
	packet.scan(Ethernet.ID);

	//			final JPacket sendPacket = new JMemoryPacket(JProtocol.ETHERNET_ID, " 001801bf 6adc0025 4bb7afec 08004500 "
	//					+ " 0041a983 40004006 d69ac0a8 00342f8c " + " ca30c3ef 008f2e80 11f52ea8 4b578018 "
	//					+ " ffffa6ea 00000101 080a152e ef03002a " + " 2c943538 322e3430 204e4f4f 500d0a");

	final Ip4 sendPacketIP = packet.getHeader(new Ip4());
	//			sendPacketIP.destination(destIp.getAddress());
	sendPacketIP.type(0x06); //TCP
	sendPacketIP.length(packetSize - ethernet.size());
	sendPacketIP.ttl(1);

	packet.setUByte(46, 0x50); // TCP
	packet.scan(Ethernet.ID);

	final Tcp sendPacketTcp = packet.getHeader(new Tcp());
	sendPacketTcp.destination(80);
	sendPacketIP.checksum(sendPacketIP.calculateChecksum());
	sendPacketTcp.checksum(sendPacketTcp.calculateChecksum());

	final Payload payload = packet.getHeader(new Payload());
	payload.setByteArray(1, "Neko".getBytes());
	return packet;
}
 
开发者ID:leolewis,项目名称:openvisualtraceroute,代码行数:37,代码来源:JNetCapTraceRoute.java

示例2: test1

import org.jnetpcap.protocol.lan.Ethernet; //导入方法依赖的package包/类
/**
	 * Test1.
	 */
	public void test1() {
		
		JMemoryPacket packet = new JMemoryPacket(64);
		packet.order(ByteOrder.BIG_ENDIAN);
		packet.setUShort(0 + 12, 0x800);
		packet.setUByte(14 + 0, 0x45);
		System.out.println(packet.toHexdump());
		packet.setUByte(14 + 9, 0x11); //UDP
		System.out.println(packet.toHexdump());
		packet.scan(JProtocol.ETHERNET_ID);
		Ethernet eth = packet.getHeader(new Ethernet());
		Ip4 ip = packet.getHeader(new Ip4());
		Udp udp = packet.getHeader(new Udp());
//		udp.transferFrom(getFakeData(1460)); //Generate Random bytes
		eth.destination(new byte[] {(byte) 0xaa, 0x0c, 0x08, 11, 22, 33});
		eth.source(new byte[] {(byte) 0xaa, 0x0c, 0x08, 11, 22, 34});
		ip.flags(0);
		ip.tos(0);
		ip.source(new byte[] {(byte) 192, (byte) 168, 18, (byte) 218});
		ip.setByteArray(16, new byte[] {(byte) 192,(byte) 168, 18, (byte) 219});
		
		ip.checksum(0);
		System.out.printf("crc=0x%X ip.len=%d\n", Checksum.inChecksum(ip, 0, ip.size()), ip.size());
		ip.checksum(Checksum.inChecksum(ip, 0, ip.size()));
		System.out.println(packet.getState().toDebugString());
		
		System.out.printf("crc=0x%X\n", Checksum.inChecksum(ip, 0, ip.size()));
		
		JBuffer b = new JBuffer(4);
		
		b.order(ByteOrder.LITTLE_ENDIAN);
		b.setUInt(0, 0x14010100);	
		System.out.printf("0x%X\n%s", 0x14010100, b.toHexdump());
		
		b.order(ByteOrder.BIG_ENDIAN);
		b.setUInt(0, 0x14010100);	
		System.out.printf("0x%X\n%s", 0x14010100, b.toHexdump());
	}
 
开发者ID:pvenne,项目名称:jgoose,代码行数:42,代码来源:Bug2878768_jmemory_packet_int.java

示例3: makeNewPacket

import org.jnetpcap.protocol.lan.Ethernet; //导入方法依赖的package包/类
public void makeNewPacket(IEC61850_GOOSE_Task transmit_task) throws IEC61850_GOOSE_Exception
{
	
	// We initialise the new packet
	JMemoryPacket local_goose_memoryPacket = new JMemoryPacket(packetSize);
	local_goose_memoryPacket.order(java.nio.ByteOrder.BIG_ENDIAN);
	
	// decodes the packet. Assign ETHERNET type to the first header
	local_goose_memoryPacket.scan(JProtocol.ETHERNET_ID);
	
	// We set the Ethernet source and destination
	Ethernet eth_header = local_goose_memoryPacket.getHeader( new Ethernet() );
	
	eth_header.destination(FormatUtils.toByteArray(destinationMacAddress.replaceAll("-", "")));
	eth_header.source(FormatUtils.toByteArray(sourceMacAddress.replaceAll("-", "")));
	
	// We identify the next header as GOOSE
	eth_header.type(0x88b8);
	
	// set GOOSE header length to a possible value for the GOOSE header to be identified
	local_goose_memoryPacket.setByte(17, (byte)(packetSize - 14));
	
	// We need to rescan to identify the goose header
	local_goose_memoryPacket.scan(JProtocol.ETHERNET_ID); 
	
	// Permanently stores the packet state and data information
	byte[] permanent_memory = new byte[local_goose_memoryPacket.getTotalSize()];
	JBuffer permanent_buffer = new JBuffer(permanent_memory);
	local_goose_memoryPacket.transferStateAndDataTo(permanent_buffer, 0);
	
	local_goose_memoryPacket.peerStateAndData(permanent_buffer);
	
	// We create a new GOOSE header object
	IEC61850_GOOSE_Header local_goose_header = local_goose_memoryPacket.getHeader( new IEC61850_GOOSE_Header());
	
	local_goose_header.encodeHeader(goCBref_length, timeAllowedToLive_length, 
			datSet_length, goID_length, stNum_length, sqNum_length, test_length, 
			confRevGoose_length, ndsCom_length, numDatSetEntries_length, allData_length);
	
	// We need to rescan because the goose header length has changed
	local_goose_memoryPacket.scan(JProtocol.ETHERNET_ID);
	
	// There is a BUG in JNetPcap, function packet.scan() does not update packet length
	// We now adjust the packet size
	local_goose_memoryPacket.setSize(local_goose_header.length() + eth_header.getLength());
		
	// Now we populate all constant fields of the header
	local_goose_header.goCBref(goCBref);
	local_goose_header.datSet(datSet);
	local_goose_header.goID(goID);
	local_goose_header.test(test);
	local_goose_header.ndsCom(ndsCom);
	local_goose_header.timeAllowedToLive(timeAllowedToLive);
	local_goose_header.confRev(confRevGoose);
	local_goose_header.numDatSetEntries(numDatSetEntries);
	local_goose_header.appID(appID);
	
	
	transmit_task.goose_header = local_goose_header;
	transmit_task.goose_memoryPacket = local_goose_memoryPacket;
}
 
开发者ID:pvenne,项目名称:jgoose,代码行数:62,代码来源:IEC61850_GOOSE_Frame.java


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