Ipop.StaticDns.AddressLookUp C# (CSharp) Method

AddressLookUp() public method

Called during LookUp to perform translation from hostname to IP. If an entry isn't in cache, we can try to get it from the Dht. Throws an exception if the name is invalid and returns null if no name is found.
public AddressLookUp ( String name ) : String
name String The name to lookup
return String
    public override String AddressLookUp(String name)
    {
      String res = null;
      // C 123 123 123 . domain.length
      int length = 1 + 9 + 1 + DomainName.Length;

      if(name.Length != length ||
          (name[0] != 'c' && name[0] != 'C') ||
          !name.EndsWith(DomainName, StringComparison.OrdinalIgnoreCase))
      {
        return null;
      }

      res = String.Empty;
      for(int i = 0; i < 3; i++) {
        res += Int32.Parse(name.Substring((3*i)+1, 3)) + ".";
      }
      return _base_address[0] + "." + res.Substring(0, res.Length - 1);
    }

Usage Example

Ejemplo n.º 1
0
        public void Test()
        {
            StaticDns dns = new StaticDns(
                MemBlock.Reference(Utils.StringToBytes("10.250.0.0", '.')),
                MemBlock.Reference(Utils.StringToBytes("255.255.0.0", '.')),
                string.Empty, false);

            Assert.AreEqual(dns.NameLookUp("10.250.1.1"), "C250001001.ipop", "NameLookUp Dns set in range.");

            try {
                Assert.AreEqual(dns.NameLookUp("10.251.1.1"), null, "NameLookUp Dns set out of range.");
            } catch { }

            Assert.AreEqual(dns.AddressLookUp("C250001001.ipop"), "10.250.1.1", "AddressLookUp Dns set.");

            try {
                Assert.AreEqual(dns.AddressLookUp("C250001001.blaha"), null, "AddressLookUp Dns set bad dns name: blaha.");
            } catch { }

            try {
                Assert.AreEqual(dns.AddressLookUp("C250001001.blah"), null, "AddressLookUp Dns set bad dns name: blah.");
            } catch { }

            dns = new StaticDns(
                MemBlock.Reference(Utils.StringToBytes("10.251.0.0", '.')),
                MemBlock.Reference(Utils.StringToBytes("255.255.0.0", '.')),
                string.Empty, false);

            try {
                Assert.AreEqual(dns.NameLookUp("10.250.1.1"), null, "NameLookUp Dns changed out of range.");
            } catch { }

            Assert.AreEqual(dns.NameLookUp("10.251.1.1"), "C251001001.ipop", "NameLookUp Dns changed in range.");
        }
All Usage Examples Of Ipop.StaticDns::AddressLookUp