示例#1
0
        public DnsPacket(Packet packet)
        {
            Header = (packet.ApplicationHeader as DnsHeader);
            if (Header == null) throw new ArgumentException("Non-Dns packet!");
            NetBinaryReader nbr = new NetBinaryReader(Header.data);

            Questions = new DnsQuestion[Header.QuestionCount];
            for (int i = 0; i < Questions.Length; i++)
            {
                Questions[i] = new DnsQuestion(nbr);
            }

            Answers = new DnsAnswer[Header.AnswerCount];
            for (int i = 0; i < Answers.Length; i++)
            {
                Answers[i] = new DnsAnswer(nbr);
            }

            Authority = new DnsAnswer[Header.AuthorityCount];
            for (int i = 0; i < Authority.Length; i++)
            {
                Authority[i] = new DnsAnswer(nbr);
            }

            Information = new DnsAnswer[Header.AdditionalCount];
            for (int i = 0; i < Information.Length; i++)
            {
                Information[i] = new DnsAnswer(nbr);
            }
        }
示例#2
0
文件: Packet.cs 项目: Arzana/Sniffles
        public Packet(byte[] raw, int byteCount)
        {
            rawData = raw;
            IpHeader = new IPHeader(raw, byteCount);

            switch (Protocol)
            {
                case (ProtocolType.Udp):
                    UdpHeader udpHeader = new UdpHeader(raw, IPHeader.OCTET_COUNT, byteCount);
                    TransportHeader = udpHeader;

                    if (udpHeader.IsDns) ApplicationHeader = new DnsHeader(raw, IPHeader.OCTET_COUNT + UdpHeader.OCTET_COUNT, byteCount);
                    break;
                case (ProtocolType.Tcp):
                    TcpHeader tcpHeader = new TcpHeader(raw, IPHeader.OCTET_COUNT);
                    TransportHeader = tcpHeader;
                    break;
                case (ProtocolType.Icmp):
                    IcmpHeader icmpHeader = new IcmpHeader(raw, IPHeader.OCTET_COUNT, byteCount);
                    TransportHeader = icmpHeader;
                    break;
            }
        }