Пример #1
0
        private void HandleNATTest2(object sender, UdpDataReceivedEventArgs e)
        {
            var p = new Packet(e.Packet, 2);
            //_packetLogger.Log<ENATPacket>(p);

            switch (p.PacketID)
            {
                case (byte)ENATPacket.Req3:
                    var addr = p.ReadUInt32();
                    var port = p.ReadUInt16();
                    //_logger.Debug("-NAT Test2- ID: {0} IP: {1} Port: {2} | {3}", p.PacketID, new IPAddress(addr), port, e.IPEndPoint.ToString());

                    var ack = new Packet(ENATPacket.Ack3);
                    ack.Write((uint)e.IPEndPoint.Address.Address);
                    ack.Write((ushort)e.IPEndPoint.Port);
                    _natServer2.Send(e.IPEndPoint, ack);
                    break;

                default:
                    _logger.Warning("-NAT Test2- ID: {0}", p.PacketID);
                    break;

            }
        }
Пример #2
0
        private void HandleNATTest(object sender, UdpDataReceivedEventArgs e)
        {
            var p = new Packet(e.Packet, 2);
            //_packetLogger.Log<ENATPacket>(p);

            uint addr;
            ushort port;

            Packet ack;
            switch (p.PacketID)
            {
                case (byte)ENATPacket.Req1: // test request
                    addr = p.ReadUInt32();
                    port = p.ReadUInt16();
                    //_logger.Debug("-NAT Test- ID: {0} IP: {1} Port: {2} | {3}", p.PacketID, new IPAddress(addr), port, e.IPEndPoint.ToString());

                    ack = new Packet(ENATPacket.Ack1);
                    ack.Write((uint)e.IPEndPoint.Address.Address);
                    ack.Write((ushort)e.IPEndPoint.Port);
                    _natServer.Send(e.IPEndPoint, ack);
                    break;

                case (byte)ENATPacket.Req2: // firewall/nat type test
                    addr = p.ReadUInt32();
                    port = p.ReadUInt16();
                    //_logger.Debug("-NAT Test- ID: {0} IP: {1} Port: {2} | {3}", p.PacketID, new IPAddress(addr), port, e.IPEndPoint.ToString());

                    ack = new Packet(ENATPacket.Ack2);
                    ack.Write((uint)e.IPEndPoint.Address.Address);
                    ack.Write((ushort)e.IPEndPoint.Port);
                    _natServer2.Send(e.IPEndPoint, ack);
                    break;

                case (byte)ENATPacket.KeepAlive: // keepalive?
                    break;

                default:
                    _logger.Warning("-NAT Test- ID: {0}", p.PacketID);
                    break;

            }
        }