本文整理汇总了Java中org.jnetpcap.packet.PcapPacket.size方法的典型用法代码示例。如果您正苦于以下问题:Java PcapPacket.size方法的具体用法?Java PcapPacket.size怎么用?Java PcapPacket.size使用的例子?那么, 这里精选的方法代码示例或许可以为您提供帮助。您也可以进一步了解该方法所在类org.jnetpcap.packet.PcapPacket
的用法示例。
在下文中一共展示了PcapPacket.size方法的6个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于系统推荐出更棒的Java代码示例。
示例1: getByteLimitedHandler
import org.jnetpcap.packet.PcapPacket; //导入方法依赖的package包/类
/**
* Creation of a pseudopackethandler packet handler type which breaks the loop after.
*
* @return returns a packethandler which handles' the packets and stops if the max_bytes amount is handled.
*/
private static PcapPacketHandler<PseudoPacketHandler> getByteLimitedHandler(final Pcap pcap, final long MAX_BYTES) {
// Packet handler. Generic callback function for PseudoPacketHandler.
return new PcapPacketHandler<PseudoPacketHandler>() {
long packetBytes = 0;
// Handle nextPacket callback.
public void nextPacket(PcapPacket packet, PseudoPacketHandler handler) {
handler.handle(packet);
packetBytes+= packet.size();
if (packetBytes >= MAX_BYTES) {
pcap.breakloop();
}
}
};
}
示例2: testCompare2SetsOfPackets
import org.jnetpcap.packet.PcapPacket; //导入方法依赖的package包/类
/**
* Test compare2 sets of packets.
*
* @throws IOException
* Signals that an I/O exception has occurred.
*/
public void testCompare2SetsOfPackets() throws IOException {
List<PcapPacket> l1 = getPacketList(L2TP);
List<PcapPacket> l2 = getPacketList(L2TP);
assertEquals(l1.size(), l2.size());
for (int i = 0; i < l1.size(); i++) {
PcapPacket p1 = l1.get(i);
PcapPacket p2 = l2.get(i);
if (p1.size() != p2.size()) {
System.out.printf("#%d p1=%d p2=%d\n%s\n%s\n", i, l1.size(),
l2.size(), p1.toHexdump(), p2.toHexdump());
System.out.println(p1.toString());
System.out.println(p2.toString());
}
assertEquals(p1.size(), p2.size());
assertTrue(compareJBuffer(p1, p2));
}
}
示例3: getTimedByteLimitedHandler
import org.jnetpcap.packet.PcapPacket; //导入方法依赖的package包/类
/**
* Initialization of the pseudo packet handler which measures the time to handle the configured amount of bytes.
*
* @param pcap the interface with the pcap library needed to construct the packet handler.
* @param MAX_BYTES the maximum amount of bytes captured
* @return the handler for the packets.
*/
private static PcapPacketHandler<PseudoPacketHandler> getTimedByteLimitedHandler(final Pcap pcap, final long MAX_BYTES) {
// Packet handler. Generic callback function for PseudoPacketHandler.
return new PcapPacketHandler<PseudoPacketHandler>() {
boolean started = false;
long packetBytes = 0;
long startTime;
long stopTime;
// A timer for performance tests.
final ThreadMXBean threadMXBean = ManagementFactory.getThreadMXBean();
// Handle nextPacket callback.
public void nextPacket(PcapPacket packet, PseudoPacketHandler handler) {
if (!started) {
startTime = threadMXBean.getCurrentThreadCpuTime();
logger.info("Started at "+ startTime);
started = true;
}
handler.handle(packet);
packetBytes+= packet.size();
if (packetBytes >= MAX_BYTES) {
stopTime = threadMXBean.getCurrentThreadCpuTime();
pcap.breakloop();
logger.info("Stopped after " + ((stopTime - startTime)/10000000000.0) + " seconds and " + packetBytes + " bytes.");
}
}
};
}
示例4: meetCriteria
import org.jnetpcap.packet.PcapPacket; //导入方法依赖的package包/类
@Override
public Boolean meetCriteria(PcapPacket itemToCheck)
{
int currPacketSize = itemToCheck.size();
switch (sign)
{
case LESS_THAN: return currPacketSize <= size;
case EQUALS: return currPacketSize == size;
case GREATER_THAN: return currPacketSize >= size;
default: return null; //never gets here
}
}
示例5: sendPacketToServer
import org.jnetpcap.packet.PcapPacket; //导入方法依赖的package包/类
/**
* <pre>
* Ŭ���̾�Ʈ���� ������ ������ ��Ŷ
* �ַ� ����ڰ� �Է��� ä�� ������ ������ ��Ŷ�� �м��Ѵ�.
* </pre>
*
* @param packet
* - ��Ŷ
* @param sourceIP-
* ����� IP
* @param destinationIP
* - ������ IP
*/
public void sendPacketToServer(PcapPacket packet, String sourceIP, String destinationIP) {
// ��Ŷ ����� 1158�̰�,
// �� ������ �����ǰ� 172.217.24 �� �����ϴ� �뿪�� �ƴѰ�,
// ����� �����ǰ� 124.150 �� �����ϴ� �뿪�� �ƴѰ�,
if (packet.size() == 1158) {
System.out.println("Ŭ��-> ���� - ����IP -> " + sourceIP);
System.out.println("Ŭ��-> ���� - ����IP -> " + destinationIP);
// 0060: 0a 00 74 6f 20 74 68 65 20 6d 6f 6f 6e 20
String hexdump = packet.toHexdump(packet.size(), true, false, true);
// ������ �����ϴ� ���� �Է��� ����
String chatMsg = fromClientHexToServerMsg(hexdump);
// ���� �����ϴ� ���ڿ� �ѱ��̳� ���� ����(��ҹ���) ������ �ִ�����
String reg = "[��-��|��-��|��-�R|0-9|a-z|A-Z|\\s|[email protected]#$%^&*()+-.]*";
if (chatMsg.matches(reg)) {
// �ѱ��� �ִٸ�,
// ����
int flagIndex = hexdump.indexOf("0080:");
// ��
int flagLastIndex = hexdump.indexOf("0090:");
String parsePacket = hexdump.substring(flagIndex + 6, flagLastIndex);
String msg = null;
// ������ ��Ŷ�� ��Ƽê �� �δ�ê ����� �����ϹǷ�, ���а��� ���ؼ� ȭ�鿡 �����ִ°�
// �Ľ̵� ��Ŷ�� "01" ��Ŷ�� �ִ��� üũ
if (parsePacket.indexOf("01") > -1) {
// �ִٸ� ��Ƽ ê ���ú�
msg = "[��Ƽ]<��> : " + chatMsg + "\n";
} else {
// ���ٸ� �δ� ê ���ú�
msg = "[�����δ�]<��> : " + chatMsg + "\n";
}
// �۷ι����� �ѱۺ�ȯ�� ��
txtMsg.appendText(msg);
}
}
}
示例6: receivePacketToClient
import org.jnetpcap.packet.PcapPacket; //导入方法依赖的package包/类
/**
* <pre>
* �������� Ŭ���̾�Ʈ�� ������ ��Ŷ
* �ַ� �ٸ� ����ڰ� �Է��� ä�� ������ ������ ��Ŷ�� �м��Ѵ�. (��Ƽ, FC)
* </pre>
*
* @param packet-
* ��Ŷ
* @param sourceIP
* - ����� IP
* @param destinationIP
* - ������ IP
*/
public void receivePacketToClient(PcapPacket packet, String sourceIP, String destinationIP) {
// ============= �������� ������ ��Ŷ ============ //
if (packet.size() == 1206 && !sourceIP.matches(".*216.58.*")) {
System.out.println("����-> Ŭ�� - ����IP -> " + sourceIP);
System.out.println("����-> Ŭ�� - ����IP -> " + destinationIP);
// ij���� ����
String charName = fromServerHexToCharName(packet);
// ��ȭ������ �����Ѵ�.
// ���� �⺻������ �Ϻ��� -> �ѱ��� �̸�, �ѱ���� �Էµǵ� �״�� �ѱ���� ��µ�.
String chatMsg = GoogleTransAPI.jpTransMessage(fromSeverHexToClientMsg(packet));
// �������� �����ϴ� ���ڿ� �ѱ��̳� ���� ����(��ҹ���), ������ Ư���̳� ������ �ִ�����
String reg = "[��-��|��-��|��-�R|0-9|a-z|A-Z|\\s|[email protected]#$%^&*()+-.]*";
if (chatMsg.matches(reg)) {
// ��Ŷ ����
String dump = packet.toHexdump();
// ����
int flagIndex = dump.indexOf("0080:");
// ��
int flagLastIndex = dump.indexOf("0090:");
String parsePacket = dump.substring(flagIndex + 6, flagLastIndex);
String msg = null;
// �� ��Ŷ�� ��Ƽê �� �δ�ê ����� �����ϹǷ�, ���а��� ���ؼ� ȭ�鿡 �����ִ°� ���ؾ��Ѵ�.
// �Ľ̵� ��Ŷ�� "01" ��Ŷ�� �ִ��� üũ
if (parsePacket.indexOf("01") > -1) {
// �ִٸ� ��Ƽ ê ���ú�
msg = "[��Ƽ]<" + charName + "> : " + chatMsg + "\n";
} else {
// ���ٸ� �δ� ê ���ú�
msg = "[�����δ�]<" + charName + "> : " + chatMsg + "\n";
}
txtMsg.appendText(msg);
}
}
}