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


Java Ethernet.type方法代码示例

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


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

示例1: updateFrame_From_UnknownPacket

import org.jnetpcap.protocol.lan.Ethernet; //导入方法依赖的package包/类
public void updateFrame_From_UnknownPacket(JPacket local_jPacket) throws IEC61850_GOOSE_Exception
{
	// We initialise empty headers. Required to decode the packet.
	Ethernet eth_header = new Ethernet();
       IEEE802dot1q dot1q_header = new IEEE802dot1q();
       IEC61850_GOOSE_Header goose_header = new IEC61850_GOOSE_Header();
       
       if (local_jPacket.hasHeader(eth_header)) 
       {  
       	this.destinationMacAddress = FormatUtils.mac(eth_header.destination());
   		this.sourceMacAddress = FormatUtils.mac(eth_header.source());
       }
       else
       {
       	throw new IEC61850_GOOSE_Exception("Typing to decode an unknown packet of a type that is not of type Ethernet: " 
       			+ "Frame number: " + local_jPacket.getFrameNumber() 
       			+ "Ethernet source: " +  FormatUtils.mac(eth_header.source())
       			+ "Ethernet destination: " +  FormatUtils.mac(eth_header.destination())
       			+ "Packet type: " + eth_header.type());
       }
       // We have to check for IEEE 802.1Q NOTE: Q in Q not supported
       if (local_jPacket.hasHeader(dot1q_header))
       {
       	/* May be usefull in the future
       	int dot1q_priority = dot1q_header.priority();
       	int dot1q_cfi = dot1q_header.cfi();
       	int dot1q_id = dot1q_header.id();
       	*/
       }
   	
       if (local_jPacket.hasHeader(goose_header))
       {
       	if (goose_header.isValidHeader() == false)
        	throw new IEC61850_GOOSE_Exception("Typing to decode an unknown packet that does not have a GOOSE header: " 
        			+ "Frame number: " + local_jPacket.getFrameNumber() 
        			+ "GOOSE header error: " +  goose_header.headerError);
       	
       	else
       	{
       		// We decode the content of the header
       		this.appID = goose_header.appID();
       		
       		this.goCBref = goose_header.goCBref();
       		this.datSet = goose_header.datSet();
       		this.goID = goose_header.goID();

       		this.test = goose_header.test();
       		this.ndsCom = goose_header.ndsCom();
       		this.stNum = goose_header.stNum();
       		this.sqNum = goose_header.sqNum();
       		this.timeAllowedToLive = goose_header.timeAllowedToLive();
       		this.confRevGoose = goose_header.confRev();
       		this.numDatSetEntries = goose_header.numDatSetEntries();
       		
       		// Reading the time in the header updates the time quality information
       		this.utc_time = goose_header.utc();
       		
       		this.leapSecondsKnown = goose_header.leapSecondsKnown;
       		this.clockFailure = goose_header.clockFailure;
       		this.clockNotSynchronized = goose_header.clockNotSynchronized;
       		this.timeAccuracy = goose_header.timeAccuracy;
       		
       		// We set the data length
       		stNum_length = sizeOf(stNum);
       		sqNum_length = sizeOf(sqNum);
   
       		// Verify frame validity
       		if ((new Date()).getTime() - this.utc_time > this.timeAllowedToLive)
       			frameValidity = IEC61850_GOOSE_FrameValidityType.questionable;
       		else
       			frameValidity = IEC61850_GOOSE_FrameValidityType.good;
       		
       		// We read the payload
       		gooseData = new IEC61850_GOOSE_Data(goose_header.numDatSetEntries());
       		
       		// We decode the data
       		gooseData.decodeData(goose_header.gooseData());
       	}
       }
}
 
开发者ID:pvenne,项目名称:jgoose,代码行数:81,代码来源:IEC61850_GOOSE_Frame.java

示例2: 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

示例3: bindToEthernet

import org.jnetpcap.protocol.lan.Ethernet; //导入方法依赖的package包/类
/**
 * Bind to ethernet.
 * 
 * @param packet
 *          the packet
 * @param eth
 *          the eth
 * @return true, if successful
 */
@Bind(to = Ethernet.class)
public static boolean bindToEthernet(JPacket packet, Ethernet eth) {
	return eth.type() == 0x8864;
}
 
开发者ID:pvenne,项目名称:jgoose,代码行数:14,代码来源:Bug_PPPoE.java

示例4: bindIp4ToEthernet

import org.jnetpcap.protocol.lan.Ethernet; //导入方法依赖的package包/类
/**
 * Bind ip4 to ethernet.
 * 
 * @param packet
 *          the packet
 * @param eth
 *          the eth
 * @return true, if successful
 */
@Bind(from = MyHeader.class, to = Ethernet.class, intValue = 0x800)
public static boolean bindIp4ToEthernet(JPacket packet, Ethernet eth) {
	return (eth.type() == 0x800);
}
 
开发者ID:pvenne,项目名称:jgoose,代码行数:14,代码来源:BindNetworkFamily.java

示例5: bindToEthernet

import org.jnetpcap.protocol.lan.Ethernet; //导入方法依赖的package包/类
/**
* Bind to ethernet.
* 
* @param packet
*          the packet
* @param eth
*          the eth
* @return true, if successful
*/
@Bind(to = Ethernet.class)
public static boolean bindToEthernet(JPacket packet, Ethernet eth) {
	return eth.type() == 0x800;
}
 
开发者ID:pvenne,项目名称:jgoose,代码行数:14,代码来源:MyHeader.java

示例6: bindIp4ToEthernet

import org.jnetpcap.protocol.lan.Ethernet; //导入方法依赖的package包/类
/**
 * Bind ip4 to ethernet.
 * 
 * @param packet
 *            the packet
 * @param eth
 *            the eth
 * @return true, if successful
 */
@Bind(from = Ip4.class, to = Ethernet.class)
public static boolean bindIp4ToEthernet(JPacket packet, Ethernet eth) {
	return eth.type() == 0x800;
}
 
开发者ID:pvenne,项目名称:jgoose,代码行数:14,代码来源:TestJRegistry.java


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