Beispiel #1
0
 public UDPSession(ConnectionKey parKey, IPAddress parAdapterIP, byte[] parBroadcastIP)
     : base(parKey, parAdapterIP)
 {
     broadcastAddr = parBroadcastIP;
     lock (deathClock)
     {
         deathClock.Start();
     }
 }
Beispiel #2
0
 public Session(ConnectionKey parKey, IPAddress parAdapterIP)
 {
     adapterIP = parAdapterIP;
     Key = parKey;
 }
Beispiel #3
0
 public TCPSession(ConnectionKey parKey, IPAddress parAdapterIP)
     : base(parKey, parAdapterIP)
 {
 }
Beispiel #4
0
 public ICMPSession(ConnectionKey parKey, ConcurrentDictionary<ConnectionKey, Session> parConnections)
     : base(parKey, IPAddress.Any)
 {
     connections = parConnections;
 }
Beispiel #5
0
        public override bool Send(IPPayload payload)
        {
            ICMP icmp = (ICMP)payload;

            switch (icmp.Type)
            {
                case 8: //Echo
                    //Code == zero
                    Log_Verb("Send Ping");
                    lock (sentry)
                    {
                        open += 1;
                    }
                    PingData pd;
                    pd.Data = icmp.Data;
                    pd.HeaderData = icmp.HeaderData;
                    Ping nPing = new Ping();
                    nPing.PingCompleted += PingCompleate;
                    lock (sentry)
                    {
                        pings.Add(nPing);
                    }
                    nPing.SendAsync(new IPAddress(DestIP), pd);
                    System.Threading.Thread.Sleep(1); //Hack Fix
                    break;
                case 3: //
                    switch (icmp.Code)
                    {
                        case 3:
                            Log_Error("Recived Packet Rejected, Port Closed");
                            IPPacket retPkt = new IPPacket(icmp);
                            byte[] srvIP = retPkt.SourceIP;
                            byte prot = retPkt.Protocol;
                            UInt16 srvPort = 0;
                            UInt16 ps2Port = 0;
                            switch (prot)
                            {
                                case (byte)IPType.TCP:
                                    TCP tcp = (TCP)retPkt.Payload;
                                    srvPort = tcp.SourcePort;
                                    ps2Port = tcp.DestinationPort;
                                    break;
                                case (byte)IPType.UDP:
                                    UDP udp = (UDP)retPkt.Payload;
                                    srvPort = udp.SourcePort;
                                    ps2Port = udp.DestinationPort;
                                    break;
                            }
                            ConnectionKey Key = new ConnectionKey();
                            Key.IP0 = srvIP[0]; Key.IP1 = srvIP[1]; Key.IP2 = srvIP[2]; Key.IP3 = srvIP[3];
                            Key.Protocol = prot;
                            Key.PS2Port = ps2Port;
                            Key.SRVPort = srvPort;

                            Session s;
                            connections.TryGetValue(Key, out s);

                            if (s != null)
                            {
                                s.Reset();
                                Log_Info("Reset Rejected Connection");
                            }
                            else
                            {
                                Log_Error("Failed To Reset Rejected Connection");
                            }
                            break;
                        default:
                            throw new NotImplementedException("Unsupported ICMP Code For Destination Unreachable" + icmp.Code);
                    }
                    break;
                default:
                    throw new NotImplementedException("Unsupported ICMP Type" + icmp.Type);
            }

            return true;
        }