// Path: src/main/java/net/fs/utils/MLog.java
// public class MLog {
// 
//     public static void info(Object str) {
//         System.out.println(str);
//     }
// 
// //	public static void println(Object str){
// //		System.out.println(str);
// //	}
// 
//     public static void println(String str) {
//         System.out.println(str);
//     }
// 
// //	public static void println(){
// //		System.out.println();
// //	}
// //	
// //	public static void print(String str){
// //		System.out.print(str);
// //	}
// 
// }


import net.fs.utils.MLog;
import org.pcap4j.core.NotOpenException;
import org.pcap4j.core.PcapHandle;
import org.pcap4j.core.PcapNativeException;
import org.pcap4j.packet.EthernetPacket.EthernetHeader;
import org.pcap4j.packet.IpV4Packet.IpV4Header;
import org.pcap4j.packet.Packet;
import org.pcap4j.packet.TcpPacket;
import org.pcap4j.packet.TcpPacket.TcpHeader;
import org.pcap4j.util.MacAddress;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Random;

            MLog.println("reset packet " + ipV4Header.getIdentification() + " " + tcpHeader.getSequenceNumber() + " "
                    + remoteAddress.getHostAddress() + ":" + remotePort + "->" + localAddress.getHostAddress() + ":" +
                    localPort + " " + " ident " + ipV4Header.getIdentification());
        }

    }

    public void process_client(CapEnv capEnv, final Packet packet, EthernetHeader ethernetHeader, IpV4Header
            ipV4Header, TcpPacket tcpPacket, boolean client) {

        TcpHeader tcpHeader = tcpPacket.getHeader();
        if (!preDataReady) {
            if (!connectReady) {
                if (tcpHeader.getAck() && tcpHeader.getSyn()) {
                    if (tcpHeader.getAcknowledgmentNumber() == (localStartSequence + 1)) {
                        MLog.println("接收第二次握手 " + " ident " + ipV4Header.getIdentification());
                        MLog.println("" + packet);
                        remoteStartSequence = tcpHeader.getSequenceNumber();
                        remoteSequence = remoteStartSequence + 1;
                        remoteSequence_max = remoteSequence;
                        Packet p3 = PacketUtils.createAck(capEnv.local_mac, capEnv.gateway_mac, capEnv.local_ipv4,
                                localPort, remoteAddress, remotePort, remoteSequence, localSequence, getIdent());
                        try {
                            sendHandle.sendPacket(p3);
                            MLog.println("发送第三次握手 " + " ident " + localIdent);
                            MLog.println("" + p3);
                            connectReady = true;

                            byte[] sim = getSimRequestHead(remotePort);
                            sendData(sim);

// Path: src/main/java/net/fs/utils/MLog.java
// public class MLog {
// 
//     public static void info(Object str) {
//         System.out.println(str);
//     }
// 
// //	public static void println(Object str){
// //		System.out.println(str);
// //	}
// 
//     public static void println(String str) {
//         System.out.println(str);
//     }
// 
// //	public static void println(){
// //		System.out.println();
// //	}
// //	
// //	public static void print(String str){
// //		System.out.print(str);
// //	}
// 
// }


// Path: src/main/java/net/fs/cap/TCPTun.java
import net.fs.utils.MLog;
import org.pcap4j.core.NotOpenException;
import org.pcap4j.core.PcapHandle;
import org.pcap4j.core.PcapNativeException;
import org.pcap4j.packet.EthernetPacket.EthernetHeader;
import org.pcap4j.packet.IpV4Packet.IpV4Header;
import org.pcap4j.packet.Packet;
import org.pcap4j.packet.TcpPacket;
import org.pcap4j.packet.TcpPacket.TcpHeader;
import org.pcap4j.util.MacAddress;
import java.net.Inet4Address;
import java.net.InetAddress;
import java.util.ArrayList;
import java.util.HashMap;
import java.util.HashSet;
import java.util.Random;

            MLog.println("reset packet " + ipV4Header.getIdentification() + " " + tcpHeader.getSequenceNumber() + " "
                    + remoteAddress.getHostAddress() + ":" + remotePort + "->" + localAddress.getHostAddress() + ":" +
                    localPort + " " + " ident " + ipV4Header.getIdentification());
        }

    }

    public void process_client(CapEnv capEnv, final Packet packet, EthernetHeader ethernetHeader, IpV4Header
            ipV4Header, TcpPacket tcpPacket, boolean client) {

        TcpHeader tcpHeader = tcpPacket.getHeader();
        if (!preDataReady) {
            if (!connectReady) {
                if (tcpHeader.getAck() && tcpHeader.getSyn()) {
                    if (tcpHeader.getAcknowledgmentNumber() == (localStartSequence + 1)) {
                        MLog.println("接收第二次握手 " + " ident " + ipV4Header.getIdentification());
                        MLog.println("" + packet);
                        remoteStartSequence = tcpHeader.getSequenceNumber();
                        remoteSequence = remoteStartSequence + 1;
                        remoteSequence_max = remoteSequence;
                        Packet p3 = PacketUtils.createAck(capEnv.local_mac, capEnv.gateway_mac, capEnv.local_ipv4,
                                localPort, remoteAddress, remotePort, remoteSequence, localSequence, getIdent());
                        try {
                            sendHandle.sendPacket(p3);
                            MLog.println("发送第三次握手 " + " ident " + localIdent);
                            MLog.println("" + p3);
                            connectReady = true;

                            byte[] sim = getSimRequestHead(remotePort);
                            sendData(sim);

                            MLog.println("发送请求 " + " ident " + localIdent);
