NetworkPackets.Dns.DnsPacket.PtrStringToMemBlock C# (CSharp) Method

PtrStringToMemBlock() public static method

Takes in an IP Address string and returns the dns ptr formatted memblock containing d.c.b.a.in-addr.arpa.
public static PtrStringToMemBlock ( String ptr ) : MemBlock
ptr String An IP Address in the format a.b.c.d.
return MemBlock
    public static MemBlock PtrStringToMemBlock(String ptr) {
      String[] res = ptr.Split('.');
      String name = String.Empty;
      for(int i = res.Length - 1; i > 0; i--) {
        name += res[i] + ".";
      }
      name += res[0] + INADDR_ARPA;
      return HostnameStringToMemBlock(name);
    }

Usage Example

Exemplo n.º 1
0
        /**
         * <summary>Constructor when creating a Dns Query</summary>
         * <param name="QName">the name of resource you are looking up, IP Address
         * when QType = Ptr otherwise hostname</param>
         * <param name="QType"> the type of look up to perform</param>
         * <param name="QClass">should always be IN</param>
         */
        public Question(String QName, DnsPacket.Types QType, DnsPacket.Classes QClass)
        {
            this.QName  = QName;
            this.QType  = QType;
            this.QClass = QClass;

            if (QType == DnsPacket.Types.A || QType == DnsPacket.Types.AAAA)
            {
                QNameBlob = DnsPacket.HostnameStringToMemBlock(QName);
            }
            else if (QType == DnsPacket.Types.Ptr)
            {
                QNameBlob = DnsPacket.PtrStringToMemBlock(QName);
            }
            else
            {
                throw new Exception("Invalid QType: " + QType + "!");
            }

            // 2 for QType + 2 for QClass
            byte[] data = new byte[4];
            int    idx  = 0;

            data[idx++] = (byte)((((int)QType) >> 8) & 0xFF);
            data[idx++] = (byte)(((int)QType) & 0xFF);
            data[idx++] = (byte)((((int)QClass) >> 8) & 0xFF);
            data[idx++] = (byte)(((int)QClass) & 0xFF);
            _icpacket   = new CopyList(QNameBlob, MemBlock.Reference(data));
        }
All Usage Examples Of NetworkPackets.Dns.DnsPacket::PtrStringToMemBlock