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


Java Checksum类代码示例

本文整理汇总了Java中org.jnetpcap.util.checksum.Checksum的典型用法代码示例。如果您正苦于以下问题:Java Checksum类的具体用法?Java Checksum怎么用?Java Checksum使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。


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

示例1: Generate_ArpReply

import org.jnetpcap.util.checksum.Checksum; //导入依赖的package包/类
public JPacket Generate_ArpReply(String MAC_SOURCE,String MAC_DESTINATION,String IP_SOURCE,String IP_DESTINATION){
	
	String Frame_WithoutCRC32=MAC_DESTINATION+MAC_SOURCE+DATA_TYPE+ARP_HEADER_REPLY+MAC_SOURCE+IP_SOURCE+MAC_DESTINATION+IP_DESTINATION+PADDING;
	
	JPacket arpRequest =new JMemoryPacket(JProtocol.ETHERNET_ID,Frame_WithoutCRC32);
	String CRC32=Integer.toHexString(Checksum.crc32IEEE802(arpRequest,0, arpRequest.size()));
	while(CRC32.length()<8){
		CRC32="0"+CRC32;
	}
	return new JMemoryPacket(JProtocol.ETHERNET_ID,Frame_WithoutCRC32+CRC32);
}
 
开发者ID:YassineFadhlaoui,项目名称:ARP-Spoofing,代码行数:12,代码来源:Create_EthernetFrame.java

示例2: calculateChecksum

import org.jnetpcap.util.checksum.Checksum; //导入依赖的package包/类
/**
 * Calculate checksum.
 * 
 * @return the long
 */
public int calculateChecksum() {
	if (getPostfixLength() < 4) {
		return 0;
	}

	final JPacket packet = getPacket();
	return Checksum.crc32IEEE802(packet, 0, getHeaderLength()
			+ getPayloadLength() + getPostfixLength() -4);
}
 
开发者ID:pvenne,项目名称:jgoose,代码行数:15,代码来源:Ethernet.java

示例3: calculateChecksum

import org.jnetpcap.util.checksum.Checksum; //导入依赖的package包/类
/**
 * Calculates a checksum using protocol specification for a header. Checksums
 * for partial headers or fragmented packets (unless the protocol allows it)
 * are not calculated.
 * 
 * @return header's calculated checksum
 */
public long calculateChecksum() {
	if (getPostfixLength() < 4) {
		return 0L;
	}
	
	final JPacket packet = getPacket();
	return Checksum.crc32IEEE802(packet, 0, packet.size() - 4);
}
 
开发者ID:pvenne,项目名称:jgoose,代码行数:16,代码来源:IEEE802dot3.java

示例4: calculateChecksum

import org.jnetpcap.util.checksum.Checksum; //导入依赖的package包/类
/**
 * Calculate checksum.
 * 
 * @return the int
 * @see org.jnetpcap.packet.JHeaderChecksum#calculateChecksum()
 */
@Override
public int calculateChecksum() {
	final JPacket packet = getPacket();
	return Checksum.inChecksum(packet, getHeaderOffset(), size()
			- getHeaderOffset());
}
 
开发者ID:pvenne,项目名称:jgoose,代码行数:13,代码来源:GRE.java

示例5: calculateChecksum

import org.jnetpcap.util.checksum.Checksum; //导入依赖的package包/类
/**
 * Calculates a checksum using protocol specification for a header. Checksums
 * for partial headers or fragmented packets (unless the protocol alows it)
 * are not calculated.
 * 
 * @return header's calculated checksum
 */
public int calculateChecksum() {

	if (getIndex() == -1) {
		throw new IllegalStateException("Oops index not set");
	}

	final int ipOffset = getPreviousHeaderOffset();

	return Checksum.inChecksumShouldBe(checksum(),
			Checksum.icmp(packet, ipOffset, this.getOffset()));
}
 
开发者ID:pvenne,项目名称:jgoose,代码行数:19,代码来源:Icmp.java

