示例#1
0
 def tcp_send_syn(cls, packet, remote_info, local_info):
     from core.sock import SockManager
     sock = SockManager.lookup_bidirectional_sock(Tcp.PROT_TYPE, local_info, remote_info)
     if sock is None:
         return
     Tcp.tcp_send_packet(sock, remote_info, local_info, ['syn'])
     sock._snd_nxt += 1
示例#2
0
 def write(cls, packet, remote_info, local_info):
     from core.sock import SockManager
     sock = SockManager.lookup_bidirectional_sock(Tcp.PROT_TYPE, local_info, remote_info)
     if sock is None:
         return
     Tcp.tcp_send_packet(sock, remote_info, local_info, ['psh', 'ack'], out_packet=packet)
     sock._snd_nxt += len(packet)
示例#3
0
    async def connect(self, remote_info):
        if self._sock is not None:
            return
        remote_ip_addr, remote_port = remote_info
        remote_ip_addr = util.ip_s2i(remote_ip_addr)

        remote_info_int = remote_ip_addr, remote_port
        local_info_int = self._local_ip_addr_int, self._local_port

        self._sock = SockManager.lookup_bidirectional_sock(
            self._prot_type, local_info_int, remote_info_int)
        await self._sock.connect()
        return
示例#4
0
 def recv(cls, ipv4_packet):
     tcp_packet = TcpPacket(ipv4_packet.payload)
     tcp_packet.LOG("info", "TAKE")
     from core.sock import SockManager
     local_info = ipv4_packet.dst_ip_addr, tcp_packet.dst_port
     remote_info = ipv4_packet.src_ip_addr, tcp_packet.src_port
     sock = SockManager.lookup_bidirectional_sock(Tcp.PROT_TYPE, local_info, remote_info)
     if sock is None:
         sock = SockManager.lookup_unidirectional_sock(Tcp.PROT_TYPE, local_info)
         if sock is None:
             tcp_packet.LOG("error", "no sock")
             return
         sock = SockManager.register_bidirectional_sock(Tcp.PROT_TYPE, remote_info, local_info)
         sock.state = "TCP_LISTEN"
     sock.LOG("info", "START")
     Tcp.tcp_state_transform(sock, ipv4_packet, tcp_packet)
     sock.LOG("info", "FINISH")