Ejemplo n.º 1
0
        public static void NS_OnReceive(Packet packet)
        {
            if (packet.Protocol == ProtocolType.Udp)
            {
                if ((packet.TransportHeader as UdpHeader).IsDns)
                {
                    DnsPacket dns = new DnsPacket(packet);
                    for (int i = 0; i < dns.Questions.Length; i++)
                    {
                        Write(dns.Questions[i]);
                    }

                    for (int i = 0; i < dns.Answers.Length; i++)
                    {
                        Write('\t' + dns.Answers[i].ToString());
                    }
                }
                else Write($"UDP: {(packet.TransportHeader as UdpHeader).ByteCount}");
            }
            else if (packet.Protocol == ProtocolType.Tcp)
            {
                if ((packet.TransportHeader as TcpHeader).IsDns) Write("DNS(TCP)");
                else Write("TCP");
            }
            else if (packet.Protocol == ProtocolType.Icmp) Write($"ICMP({(packet.TransportHeader as IcmpHeader).Type})");
            else Write(packet.Protocol.ToString());
        }
Ejemplo n.º 2
0
        private static void HandlePackage(IAsyncResult ar)
        {
            int count = socket.EndReceive(ar);
            Packet p = new Packet(buffer, count);

            if (!Stop)
            {
                buffer = new byte[4096];
                socket.BeginReceive(buffer, 0, buffer.Length, 0, HandlePackage, null);
            }
            else working = false;

            if (OnReceive != null) OnReceive.Invoke(p);
        }