本文整理汇总了Java中org.jnetpcap.protocol.tcpip.Tcp类的典型用法代码示例。如果您正苦于以下问题:Java Tcp类的具体用法?Java Tcp怎么用?Java Tcp使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。
Tcp类属于org.jnetpcap.protocol.tcpip包,在下文中一共展示了Tcp类的17个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的Java代码示例。
示例1: recalculateChecksums
import org.jnetpcap.protocol.tcpip.Tcp; //导入依赖的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
示例2: setPacket
import org.jnetpcap.protocol.tcpip.Tcp; //导入依赖的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;
}
开发者ID:leolewis,项目名称:openvisualtraceroute,代码行数:29,代码来源:JNetCapPacketPoint.java
示例3: testFlagsToEnumSet
import org.jnetpcap.protocol.tcpip.Tcp; //导入依赖的package包/类
/**
* Bug#3321797
*
* <pre>
* Details:
* I use the following snippet to reproduce the bug.
* I hope the information is sufficient for you to track it down.
* Thanks a lot for this very nice software!
*
* </pre>
*/
public void testFlagsToEnumSet() {
/*
*
* From org.jnetpcap.protocol.tcpip.Tcp
*
* The Constant FLAG_ACK. private static final int FLAG_ACK = 0x10;
*
* ...
*
* The Constant FLAG_SYN. private static final int FLAG_SYN = 0x02;
*/
int flags = 0x02 | 0x10;
Set<Tcp.Flag> flagSet = Tcp.Flag.asSet(flags);
assertEquals("[SYN, ACK]", flagSet.toString());
assertEquals(EnumSet.of(Flag.ACK, Flag.SYN), flagSet);
/*
* Result: java.lang.AssertionError: expected:<[ACK, SYN]> but
* was:<[CWR, PSH]> ...
*
* JNetPcap Version: jnetpcap-1.4.r1300-1
*/
}
开发者ID:pvenne,项目名称:jgoose,代码行数:37,代码来源:TestTcpIp.java
示例4: nextPacket
import org.jnetpcap.protocol.tcpip.Tcp; //导入依赖的package包/类
@Override
public void nextPacket(JPacket packet, T cookie) {
if (packet.hasHeader(Ip4.ID) && packet.hasHeader(Tcp.ID)) {
packet.getHeader(ip4);
packet.getHeader(tcp);
final int payloadLength = tcp.getPayloadLength();
if (payloadLength > 0) {
switch (packetFilter.filter(ip4, tcp)) {
case Inbound:
inboundFlowHandler.parse(packet, tcp.getPayloadOffset(), payloadLength, cookie);
break;
case Outbound:
outboundFlowHandler.parse(packet, tcp.getPayloadOffset(), payloadLength, cookie);
break;
case Skip:
break;
}
}
}
}
开发者ID:andymalakov,项目名称:libpcap-latency-meter,代码行数:23,代码来源:LatencyMeterPacketHandler.java
示例5: isDns
import org.jnetpcap.protocol.tcpip.Tcp; //导入依赖的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
示例6: creatPacket
import org.jnetpcap.protocol.tcpip.Tcp; //导入依赖的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;
}
开发者ID:leolewis,项目名称:openvisualtraceroute,代码行数:37,代码来源:JNetCapTraceRoute.java
示例7: converge
import org.jnetpcap.protocol.tcpip.Tcp; //导入依赖的package包/类
/**
* 将数据包汇聚成网络流
* @param data
*/
private void converge(List<PacketInfo> data) {
for (PacketInfo packetInfo : data) {
PcapPacket packet = packetInfo.getPacket();
Ip4 ip4 = new Ip4();
Tcp tcp = new Tcp();
if (!packet.hasHeader(ip4) || !packet.hasHeader(tcp)) continue;
NetFlow netFlow = find(packetInfo);
if (tcp.flags_SYN()) { // SYN 作为TCP建立连接的标识,创建网络流
if (netFlow == null) {
netFlow = new NetFlow(ip4.sourceToInt(), ip4.destinationToInt(),
tcp.source(), tcp.destination());
netFlow.add(packetInfo);
netFlows.add(netFlow);
}
} else if (tcp.flags_FIN()) {
if (netFlow != null) {
netFlow.setClosed(true); // FIN作为TCP结束标识,关闭网络流
}
} else { // 加入到已存在的网络流中
if (netFlow != null && !netFlow.isClosed()) {
netFlow.add(packetInfo);
}
}
}
}
开发者ID:whinc,项目名称:PcapAnalyzer,代码行数:32,代码来源:ClusterModule.java
示例8: contain
import org.jnetpcap.protocol.tcpip.Tcp; //导入依赖的package包/类
/**
* 判断数据包是否属于当前网络流
* @param packetInfo
* @return
*/
public boolean contain(PacketInfo packetInfo) {
boolean b = false;
PcapPacket packet = packetInfo.getPacket();
Tcp tcp = new Tcp();
Ip4 ip4 = new Ip4();
if (packet.hasHeader(ip4)
&& packet.hasHeader(tcp) ) {
if (ip4.sourceToInt() == srcIp
&& ip4.destinationToInt() == dstIp
&& tcp.source() == srcPort
&& tcp.destination() == dstPort) {
packetInfo.setReversed(false);
b = true;
} else if (ip4.sourceToInt() == dstIp
&& ip4.destinationToInt() == srcIp
&& tcp.source() == dstPort
&& tcp.destination() == srcPort) {
packetInfo.setReversed(true);
b = true;
}
}
return b;
}
开发者ID:whinc,项目名称:PcapAnalyzer,代码行数:30,代码来源:NetFlow.java
示例9: testTcpOptions
import org.jnetpcap.protocol.tcpip.Tcp; //导入依赖的package包/类
/**
* Test tcp options.
*
* <pre>
*
* </pre>
*/
public void testTcpOptions() {
JPacket packet = TestUtils.getPcapPacket(SMALL_IMAP, 1 - 1);
System.out.println(packet.getState().toDebugString());
System.out.println(packet.toString());
Tcp tcp = packet.getHeader(new Tcp());
Tcp.Timestamp ts = new Tcp.Timestamp();
if (tcp.hasSubHeader(ts)) {
System.out.printf("tsval=%d tsecr=%d%n", ts.tsval(), ts.tsecr());
}
}
开发者ID:pvenne,项目名称:jgoose,代码行数:20,代码来源:TestTcpIp.java
示例10: TCPPacket
import org.jnetpcap.protocol.tcpip.Tcp; //导入依赖的package包/类
public TCPPacket(PcapPacket packet) {
packetTime = Instant.now();
Ip4 ip4 = packet.getHeader(new Ip4());
Tcp tcp = packet.getHeader(new Tcp());
connectionInfo = new TCPConnectionInfo(ip4.sourceToInt(), tcp.source(), ip4.destinationToInt(), tcp.destination());
seqNumber = tcp.seq();
ackNumber = tcp.ack();
tcpFlags = tcp.flags();
JBuffer storage = new JBuffer(JMemory.Type.POINTER);
JBuffer packetPayload = tcp.peerPayloadTo(storage);
payload = new byte[packetPayload.size()];
packetPayload.getByteArray(0, payload);
}
开发者ID:vincentzhang96,项目名称:HearthCaptureLib,代码行数:14,代码来源:TCPPacket.java
示例11: filter
import org.jnetpcap.protocol.tcpip.Tcp; //导入依赖的package包/类
@Override
public Direction filter(Ip4 ip4, Tcp tcp) {
if (Arrays.equals(localIpAddress, ip4.destination()))
return Direction.Inbound;
if (Arrays.equals(localIpAddress, ip4.source()))
return Direction.Outbound;
return Direction.Skip;
}
开发者ID:andymalakov,项目名称:libpcap-latency-meter,代码行数:10,代码来源:HostBasedPacketFilter.java
示例12: filter
import org.jnetpcap.protocol.tcpip.Tcp; //导入依赖的package包/类
@Override
public Direction filter(Ip4 ip4, Tcp tcp) {
if (tcp.source() == inboundPort)
return Direction.Inbound;
if (tcp.destination() == outboundPort)
return Direction.Outbound;
return Direction.Skip;
}
开发者ID:andymalakov,项目名称:libpcap-latency-meter,代码行数:10,代码来源:PortBasedTcpPacketFilter.java
示例13: testTcpIp4CRC16UsingHandler
import org.jnetpcap.protocol.tcpip.Tcp; //导入依赖的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
示例14: testSendPacketUsingJBuffer
import org.jnetpcap.protocol.tcpip.Tcp; //导入依赖的package包/类
/**
* Test send packet using j buffer.
*
* @throws UnknownHostException
* the unknown host exception
*/
public void testSendPacketUsingJBuffer() throws UnknownHostException {
JPacket packet =
new JMemoryPacket(JProtocol.ETHERNET_ID,
"0016b6c13cb10021 5db0456c08004500 "
+ "00340e8e40008006 9c54c0a80165d822 "
+ "b5b1c1cf005020ce 4303000000008002 "
+ "2000d94300000204 05b4010303020101 " + "0402");
InetAddress dst = InetAddress.getByName("201.1.1.1");
InetAddress src = InetAddress.getByName("192.168.1.1");
Ip4 ip = packet.getHeader(new Ip4());
Tcp tcp = packet.getHeader(new Tcp());
ip.destination(dst.getAddress());
ip.source(src.getAddress());
ip.checksum(ip.calculateChecksum());
tcp.checksum(tcp.calculateChecksum());
packet.scan(Ethernet.ID);
System.out.println(packet);
List<PcapIf> alldevs = new ArrayList<PcapIf>(); // Will be filled with NICs
StringBuilder errbuf = new StringBuilder(); // For any error msgs
/***************************************************************************
* First get a list of devices on this system
**************************************************************************/
int r = Pcap.findAllDevs(alldevs, errbuf);
if (r == Pcap.NOT_OK || alldevs.isEmpty()) {
System.err.printf("Can't read list of devices, error is %s", errbuf
.toString());
return;
}
PcapIf device = alldevs.get(0); // We know we have atleast 1 device
/***************************************************************************
* Second we open a network interface
**************************************************************************/
int snaplen = 64 * 1024; // Capture all packets, no trucation
int flags = Pcap.MODE_NON_PROMISCUOUS; // capture all packets
int timeout = 10 * 1000; // 10 seconds in millis
Pcap pcap =
Pcap.openLive(device.getName(), snaplen, flags, timeout, errbuf);
System.out.println("Device ->" + device.getName());
try {
if (pcap.sendPacket(packet) != Pcap.OK) {
System.err.println(pcap.getErr());
}
} finally {
/*************************************************************************
* Lastly we close
************************************************************************/
pcap.close();
}
}
开发者ID:pvenne,项目名称:jgoose,代码行数:64,代码来源:TestTransmitter.java
示例15: testTcpIp6CRC16UsingHandler
import org.jnetpcap.protocol.tcpip.Tcp; //导入依赖的package包/类
/**
* Test tcp ip6 cr c16 using handler.
*/
public void testTcpIp6CRC16UsingHandler() {
StringBuilder errbuf = new StringBuilder();
Pcap pcap = Pcap.openOffline(HTTP_IP6, errbuf);
assertNotNull(errbuf.toString(), pcap);
pcap.loop(Pcap.LOOP_INFINATE, new PcapPacketHandler<String>() {
Ip6 ip = new Ip6();
Tcp tcp = new Tcp();
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));
assertTrue("Frame #" + f, tcp.isChecksumValid());
}
}, null);
}
开发者ID:pvenne,项目名称:jgoose,代码行数:31,代码来源:TestTcpIp.java
示例16: bindToTcp
import org.jnetpcap.protocol.tcpip.Tcp; //导入依赖的package包/类
/**
* Bind to tcp.
*
* @param packet
* the packet
* @param tcp
* the tcp
* @return true, if successful
*/
@Bind(to = Tcp.class)
public static boolean bindToTcp(JPacket packet, Tcp tcp) {
return tcp.destination() == 3868 || tcp.source() == 3868;
}
开发者ID:pvenne,项目名称:jgoose,代码行数:14,代码来源:Diameter.java
示例17: filter
import org.jnetpcap.protocol.tcpip.Tcp; //导入依赖的package包/类
Direction filter(Ip4 ip4, Tcp tcp);
开发者ID:andymalakov,项目名称:libpcap-latency-meter,代码行数:2,代码来源:TcpPacketFilter.java
注:本文中的org.jnetpcap.protocol.tcpip.Tcp类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。 |
请发表评论