本文整理汇总了Java中org.jnetpcap.packet.JPacket类的典型用法代码示例。如果您正苦于以下问题:Java JPacket类的具体用法?Java JPacket怎么用?Java JPacket使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
JPacket类属于org.jnetpcap.packet包,在下文中一共展示了JPacket类的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: modifyPacket
import org.jnetpcap.packet.JPacket; //导入依赖的package包/类
/**
* In this function the packet is pseudonymization and checksums are recalculated as configured.
*
* @param packet the captured packet
*/
public void modifyPacket(JPacket packet) {
if ((!DNS_ONLY) || isDns(packet)) {
// If the original ip4 checksum is not valid, the checksum should not be modified.
boolean originalChecksumValid = true;
if (_pseudonymizerMap.containsKey(JProtocol.IP4) && packet.hasHeader(Ip4.ID)) {
Ip4 ip4 = packet.getHeader(new Ip4());
originalChecksumValid = ip4.isChecksumValid();
pseudonymizeIP4(_pseudonymizerMap.get(JProtocol.IP4), ip4);
} else if (_pseudonymizerMap.containsKey(JProtocol.IP6) && packet.hasHeader(Ip6.ID)) {
Ip6 ip6 = packet.getHeader(new Ip6());
pseudonymizeIP6(_pseudonymizerMap.get(JProtocol.IP6), ip6);
}
// Checksum updates.
recalculateChecksums(packet, originalChecksumValid);
}
}
开发者ID:NCSC-NL,项目名称:PEF,代码行数:23,代码来源:JNetPcapPacketModifier.java
示例2: recalculateChecksums
import org.jnetpcap.packet.JPacket; //导入依赖的package包/类
/**
* Recalculates the checksums as configured.
*
* @param packet the captured packet
* @param originalChecksumValid boolean that holds whether the checksum was valid before modification.
*/
private void recalculateChecksums(final JPacket packet, final boolean originalChecksumValid) {
for (int checksumType : _checksumList) {
// The ip4 or ip6 checksum should be updated first.
if (checksumType == Ip4.ID && originalChecksumValid) {
if (packet.hasHeader(Ip4.ID)) {
Ip4 ip4 = packet.getHeader(new Ip4());
ip4.recalculateChecksum();
}
}
if (checksumType == Udp.ID && packet.hasHeader(Udp.ID)) {
recalulateUdpChecksum(packet);
}
if (checksumType == Tcp.ID && packet.hasHeader(Tcp.ID)) {
Tcp tcp = packet.getHeader(new Tcp());
tcp.recalculateChecksum();
}
if (checksumType == Icmp.ID && packet.hasHeader(Icmp.ID)) {
Icmp icmp = packet.getHeader(new Icmp());
icmp.recalculateChecksum();
}
}
}
开发者ID:NCSC-NL,项目名称:PEF,代码行数:29,代码来源:JNetPcapPacketModifier.java
示例3: bind2Http
import org.jnetpcap.packet.JPacket; //导入依赖的package包/类
/**
* Bind2 http.
*
* @param packet
* the packet
* @param http
* the http
* @return true, if successful
*/
@Bind(to = Http.class)
public static boolean bind2Http(JPacket packet, Http http) {
Http.ContentType type = http.contentTypeEnum();
switch (type) {
case JPEG:
case PNG:
case GIF:
return true;
default:
return false;
}
}
开发者ID:pvenne,项目名称:jgoose,代码行数:23,代码来源:WebImage.java
示例4: checkNonStaticSignature
import org.jnetpcap.packet.JPacket; //导入依赖的package包/类
/**
* Check non static signature.
*
* @param method
* the method
*/
private static void checkNonStaticSignature(final Method method) {
final Class<?> declaringClass = method.getDeclaringClass();
if (method.isAnnotationPresent(Bind.class) == false) {
throw new AnnotatedMethodException(declaringClass,
"@Bind annotation missing for " + method.getName() + "()");
}
/*
* Now make sure it has the right signature of: <code>static int
* name(JBuffer, int)</code.
*/
final Class<?>[] sig = method.getParameterTypes();
if (sig.length != 2 || sig[0] != JPacket.class
|| sig[1].isAssignableFrom(JHeader.class)) {
throw new AnnotatedMethodException(declaringClass,
"Invalid signature for " + method.getName() + "()");
}
if ((method.getModifiers() & Modifier.STATIC) != 0) {
throw new AnnotatedMethodException(declaringClass, method.getName()
+ "()" + " can not be declared static");
}
}
开发者ID:pvenne,项目名称:jgoose,代码行数:32,代码来源:AnnotatedBindMethod.java
示例5: analyzeFrame
import org.jnetpcap.packet.JPacket; //导入依赖的package包/类
public int analyzeFrame(JPacket packet, long referenceEpochTime){
add("Frame "+Long.toString(packet.getFrameNumber()), 0);
JCaptureHeader captureHeader = packet.getCaptureHeader();
add("arrival time = "+new Timestamp(captureHeader.timestampInMillis()).toString(),1);
double time= (double)(captureHeader.timestampInNanos())/1000000000.0;
double timeSinceReference= (double)(captureHeader.timestampInNanos()-referenceEpochTime)/1000000000.0;
add(String.format("epoch time = %1$.9f seconds",time),1);
add(String.format("time since first frame = %1$.9f seconds",timeSinceReference),1);
add("wire length = "+Integer.toString(captureHeader.wirelen()),1);
add("capture length = "+Integer.toString(captureHeader.caplen()),1);
return 1;
}
开发者ID:GlacialSoftware,项目名称:PCAPReader,代码行数:18,代码来源:PacketFormatter.java
示例6: testJHeaderIsFragmented
import org.jnetpcap.packet.JPacket; //导入依赖的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());
}
}
开发者ID:pvenne,项目名称:jgoose,代码行数:23,代码来源:TestTcpIp.java
示例7: checkSignature
import org.jnetpcap.packet.JPacket; //导入依赖的package包/类
/**
* Check signature.
*
* @param method
* the method
*/
private static void checkSignature(final Method method) {
final Class<?> declaringClass = method.getDeclaringClass();
if (method.isAnnotationPresent(Bind.class) == false) {
throw new AnnotatedMethodException(declaringClass,
"@Bind annotation missing for " + method.getName() + "()");
}
/*
* Now make sure it has the right signature of: <code>static int
* name(JBuffer, int)</code.
*/
final Class<?>[] sig = method.getParameterTypes();
if (sig.length != 2 || sig[0] != JPacket.class
|| sig[1].isAssignableFrom(JHeader.class)) {
throw new AnnotatedMethodException(declaringClass,
"Invalid signature for " + method.getName() + "()");
}
if ((method.getModifiers() & Modifier.STATIC) == 0) {
throw new AnnotatedMethodException(declaringClass, method.getName()
+ "()" + " must be declared static");
}
}
开发者ID:universsky,项目名称:diddler,代码行数:32,代码来源:AnnotatedBindMethod.java
示例8: analyzePacket
import org.jnetpcap.packet.JPacket; //导入依赖的package包/类
public int analyzePacket(JPacket packet, long referenceEpochTime){
int maxLevel=analyzeFrame(packet, referenceEpochTime);
final int headerCount = packet.getHeaderCount();
for (int i=0;i<headerCount;++i){
final int id = packet.getHeaderIdByIndex(i);
final JHeader header = headerPool.getHeader(id);
packet.getHeaderByIndex(i, header);
int depth;
if (id==JProtocol.PAYLOAD_ID){
depth=analyzePayload(header);
} else {
depth=analyzeHeader(header);
}
if (depth>maxLevel){
maxLevel=depth;
}
}
return maxLevel;
}
开发者ID:GlacialSoftware,项目名称:PCAPReader,代码行数:24,代码来源:PacketFormatter.java
示例9: packetBefore
import org.jnetpcap.packet.JPacket; //导入依赖的package包/类
/**
* @param packet
* @param detail
* @throws IOException
* @see org.jnetpcap.packet.format.JFormatter#packetBefore(org.jnetpcap.packet.JPacket, org.jnetpcap.packet.format.JFormatter.Detail)
*/
@Override
public void packetBefore(JPacket packet, Detail detail) throws IOException {
pad().format(LT + "packet");
incLevel(PAD + PAD);
pad().format("wirelen=\"%d\"", packet.getCaptureHeader().wirelen());
pad().format("caplen=\"%d\"", packet.getCaptureHeader().caplen());
if (frameIndex != -1) {
pad().format("index=\"%d\"", frameIndex);
}
pad().format("timestamp=\"%s\"",
new Timestamp(packet.getCaptureHeader().timestampInMillis()));
pad().format("captureSeconds=\"%s\"", packet.getCaptureHeader().seconds());
pad().format("captureNanoSeconds=\"%s\"" + GT,
packet.getCaptureHeader().nanos());
pad();
decLevel();
incLevel(PAD);
}
开发者ID:GlacialSoftware,项目名称:PCAPReader,代码行数:31,代码来源:XmlFormatter.java
示例10: updateFrame_From_Packet
import org.jnetpcap.packet.JPacket; //导入依赖的package包/类
public void updateFrame_From_Packet(JPacket local_jPacket){
IEC61850_GOOSE_Header goose_header = local_jPacket.getHeader( new IEC61850_GOOSE_Header());
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();
// 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 decode the data
gooseData.decodeData(goose_header.gooseData());
}
开发者ID:pvenne,项目名称:jgoose,代码行数:22,代码来源:IEC61850_GOOSE_Frame.java
示例11: recalulateUdpChecksum
import org.jnetpcap.packet.JPacket; //导入依赖的package包/类
/**
* Within JNetPcap the UDP checksum recalculation does not work.
* It is reimplemented here.
*
* @param packet packet to recalculate the udp checksum over.
*/
private void recalulateUdpChecksum(final JPacket packet) {
final Udp udp = packet.getHeader(new Udp());
udp.checksum(0); // The checksum is left out of the calculation but reset for correctness.
final byte[] mergedBytes;
if (packet.hasHeader(Ip4.ID)) {
Ip4 ip4 = packet.getHeader(new Ip4());
mergedBytes = constructIp4UdpChecksumByteArray(ip4, udp);
} else {
Ip6 ip6 = packet.getHeader(new Ip6());
mergedBytes = constructIp6UdpChecksumByteArray(ip6, udp);
}
udp.checksum(ByteBuffer.wrap(calculateInternetChecksum(mergedBytes)).order(ByteOrder.BIG_ENDIAN).getShort());
}
开发者ID:NCSC-NL,项目名称:PEF,代码行数:20,代码来源:JNetPcapPacketModifier.java
示例12: isDns
import org.jnetpcap.packet.JPacket; //导入依赖的package包/类
/**
* Check for DNS packets if required that only DNS packets should be handled.
*
* @param packet the captured packet.
* @return true if the packet is a dns packet.
*/
private boolean isDns(final JPacket packet) {
if (packet.hasHeader(Udp.ID)) {
final Udp udp = packet.getHeader(new Udp());
return (udp.source() == 53 || udp.destination() == 53);
}
else if (packet.hasHeader(Tcp.ID)) {
final Tcp tcp = packet.getHeader(new Tcp());
return (tcp.source() == 53 || tcp.destination() == 53);
}
return false;
}
开发者ID:NCSC-NL,项目名称:PEF,代码行数:18,代码来源:JNetPcapPacketModifier.java
示例13: Generate_ArpReply
import org.jnetpcap.packet.JPacket; //导入依赖的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
示例14: calculateChecksum
import org.jnetpcap.packet.JPacket; //导入依赖的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
示例15: checksum
import org.jnetpcap.packet.JPacket; //导入依赖的package包/类
/**
* Retrieves the header's checksum.
*
* @return header's stored checksum
*/
@Field(length = 4 * BYTE, format = "%x", display = "FCS")
public int checksum() {
if (getPostfixLength() < 4) {
return 0;
}
final JPacket packet = getPacket();
packet.order(ByteOrder.BIG_ENDIAN);
return packet.getInt(packet.size() - 4);
}
开发者ID:pvenne,项目名称:jgoose,代码行数:16,代码来源:Ethernet.java
示例16: checksum
import org.jnetpcap.packet.JPacket; //导入依赖的package包/类
/**
* Retrieves the header's checksum.
*
* @return header's stored checksum
*/
@Field(length = 4 * BYTE, format = "%x", display = "FCS")
public long checksum() {
final JPacket packet = getPacket();
packet.order(ByteOrder.BIG_ENDIAN);
return packet.getUInt(getPostfixOffset());
}
开发者ID:pvenne,项目名称:jgoose,代码行数:12,代码来源:IEEE802dot3.java
示例17: calculateChecksum
import org.jnetpcap.packet.JPacket; //导入依赖的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
示例18: bind2Udp
import org.jnetpcap.packet.JPacket; //导入依赖的package包/类
@Bind(to = Udp.class)
public static boolean bind2Udp(JPacket packet, Udp udp) {
return udp.destination() == 1812 || udp.source() == 1812 // Server
|| udp.destination() == 1813 || udp.source() == 1813 // Accounting
|| udp.destination() == 3799 || udp.source() == 3799 // Authorization
|| udp.destination() == 1646 || udp.source() == 1646; // Obsolete
}
开发者ID:pvenne,项目名称:jgoose,代码行数:8,代码来源:Radius.java
示例19: format
import org.jnetpcap.packet.JPacket; //导入依赖的package包/类
/**
* Formats a packet for output.
*
* @param packet
* packet to format
* @param detail
* detail level
* @throws IOException
* any IO errors when sending data to default output device
*/
public void format(JPacket packet, Detail detail) throws IOException {
if (packet == null) {
packetNull(packet, detail);
return;
}
packetBefore(packet, detail);
final int count = packet.getHeaderCount();
for (int i = 0; i < count; i++) {
final int id = packet.getHeaderIdByIndex(i);
if (id == JProtocol.PAYLOAD_ID && displayPayload == false) {
continue;
}
try {
final JHeader header = headers.getHeader(id);
final Detail headerDetail =
(detailsPerHeader[id] == null) ? detail : detailsPerHeader[id];
packet.getHeaderByIndex(i, header);
if (header.getLength() == 0) {
continue;
}
format(header, headerDetail);
} catch (UnregisteredHeaderException e) {
throw new IllegalStateException(e); // Serious internal error
}
}
packetAfter(packet, detail);
}
开发者ID:GlacialSoftware,项目名称:PCAPReader,代码行数:46,代码来源:JFormatter.java
示例20: packetAfter
import org.jnetpcap.packet.JPacket; //导入依赖的package包/类
/**
* @param packet
* @param detail
* @throws IOException
* @see org.jnetpcap.packet.format.JFormatter#packetAfter(org.jnetpcap.packet.JPacket, org.jnetpcap.packet.format.JFormatter.Detail)
*/
@Override
public void packetAfter(JPacket packet, Detail detail) throws IOException {
decLevel();
pad().format(LT + "/packet" + GT);
}
开发者ID:pvenne,项目名称:jgoose,代码行数:14,代码来源:XmlFormatter.java
注:本文中的org.jnetpcap.packet.JPacket类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论