示例6: isChecksumValid

import org.jnetpcap.util.checksum.Checksum; //导入依赖的package包/类
/**
 * Checks if the checksum is valid, for un-fragmented packets. If a packet is
 * fragmented, the checksum is not verified as data to is incomplete, but the
 * method returns true none the less.
 * 
 * @return true if checksum checks out or if this is a fragment, otherwise if
 *         the computed checksum does not match the stored checksum false is
 *         returned
 */
public boolean isChecksumValid() {

	if (isFragmented()) {
		return true;
	}

	if (getIndex() == -1) {
		throw new IllegalStateException("Oops index not set");
	}

	final int ipOffset = getPreviousHeaderOffset();

	return Checksum.icmp(packet, ipOffset, this.getOffset()) == 0;
}
 
开发者ID:pvenne,项目名称:jgoose,代码行数:24,代码来源:Icmp.java

示例7: calculateChecksum

import org.jnetpcap.util.checksum.Checksum; //导入依赖的package包/类
/**
 * Calculate checksum.
 * 
 * @return the long
 */
public int calculateChecksum() {
	final JPacket packet = getPacket();
	int save = checksum();
	checksum(0); // Reset to 0, a requirement for calculation
	int crc = Checksum.sctp(packet, getOffset(), getHeaderLength()
			+ getPayloadLength());
	// int crc = Checksum.crc32IEEE802(packet, 0, getHeaderLength()
	// + getPayloadLength());

	checksum(save); // Restore CRC

	return crc;
}
 
开发者ID:pvenne,项目名称:jgoose,代码行数:19,代码来源:Sctp.java

示例8: calculateChecksum

import org.jnetpcap.util.checksum.Checksum; //导入依赖的package包/类
/**
 * Calculates a checksum using protocol specification for a header. Checksums
 * for partial headers or fragmented packets (unless the protocol alows it)
 * are not calculated.
 * 
 * @return header's calculated checksum
 */
public int calculateChecksum() {

	if (getIndex() == -1) {
		throw new IllegalStateException("Oops index not set");
	}

	final int ipOffset = getPreviousHeaderOffset();

	return Checksum.inChecksumShouldBe(checksum(),
			Checksum.pseudoTcp(this.packet, ipOffset, getOffset()));
}
 
开发者ID:pvenne,项目名称:jgoose,代码行数:19,代码来源:Tcp.java

示例9: isChecksumValid

import org.jnetpcap.util.checksum.Checksum; //导入依赖的package包/类
/**
 * Checks if the checksum is valid, for un-fragmented packets. If a packet is
 * fragmented, the checksum is not verified as data to is incomplete, but the
 * method returns true none the less.
 * 
 * @return true if checksum checks out or if this is a fragment, otherwise if
 *         the computed checksum does not match the stored checksum false is
 *         returned
 */
public boolean isChecksumValid() {

	if (isFragmented()) {
		return true;
	}

	if (getIndex() == -1) {
		throw new IllegalStateException("Oops index not set");
	}

	final int ipOffset = getPreviousHeaderOffset();

	return Checksum.pseudoTcp(this.packet, ipOffset, getOffset()) == 0;
}
 
开发者ID:pvenne,项目名称:jgoose,代码行数:24,代码来源:Tcp.java

示例10: isChecksumValid

import org.jnetpcap.util.checksum.Checksum; //导入依赖的package包/类
/**
 * Checks if the checksum is valid, for un-fragmented packets. If a packet is
 * fragmented, the checksum is not verified as data to is incomplete, but the
 * method returns true none the less.
 * 
 * @return true if checksum checks out or if this is a fragment, otherwise if
 *         the computed checksum does not match the stored checksum false is
 *         returned
 */
public boolean isChecksumValid() {

	if (isFragmented()) {
		return true;
	}

	if (getIndex() == -1) {
		throw new IllegalStateException("Oops index not set");
	}

	final int ipOffset = getPreviousHeaderOffset();

	return Checksum.pseudoUdp(this.packet, ipOffset, getOffset()) == 0;
}
 
