PtrMemBlockToString() public static method

Takes in a memblock containing dns ptr data ... d.c.b.a.in-addr.arpa ... and returns the IP Address as a string.
public static PtrMemBlockToString ( MemBlock ptr ) : String
ptr MemBlock The block containing the dns ptr data.
return String
Exemplo n.º 1
0
        public void TestPtr()
        {
            String   ptr  = "64.233.169.104";
            MemBlock ptrm = MemBlock.Reference(new byte[] { 0x03, 0x31, 0x30, 0x34,
                                                            0x03, 0x31, 0x36, 0x39, 0x03, 0x32, 0x33, 0x33, 0x02, 0x36, 0x34, 0x07,
                                                            0x69, 0x6e, 0x2d, 0x61, 0x64, 0x64, 0x72, 0x04, 0x61, 0x72, 0x70, 0x61,
                                                            0x00 });

            Assert.AreEqual(ptr, DnsPacket.PtrMemBlockToString(ptrm),
                            "PtrMemBlockToString");
            Assert.AreEqual(ptrm, DnsPacket.PtrStringToMemBlock(ptr),
                            "PtrStringToMemBlock");
            Assert.AreEqual(ptr, DnsPacket.PtrMemBlockToString(
                                DnsPacket.PtrStringToMemBlock(ptr)),
                            "Ptr String dual");
            Assert.AreEqual(ptrm, DnsPacket.PtrStringToMemBlock(
                                DnsPacket.PtrMemBlockToString(ptrm)),
                            "Ptr MemBlock dual");
        }
Exemplo n.º 2
0
        /**
         * <summary>Creates a response given the entire packet.</summary>
         * <remarks>The entire packet must be given, because some name servers take
         * advantage of pointers to reduce their size.</remarks>
         * <param name="Data">The entire Dns packet.</param>
         * <param name="Start">The starting position of the Response.</param>
         */
        public Response(MemBlock Data, int Start)
        {
            int idx = 0;

            NameBlob = DnsPacket.RetrieveBlob(Data, Start, out idx);

            int type = (Data[idx++] << 8) + Data[idx++];

            Type = (DnsPacket.Types)type;

            CacheFlush = ((Data[idx] & 0x80) == 0x80) ? true : false;
            int rclass = ((Data[idx++] << 8) & 0x7F) + Data[idx++];

            Class = (DnsPacket.Classes)rclass;

            Ttl  = (Data[idx++] << 24);
            Ttl |= (Data[idx++] << 16);
            Ttl |= (Data[idx++] << 8);
            Ttl |= (Data[idx++]);

            RdLength  = (short)((Data[idx++] << 8) + Data[idx++]);
            RDataBlob = Data.Slice(idx, RdLength);

            if (Type == DnsPacket.Types.Ptr)
            {
                try {
                    Name = DnsPacket.PtrMemBlockToString(NameBlob);
                }
                catch {
                    Name = DnsPacket.HostnameMemBlockToString(NameBlob);
                }
                int End = 0;
                RDataBlob = DnsPacket.RetrieveBlob(Data, idx, out End);
                RData     = DnsPacket.HostnameMemBlockToString(RDataBlob);
            }
            else if (Type == DnsPacket.Types.A)
            {
                Name  = DnsPacket.HostnameMemBlockToString(NameBlob);
                RData = DnsPacket.IPMemBlockToString(RDataBlob);
            }
            _icpacket = _packet = Data.Slice(Start, idx + RdLength - Start);
        }
Exemplo n.º 3
0
        /**
         * <summary>Constructor when parsing a Dns Query</summary>
         * <param name="Data"> must pass in the entire packet from where the question
         * begins, after parsing, can check Data.Length to find where next
         * container begins.</param>
         */
        public Question(MemBlock Data, int Start)
        {
            int idx = 0;

            QNameBlob = DnsPacket.RetrieveBlob(Data, Start, out idx);
            int qtype = (Data[idx++] << 8) + Data[idx++];

            QType = (DnsPacket.Types)qtype;

            int qclass = (Data[idx++] << 8) + Data[idx];

            QClass = (DnsPacket.Classes)qclass;

            if (QType == DnsPacket.Types.A || QType == DnsPacket.Types.AAAA)
            {
                QName = DnsPacket.HostnameMemBlockToString(QNameBlob);
            }
            else if (QType == DnsPacket.Types.Ptr)
            {
                QName = DnsPacket.PtrMemBlockToString(QNameBlob);
            }

            _icpacket = _packet = Data.Slice(Start, idx + 1 - Start);
        }