Hostname for .net too long?

The . NET Dns class has a hard upper limit of 126 characters for hostnames (checked for . NET4) However, you can use the lower-level Win32 DnsQuery method using P/Invoke to translate host names into IP addresses and then use those raw addresses with the .

NET networking classes Here is a sample DnsAddr class using this approach: public static class DnsAddr { DllImport("dnsapi", EntryPoint = "DnsQuery_W", CharSet = CharSet. Unicode, SetLastError = true, ExactSpelling = true) private static extern int DnsQuery(MarshalAs(UnmanagedType. VBByRefStr)ref string pszName, QueryTypes wType, QueryOptions options, int aipServers, ref IntPtr ppQueryResults, int pReserved); DllImport("dnsapi", CharSet = CharSet.

Auto, SetLastError = true) private static extern void DnsRecordListFree(IntPtr pRecordList, int FreeType); public static IEnumerable GetAddress(string domain) { IntPtr ptr1 = IntPtr. Zero; IntPtr ptr2 = IntPtr. Zero; List list = new List(); DnsRecord record = new DnsRecord(); int num1 = DnsAddr.DnsQuery(ref domain, QueryTypes.

DNS_TYPE_A, QueryOptions. DNS_QUERY_NONE, 0, ref ptr1, 0); if (num1! = 0) throw new Win32Exception(num1); for (ptr2 = ptr1;!

Ptr2. Equals(IntPtr. Zero); ptr2 = record.

PNext) { record = (DnsRecord)Marshal. PtrToStructure(ptr2, typeof(DnsRecord)); list. Add(new IPAddress(record.

IpAddress)); } DnsAddr.DnsRecordListFree(ptr1, 0); return list; } private enum QueryOptions { DNS_QUERY_NONE = 0, } private enum QueryTypes { DNS_TYPE_A = 1, } StructLayout(LayoutKind. Sequential) private struct DnsRecord { public IntPtr pNext; public string pName; public short wType; public short wDataLength; public int flags; public int dwTtl; public int dwReserved; public uint ipAddress; } } Here is a sample test program: class Program { static void Main(string args) { var addresses = DnsAddr.GetAddress("google. Com"); foreach (var address in addresses) Console.

WriteLine(address.ToString()); } } which on my machine produces this output: 173.194.33.51 173.194.33.50 173.194.33.49 173.194.33.52 173.194.33.48.

The . NET Dns class has a hard upper limit of 126 characters for hostnames (checked for . NET4).

However, you can use the lower-level Win32 DnsQuery method using P/Invoke to translate host names into IP addresses and then use those raw addresses with the . NET networking classes. Here is a sample DnsAddr class using this approach: public static class DnsAddr { DllImport("dnsapi", EntryPoint = "DnsQuery_W", CharSet = CharSet.

Unicode, SetLastError = true, ExactSpelling = true) private static extern int DnsQuery(MarshalAs(UnmanagedType. VBByRefStr)ref string pszName, QueryTypes wType, QueryOptions options, int aipServers, ref IntPtr ppQueryResults, int pReserved); DllImport("dnsapi", CharSet = CharSet. Auto, SetLastError = true) private static extern void DnsRecordListFree(IntPtr pRecordList, int FreeType); public static IEnumerable GetAddress(string domain) { IntPtr ptr1 = IntPtr.

Zero; IntPtr ptr2 = IntPtr. Zero; List list = new List(); DnsRecord record = new DnsRecord(); int num1 = DnsAddr.DnsQuery(ref domain, QueryTypes. DNS_TYPE_A, QueryOptions.

DNS_QUERY_NONE, 0, ref ptr1, 0); if (num1! = 0) throw new Win32Exception(num1); for (ptr2 = ptr1;! Ptr2.

Equals(IntPtr. Zero); ptr2 = record. PNext) { record = (DnsRecord)Marshal.

PtrToStructure(ptr2, typeof(DnsRecord)); list. Add(new IPAddress(record. IpAddress)); } DnsAddr.DnsRecordListFree(ptr1, 0); return list; } private enum QueryOptions { DNS_QUERY_NONE = 0, } private enum QueryTypes { DNS_TYPE_A = 1, } StructLayout(LayoutKind.

Sequential) private struct DnsRecord { public IntPtr pNext; public string pName; public short wType; public short wDataLength; public int flags; public int dwTtl; public int dwReserved; public uint ipAddress; } } Here is a sample test program: class Program { static void Main(string args) { var addresses = DnsAddr.GetAddress("google. Com"); foreach (var address in addresses) Console. WriteLine(address.ToString()); } } which on my machine produces this output: 173.194.33.51 173.194.33.50 173.194.33.49 173.194.33.52 173.194.33.48.

Call gethostbyname, then pass an IP address (which is never more than a couple dozen characters, even for IPv6) to the ping class.

Both informations are right. The 255 character limit refers to the entire hostname (e.g. Some.thing.example.Com). In turn, each label (e.g. Example or com) is limited to 63 characters.So top-level domains have a theoretical limit of 126 non-dot characters.

Apparently it is like Joel and Dennis explained. . Net is not capable of resolving names longer than 126 chars.

However if somebody has the same problem, take a look here at DNS Plus: simpledns.com/dns-client-lib.aspx#download.

I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.

Related Questions