开发者ID:pvenne,项目名称:jgoose,代码行数:24,代码来源:Udp.java

示例11: testIp4CRC16Pkt1

import org.jnetpcap.util.checksum.Checksum; //导入依赖的package包/类
/**
 * Test ip4 cr c16 pkt1.
 */
public void testIp4CRC16Pkt1() {

	JPacket packet = super.getPcapPacket(TestUtils.L2TP, 0);
	Ip4 ip = packet.getHeader(new Ip4());

	int computed = Checksum.inChecksum(ip, 0, ip.size());

	System.out.printf("1chunk=%x\n", computed);
	System.out.printf("shoudbe=%x checksum=%x\n",
			Checksum.inChecksumShouldBe(ip.checksum(), computed),
			ip.checksum());

	assertTrue(ip.isChecksumValid());
}
 
开发者ID:pvenne,项目名称:jgoose,代码行数:18,代码来源:TestTcpIp.java

示例12: test1

import org.jnetpcap.util.checksum.Checksum; //导入依赖的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

示例13: calculateChecksum

import org.jnetpcap.util.checksum.Checksum; //导入依赖的package包/类
/**
 * Calculate checksum.
 * 
 * @return the long
 */
public long calculateChecksum() {

	final JPacket packet = getPacket();
	return Checksum.crc32IEEE802(packet, 0, getHeaderLength()
			+ getPayloadLength());
}
 
开发者ID:GlacialSoftware,项目名称:PCAPReader,代码行数:12,代码来源:Ethernet.java

示例14: calculateChecksum

import org.jnetpcap.util.checksum.Checksum; //导入依赖的package包/类
/**
 * Calculates a checksum using protocol specification for a header. Checksums
 * for partial headers or fragmented packets (unless the protocol alows it)
 * are not calculated.
 * 
 * @return header's calculated checksum
 */
public int calculateChecksum() {

	if (getIndex() == -1) {
		throw new IllegalStateException("Oops index not set");
	}

	final int ipOffset = getPreviousHeaderOffset();

	return Checksum.inChecksumShouldBe(checksum(), Checksum.icmp(packet,
	    ipOffset, this.getOffset()));
}
 
开发者ID:GlacialSoftware,项目名称:PCAPReader,代码行数:19,代码来源:Icmp.java

示例15: testTcpIp4CRC16UsingHandler

import org.jnetpcap.util.checksum.Checksum; //导入依赖的package包/类
/**
 * Test tcp ip4 cr c16 using handler.
 */
public void testTcpIp4CRC16UsingHandler() {
	StringBuilder errbuf = new StringBuilder();
	Pcap pcap = Pcap.openOffline(TestUtils.HTTP, errbuf);

	assertNotNull(errbuf.toString(), pcap);

	pcap.loop(Pcap.LOOP_INFINATE, new PcapPacketHandler<String>() {
		Ip4 ip = new Ip4();

		Tcp tcp = new Tcp();

		// public void nextPacket(PcapHeader header, JBuffer buffer, String
		// user)
		// {
		public void nextPacket(PcapPacket packet, String user) {

			if (packet.hasHeader(tcp) == false) {
				return;
			}

			// PcapPacket packet = new PcapPacket(header, buffer);

			long f = packet.getFrameNumber();
			assertTrue("#" + f, packet.hasHeader(ip));

			final int crc = Checksum.pseudoTcp(packet, ip.getOffset(),
					tcp.getOffset());

			if (crc != 0 && tcp.checksum() != crc) {
				System.out.println(tcp);
				System.out.printf("#%d: tcp.crc=%x computed=%x\n", f,
						tcp.checksum(), crc);
				// System.out.println(ip.toHexdump());
				// System.out.println(tcp.toHexdump());
				System.exit(0);
			}

			// assertEquals("Frame #" + f, tcp.checksum(), crc);
		}

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


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