本文整理汇总了Java中org.jnetpcap.protocol.lan.Ethernet类的典型用法代码示例。如果您正苦于以下问题:Java Ethernet类的具体用法?Java Ethernet怎么用?Java Ethernet使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Ethernet类属于org.jnetpcap.protocol.lan包,在下文中一共展示了Ethernet类的15个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: testScanIpv6File
import org.jnetpcap.protocol.lan.Ethernet; //导入依赖的package包/类
/**
* Printing to DEV_NULL still causes entire packet structure to be decoded and
* dumped to /dev/null while using every available header found in the packet.
* Good stress test for Ip6 based packets.
*
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public void testScanIpv6File() throws IOException {
TextFormatter out = new TextFormatter(OUT);
out.setResolveAddresses(false);
int i = 0;
Ethernet eth = new Ethernet();
for (PcapPacket packet : TestUtils.getIterable("tests/test-ipv6.pcap")) {
System.out.println(packet.toDebugString());
if (packet.hasHeader(eth)) {
out.format(eth);
}
out.setFrameIndex(i++);
out.format(packet);
}
}
示例2: setPacket
import org.jnetpcap.protocol.lan.Ethernet; //导入依赖的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;
}
示例3: meetCriteria
import org.jnetpcap.protocol.lan.Ethernet; //导入依赖的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: testJHeaderIsFragmented
import org.jnetpcap.protocol.lan.Ethernet; //导入依赖的package包/类
/**
* Test j header is fragmented.
*/
public void testJHeaderIsFragmented() {
JPacket packet = TestUtils.getPcapPacket(TestUtils.REASEMBLY, 1 - 1);
Ethernet eth = new Ethernet();
if (packet.hasHeader(eth)) {
assertFalse(eth.isFragmented());
}
Ip4 ip = new Ip4();
if (packet.hasHeader(ip)) {
assertTrue(ip.isFragmented());
}
Icmp icmp = new Icmp();
if (packet.hasHeader(icmp)) {
assertTrue(ip.isFragmented());
}
}
示例5: dispatchToPcapPacketHandler
import org.jnetpcap.protocol.lan.Ethernet; //导入依赖的package包/类
public <T> long dispatchToPcapPacketHandler(PcapPacketHandler<T> handler,
T user) {
// for (Record record: buffer) {
// handler.nextPacket(record.header, record.packet, user);
// }
final JPcapRecordBuffer.Iterator i = this.iterator();
for (JPcapRecordBuffer.Record record : this) {
// final PcapPacket pkt = new PcapPacket(record.header, record.packet);
packet.transferHeaderAndDataFrom(record.header, record.packet);
packet.scan(Ethernet.ID);
handler.nextPacket(packet, user);
}
return this.getPacketRecordCount();
}
示例6: _testScanOnePacket
import org.jnetpcap.protocol.lan.Ethernet; //导入依赖的package包/类
/**
* _test scan one packet.
*
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public void _testScanOnePacket() throws IOException {
JPacket packet = new JMemoryPacket(new byte[] {
(byte) 0xa0,
(byte) 0xa1,
(byte) 0xa2,
(byte) 0xa3,
(byte) 0xa4,
(byte) 0xa5,
(byte) 0xb0,
(byte) 0xb1,
(byte) 0xb2,
(byte) 0xb3,
(byte) 0xb4,
(byte) 0xb5,
(byte) 0x00,
(byte) 0x08, });
JScanner scanner = new JScanner();
scanner.scan(packet, Ethernet.ID);
TextFormatter out = new TextFormatter();
out.format(packet);
}
示例7: nextPacket
import org.jnetpcap.protocol.lan.Ethernet; //导入依赖的package包/类
public void nextPacket(PcapHeader pcapHdr, JBuffer jbuf, String user) {
packet.peerHeaderAndData(pcapHdr, jbuf);
scanner.scan(packet, Ethernet.ID);
assertTrue(packet.getPacketWirelen() > 0);
System.out.printf("JHandlerTest::nextPacket() - %s\n", packet.getState()
.toDebugString());
if (packet.hasHeader(ethernet)) {
System.out.println("ethernet.dst=" + ethernet.destination());
}
if (packet.hasHeader(ip4)) {
System.out.println("ip4.ver=" + ip4.version());
}
if (packet.hasHeader(ip6)) {
System.out.println("ip4.ver=" + ip4.version());
}
}
示例8: handle
import org.jnetpcap.protocol.lan.Ethernet; //导入依赖的package包/类
/**
* pseudonymizes the packet according to the settings and stored the
*
* @param packet the captured PcapPacket
*/
@Override
public void handle(PcapPacket packet) {
// Determine if the packet is an ethernet packet first.
if (packet.hasHeader(Ethernet.ID)){
_packetModifier.modifyPacket(packet);
_pseudoDumper.dump(packet);
}
else {
// TODO PEF-77: don't send or nullify the packet.
logger.warning("Non-ethernet packet found, packet is left untouched.");
}
}
示例9: 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;
}
示例10: testDumpJPacket
import org.jnetpcap.protocol.lan.Ethernet; //导入依赖的package包/类
/**
* Test method for {@link org.jnetpcap.PcapDumper#dump(org.jnetpcap.packet.JMemoryPacket)}.
*/
@Test
public void testDumpJPacket() {
JMemoryPacket packet = new JMemoryPacket(Ethernet.ID, data);
dumper.dump(packet);
checkFileSize();
}
示例11: testDiameterHeader
import org.jnetpcap.protocol.lan.Ethernet; //导入依赖的package包/类
/**
* Test diameter header.
*/
public void testDiameterHeader() {
Diameter diameter = new Diameter(); // Need an instance so we can check on sub header
// Wireshark packet # 29 (1-based)
PcapPacket packet = TestUtils.getPcapPacket("tests/tc_TC_IDPRE_EXT0140.pcap", 43 - 1);
System.out.println(packet.toHexdump(128, false, false, true));
long map = packet.getState().get64BitHeaderMap(JProtocol.idToGroup(Diameter.ID));
JRegistry.addBindings(Diameter.class);
System.out.println(JRegistry.toDebugString());
System.out.println(packet);
assertEquals(JRegistry.lookupId(Diameter.class), Diameter.ID);
assertTrue(packet.hasHeader(Ethernet.ID));
assertTrue(packet.hasHeader(JProtocol.IP4_ID, 0));
assertTrue(packet.hasHeader(diameter));
System.out.println(diameter.toHexdump());
// Check specific values
assertEquals(1, diameter.getVersion());
assertEquals(364, diameter.getMessageLength());
assertEquals(0x40, diameter.getCommandFlags());
assertEquals(0x132, diameter.getCommandCode());
}
示例12: testIp4FragmentFlagDirectly
import org.jnetpcap.protocol.lan.Ethernet; //导入依赖的package包/类
/**
* Test ip4 fragment flag directly.
*/
public void testIp4FragmentFlagDirectly() {
JPacket packet = TestUtils.getPcapPacket(TestUtils.REASEMBLY, 1 - 1);
Ethernet eth = new Ethernet();
if (packet.hasHeader(eth)) {
// System.out.println(eth);
// System.out.printf("flags=%x\n", eth.getState().getFlags());
assertNotSame(JHeader.State.FLAG_HEADER_FRAGMENTED, (eth.getState()
.getFlags() & JHeader.State.FLAG_HEADER_FRAGMENTED));
}
Ip4 ip = new Ip4();
if (packet.hasHeader(ip)) {
// System.out.println(ip);
// System.out.printf("flags=%x\n", ip.getState().getFlags());
assertEquals(JHeader.State.FLAG_HEADER_FRAGMENTED, (ip.getState()
.getFlags() & JHeader.State.FLAG_HEADER_FRAGMENTED));
}
Icmp icmp = new Icmp();
if (packet.hasHeader(icmp)) {
// System.out.println(icmp);
// System.out.printf("flags=%x\n", icmp.getState().getFlags());
assertEquals(JHeader.State.FLAG_HEADER_FRAGMENTED, (icmp.getState()
.getFlags() & JHeader.State.FLAG_HEADER_FRAGMENTED));
}
}
示例13: 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());
}
示例14: testPrintEachHeaderGradually
import org.jnetpcap.protocol.lan.Ethernet; //导入依赖的package包/类
/**
* Test print each header gradually.
*
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public void testPrintEachHeaderGradually() throws IOException {
final String data =
"" + "00 0c 41 76 33 05 00 03 6b f7 12 0f 08 00 45 00"
+ "00 7c 6f f7 40 00 fa 11 f8 8f 41 20 01 41 c0 a8"
+ "14 e0 00 35 c0 66 00 68 60 f0 b4 16 85 83 00 01"
+ "00 00 00 01 00 00 0a 6e 6d 72 66 6c 69 73 6d 73"
+ "31 04 69 61 67 72 03 6e 65 74 00 00 01 00 01 c0"
+ "17 00 06 00 01 00 00 2a 30 00 2f 05 70 64 6e 73"
+ "31 08 75 6c 74 72 61 64 6e 73 c0 1c 07 6b 67 72"
+ "61 75 65 72 c0 17 77 bf dd f5 00 00 2a 30 00 00"
+ "0e 10 00 27 8d 00 00 01 51 80" + "";
final JPacket packet = new JMemoryPacket(JProtocol.ETHERNET_ID, data);
// final String TEMP_CAP = "tests/temp.pcap";
// final File TEMP_CAP_FILE = new File(TEMP_CAP);
// if (TEMP_CAP_FILE.exists()) {
// TEMP_CAP_FILE.delete();
// }
// FormatUtils.createPcapFile(TEMP_CAP, data);
// System.out.println(packet);
System.out.println(packet.getHeader(new Ethernet()));
System.out.println(packet.getHeader(new Ip4()));
System.out.println(packet.getHeader(new Udp()));
System.out.println(packet.getState().toDebugString());
}
示例15: testPeerToJBuffer
import org.jnetpcap.protocol.lan.Ethernet; //导入依赖的package包/类
/**
* Test peer to j buffer.
*/
public void testPeerToJBuffer() {
assertNotNull(VariousInMemoryPackets.PACKET_1);
JPacket packet = new JMemoryPacket(VariousInMemoryPackets.PACKET_1);
packet.scan(Ethernet.ID);
System.out.println(packet);
}