// For names -> type A Query // For IP addresses -> PTR + A -> will at least return itself // Careful: for IP addresses with PTR, the hostname might yield different IP addresses! public bool GetHostEntryAsync(SimpleResolverEventArgs args) { if (args == null) { throw new ArgumentNullException("args"); } if (args.HostName == null) { throw new ArgumentNullException("args.HostName is null"); } if (args.HostName.Length > 255) { throw new ArgumentException("args.HostName is too long"); } args.Reset(ResolverAsyncOperation.GetHostEntry); string host = args.HostName; if (host == "") { GetLocalHost(args); return(false); } IPAddress addr; if (IPAddress.TryParse(host, out addr)) { IPHostEntry entry = new IPHostEntry(); entry.HostName = host; entry.Aliases = EmptyStrings; entry.AddressList = new IPAddress [1] { addr }; args.HostEntry = entry; args.PTRAddress = addr; SendPTRQuery(args, true); return(true); } // 3. For IP addresses: // 3.1 Parsing IP succeeds // 3.2 Reverse lookup of the IP fills in HostName -> fails? HostName = IP // 3.3 The hostname resulting from this is used to query DNS again to get the IP addresses // // Exclude IPv6 addresses if not supported by the system // .Aliases is always empty // Length > 255 SendAQuery(args, true); return(true); }
// Type A query // Might fill in Aliases // -IPAddress -> return the same IPAddress // -"" -> Local host ip addresses (filter out IPv6 if needed) public bool GetHostAddressesAsync(SimpleResolverEventArgs args) { if (args == null) { throw new ArgumentNullException("args"); } if (args.HostName == null) { throw new ArgumentNullException("args.HostName is null"); } if (args.HostName.Length > 255) { throw new ArgumentException("args.HostName is too long"); } args.Reset(ResolverAsyncOperation.GetHostAddresses); string host = args.HostName; if (host == "") { GetLocalHost(args); return(false); } IPAddress addr; if (IPAddress.TryParse(host, out addr)) { IPHostEntry entry = new IPHostEntry(); entry.HostName = host; entry.Aliases = EmptyStrings; entry.AddressList = new IPAddress [1] { addr }; args.HostEntry = entry; return(false); } SendAQuery(args, true); return(true); }
// For names -> type A Query // For IP addresses -> PTR + A -> will at least return itself // Careful: for IP addresses with PTR, the hostname might yield different IP addresses! public bool GetHostEntryAsync (SimpleResolverEventArgs args) { if (args == null) throw new ArgumentNullException ("args"); if (args.HostName == null) throw new ArgumentNullException ("args.HostName is null"); if (args.HostName.Length > 255) throw new ArgumentException ("args.HostName is too long"); args.Reset (ResolverAsyncOperation.GetHostEntry); string host = args.HostName; if (host == "") { GetLocalHost (args); return false; } IPAddress addr; if (IPAddress.TryParse (host, out addr)) { IPHostEntry entry = new IPHostEntry (); entry.HostName = host; entry.Aliases = EmptyStrings; entry.AddressList = new IPAddress [1] { addr }; args.HostEntry = entry; args.PTRAddress = addr; SendPTRQuery (args, true); return true; } // 3. For IP addresses: // 3.1 Parsing IP succeeds // 3.2 Reverse lookup of the IP fills in HostName -> fails? HostName = IP // 3.3 The hostname resulting from this is used to query DNS again to get the IP addresses // // Exclude IPv6 addresses if not supported by the system // .Aliases is always empty // Length > 255 SendAQuery (args, true); return true; }
// Type A query // Might fill in Aliases // -IPAddress -> return the same IPAddress // -"" -> Local host ip addresses (filter out IPv6 if needed) public bool GetHostAddressesAsync (SimpleResolverEventArgs args) { if (args == null) throw new ArgumentNullException ("args"); if (args.HostName == null) throw new ArgumentNullException ("args.HostName is null"); if (args.HostName.Length > 255) throw new ArgumentException ("args.HostName is too long"); args.Reset (ResolverAsyncOperation.GetHostAddresses); string host = args.HostName; if (host == "") { GetLocalHost (args); return false; } IPAddress addr; if (IPAddress.TryParse (host, out addr)) { IPHostEntry entry = new IPHostEntry (); entry.HostName = host; entry.Aliases = EmptyStrings; entry.AddressList = new IPAddress [1] { addr }; args.HostEntry = entry; return false; } SendAQuery (args, true); return true; }