[System] Rewrite Dns tests so that failures don't cause the process to crash.
[mono.git] / mcs / class / System / Test / System.Net / DnsTest.cs
1 // DnsTest.cs - NUnit Test Cases for the System.Net.Dns class\r
2 //\r
3 // Authors: \r
4 //   Mads Pultz (mpultz@diku.dk)\r
5 //   Martin Willemoes Hansen (mwh@sysrq.dk)\r
6 //\r
7 // (C) 2001 Mads Pultz\r
8 // (C) 2003 Martin Willemoes Hansen\r
9 // \r
10 \r
11 using System;\r
12 using System.Linq;\r
13 using System.Net;\r
14 using System.Net.Sockets;\r
15 using System.Threading;\r
16 \r
17 using NUnit.Framework;\r
18 \r
19 namespace MonoTests.System.Net\r
20 {\r
21         [TestFixture]\r
22         [Category ("RequiresBSDSockets")]\r
23         public class DnsTest\r
24         {\r
25                 private String site1Name = "google-public-dns-a.google.com",\r
26                         site1Dot = "8.8.8.8",\r
27                         site2Name = "google-public-dns-b.google.com",\r
28                         site2Dot = "8.8.4.4",\r
29                         noneExistingSite = "unlikely.xamarin.com";\r
30                 private uint site1IP = 134744072, site2IP = 134743044; // Big-Endian\r
31 \r
32                 [Test]\r
33                 public void AsyncGetHostByName ()\r
34                 {\r
35                         IAsyncResult async = Dns.BeginGetHostByName (site1Name, null, null);\r
36                         IPHostEntry entry = Dns.EndGetHostByName (async);\r
37                         SubTestValidIPHostEntry (entry);\r
38                         Assert.IsTrue (entry.HostName == "google-public-dns-a.google.com");\r
39                 }\r
40 \r
41                 [Test]\r
42                 public void AsyncGetHostByNameCallback ()\r
43                 {\r
44                         var evt = new ManualResetEvent (false);\r
45                         Exception ex = null;\r
46                         Dns.BeginGetHostByName (site1Name, new AsyncCallback ((IAsyncResult ar) =>\r
47                         {\r
48                                 try {\r
49                                         IPHostEntry h;\r
50                                         h = Dns.EndGetHostByName (ar);\r
51                                         SubTestValidIPHostEntry (h);\r
52                                 } catch (Exception e) {\r
53                                         ex = e;\r
54                                 } finally {\r
55                                         evt.Set ();\r
56                                 }\r
57                         }), null);\r
58 \r
59                         Assert.IsTrue (evt.WaitOne (TimeSpan.FromSeconds (60)), "Wait");\r
60                         Assert.IsNull (ex, "Exception");\r
61                 }\r
62 \r
63                 [Test]\r
64                 public void AsyncResolve ()\r
65                 {\r
66                         IAsyncResult async = Dns.BeginResolve (site1Dot, null, null);\r
67                         IPHostEntry entry = Dns.EndResolve (async);\r
68                         SubTestValidIPHostEntry (entry);\r
69                         var ip = GetIPv4Address (entry);\r
70                         Assert.AreEqual (site1Dot, ip.ToString ());\r
71                 }\r
72 \r
73                 [Test]\r
74                 public void AsyncResolveCallback ()\r
75                 {\r
76                         var evt = new ManualResetEvent (false);\r
77                         Exception ex = null;\r
78                         Dns.BeginResolve (site1Name, new AsyncCallback ((IAsyncResult ar) =>\r
79                         {\r
80                                 try {\r
81                                         IPHostEntry h = Dns.EndResolve (ar);\r
82                                         SubTestValidIPHostEntry (h);\r
83                                 } catch (Exception e) {\r
84                                         ex = e;\r
85                                 } finally {\r
86                                         evt.Set ();\r
87                                 }\r
88                         }), null);\r
89 \r
90                         Assert.IsTrue (evt.WaitOne (TimeSpan.FromSeconds (60)), "Wait");\r
91                         Assert.IsNull (ex, "Exception");\r
92                 }\r
93 \r
94                 [Test]\r
95                 public void BeginGetHostAddresses_HostNameOrAddress_Null ()\r
96                 {\r
97                         try {\r
98                                 Dns.BeginGetHostAddresses (\r
99                                         (string) null,\r
100                                         new AsyncCallback (ShouldntBeCalled),\r
101                                         null);\r
102                                 Assert.Fail ("#1");\r
103                         } catch (ArgumentNullException ex) {\r
104                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");\r
105                                 Assert.IsNull (ex.InnerException, "#3");\r
106                                 Assert.IsNotNull (ex.Message, "#4");\r
107                                 Assert.AreEqual ("hostName", ex.ParamName, "#5");\r
108                         }\r
109                 }\r
110 \r
111                 [Test]\r
112                 public void BeginGetHostAddresses_HostNameOrAddress_UnspecifiedAddress ()\r
113                 {\r
114                         // IPv4\r
115                         try {\r
116                                 Dns.BeginGetHostAddresses (\r
117                                         "0.0.0.0",\r
118                                         new AsyncCallback (ShouldntBeCalled),\r
119                                         null);\r
120                                 Assert.Fail ("#A1");\r
121                         } catch (ArgumentException ex) {\r
122                                 // IPv4 address 0.0.0.0 and IPv6 address ::0 are\r
123                                 // unspecified addresses that cannot be used as\r
124                                 // a target address\r
125                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");\r
126                                 Assert.IsNull (ex.InnerException, "#A3");\r
127                                 Assert.IsNotNull (ex.Message, "#A4");\r
128                                 Assert.AreEqual ("hostNameOrAddress", ex.ParamName, "#A5");\r
129                         }\r
130 \r
131                         // IPv6\r
132                         try {\r
133                                 Dns.BeginGetHostAddresses (\r
134                                         "::0",\r
135                                         new AsyncCallback (ShouldntBeCalled),\r
136                                         null);\r
137                                 Assert.Fail ("#B1");\r
138                         } catch (ArgumentException ex) {\r
139                                 // IPv4 address 0.0.0.0 and IPv6 address ::0 are\r
140                                 // unspecified addresses that cannot be used as\r
141                                 // a target address\r
142                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");\r
143                                 Assert.IsNull (ex.InnerException, "#B3");\r
144                                 Assert.IsNotNull (ex.Message, "#B4");\r
145                                 Assert.AreEqual ("hostNameOrAddress", ex.ParamName, "#B5");\r
146                         }\r
147                 }\r
148 \r
149                 void ShouldntBeCalled (IAsyncResult ar)\r
150                 {\r
151                         Assert.Fail ("Should not be called");\r
152                 }\r
153 \r
154                 [Test]\r
155                 public void GetHostAddresses_HostNameOrAddress_Null ()\r
156                 {\r
157                         try {\r
158                                 Dns.GetHostAddresses ((string) null);\r
159                                 Assert.Fail ("#1");\r
160                         } catch (ArgumentNullException ex) {\r
161                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");\r
162                                 Assert.IsNull (ex.InnerException, "#3");\r
163                                 Assert.IsNotNull (ex.Message, "#4");\r
164                                 Assert.AreEqual ("hostNameOrAddress", ex.ParamName, "#5");\r
165                         }\r
166                 }\r
167 \r
168                 [Test]\r
169                 public void GetHostAddresses_HostNameOrAddress_UnspecifiedAddress ()\r
170                 {\r
171                         // IPv4\r
172                         try {\r
173                                 Dns.GetHostAddresses ("0.0.0.0");\r
174                                 Assert.Fail ("#A1");\r
175                         } catch (ArgumentException ex) {\r
176                                 // IPv4 address 0.0.0.0 and IPv6 address ::0 are\r
177                                 // unspecified addresses that cannot be used as\r
178                                 // a target address\r
179                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");\r
180                                 Assert.IsNull (ex.InnerException, "#A3");\r
181                                 Assert.IsNotNull (ex.Message, "#A4");\r
182                                 Assert.AreEqual ("hostNameOrAddress", ex.ParamName, "#A5");\r
183                         }\r
184 \r
185                         // IPv6\r
186                         try {\r
187                                 Dns.GetHostAddresses ("::0");\r
188                                 Assert.Fail ("#B1");\r
189                         } catch (ArgumentException ex) {\r
190                                 // IPv4 address 0.0.0.0 and IPv6 address ::0 are\r
191                                 // unspecified addresses that cannot be used as\r
192                                 // a target address\r
193                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");\r
194                                 Assert.IsNull (ex.InnerException, "#B3");\r
195                                 Assert.IsNotNull (ex.Message, "#B4");\r
196                                 Assert.AreEqual ("hostNameOrAddress", ex.ParamName, "#B5");\r
197                         }\r
198                 }\r
199 \r
200                 [Test]\r
201                 public void GetHostName ()\r
202                 {\r
203                         string hostName = Dns.GetHostName ();\r
204                         Assert.IsNotNull (hostName);\r
205                 }\r
206 \r
207                 [Test]\r
208                 public void GetHostByName ()\r
209                 {\r
210                         SubTestGetHostByName (site1Name, site1Dot);\r
211                         SubTestGetHostByName (site2Name, site2Dot);\r
212                         try {\r
213                                 var entry = Dns.GetHostByName (noneExistingSite);\r
214                                 /*\r
215                                  * Work around broken t-online.de DNS Server.\r
216                                  * \r
217                                  * T-Online's DNS Server for DSL Customers resolves\r
218                                  * non-exisitng domain names to\r
219                                  * http://navigationshilfe1.t-online.de/dnserror?url=....\r
220                                  * instead of reporting an error.\r
221                                  */\r
222                                 var navigationshilfe1 = IPAddress.Parse ("80.156.86.78");\r
223                                 var navigationshilfe2 = IPAddress.Parse ("62.157.140.133");\r
224                                 foreach (var addr in entry.AddressList) {\r
225                                         if (addr.Equals (navigationshilfe1) || addr.Equals (navigationshilfe2))\r
226                                                 return;\r
227                                 }\r
228                                 Assert.Fail ("Should raise a SocketException (assuming that '" + noneExistingSite + "' does not exist)");\r
229                         } catch (SocketException) {\r
230                         }\r
231                 }\r
232 \r
233                 static IPAddress GetIPv4Address (IPHostEntry h)\r
234                 {\r
235                         var al = h.AddressList.FirstOrDefault (x => x.AddressFamily == AddressFamily.InterNetwork);\r
236                         if (al == null)\r
237                                 Assert.Ignore ("Could not resolve an IPv4 address as required by this test case, e.g. running on an IPv6 only network");\r
238                         return al;\r
239                 }\r
240 \r
241                 void SubTestGetHostByName (string siteName, string siteDot)\r
242                 {\r
243                         IPHostEntry h = Dns.GetHostByName (siteName);\r
244                         SubTestValidIPHostEntry (h);\r
245                         Assert.AreEqual (siteName, h.HostName, "siteName");\r
246                         var ip = GetIPv4Address (h);\r
247                         Assert.AreEqual (siteDot, ip.ToString (), "siteDot");\r
248                 }\r
249 \r
250                 [Test]\r
251                 public void GetHostByName_HostName_Null ()\r
252                 {\r
253                         try {\r
254                                 Dns.GetHostByName ((string) null);\r
255                                 Assert.Fail ("#1");\r
256                         } catch (ArgumentNullException ex) {\r
257                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");\r
258                                 Assert.IsNull (ex.InnerException, "#3");\r
259                                 Assert.IsNotNull (ex.Message, "#4");\r
260                                 Assert.AreEqual ("hostName", ex.ParamName, "#5");\r
261                         }\r
262                 }\r
263 \r
264                 [Test]\r
265                 public void GetHostByAddressString_Address_Null ()\r
266                 {\r
267                         try {\r
268                                 Dns.GetHostByAddress ((string) null);\r
269                                 Assert.Fail ("#1");\r
270                         } catch (ArgumentNullException ex) {\r
271                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");\r
272                                 Assert.IsNull (ex.InnerException, "#3");\r
273                                 Assert.IsNotNull (ex.Message, "#4");\r
274                                 Assert.AreEqual ("address", ex.ParamName, "#5");\r
275                         }\r
276                 }\r
277 \r
278                 [Test]\r
279                 [ExpectedException (typeof (SocketException))]\r
280                 public void GetHostByAddressString2 ()\r
281                 {\r
282                         Dns.GetHostByAddress ("123.255.23");\r
283                 }\r
284 \r
285                 [Test]\r
286                 [ExpectedException (typeof (FormatException))]\r
287                 public void GetHostByAddressString3 ()\r
288                 {\r
289                         Dns.GetHostByAddress ("123.256.34.10");\r
290                 }\r
291 \r
292                 [Test, ExpectedException (typeof (FormatException))]\r
293                 public void GetHostByAddressString4 ()\r
294                 {\r
295                         Dns.GetHostByAddress ("not an IP address");\r
296                 }\r
297 \r
298                 [Test]\r
299                 public void GetHostByAddressString5 ()\r
300                 {\r
301                         Dns.GetHostByAddress (site1Dot);\r
302                 }\r
303 \r
304                 [Test]\r
305                 public void GetHostByAddressIPAddress_Address_Null ()\r
306                 {\r
307                         try {\r
308                                 Dns.GetHostByAddress ((IPAddress) null);\r
309                                 Assert.Fail ("#1");\r
310                         } catch (ArgumentNullException ex) {\r
311                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");\r
312                                 Assert.IsNull (ex.InnerException, "#3");\r
313                                 Assert.IsNotNull (ex.Message, "#4");\r
314                                 Assert.AreEqual ("address", ex.ParamName, "#5");\r
315                         }\r
316                 }\r
317 \r
318                 [Test]\r
319                 public void GetHostByAddressIPAddress2 ()\r
320                 {\r
321                         IPAddress addr = new IPAddress (IPAddress.NetworkToHostOrder ((int) site1IP));\r
322                         IPHostEntry h = Dns.GetHostByAddress (addr);\r
323                         SubTestValidIPHostEntry (h);\r
324                         var ip = GetIPv4Address (h);\r
325                         Assert.AreEqual (addr.ToString (), ip.ToString ());\r
326                 }\r
327 \r
328                 [Test]\r
329                 public void GetHostByAddressIPAddress3 ()\r
330                 {\r
331                         IPAddress addr = new IPAddress (IPAddress.NetworkToHostOrder ((int) site2IP));\r
332                         IPHostEntry h = Dns.GetHostByAddress (addr);\r
333                         SubTestValidIPHostEntry (h);\r
334                         var ip = GetIPv4Address (h);\r
335                         Assert.AreEqual (addr.ToString (), ip.ToString ());\r
336                 }\r
337 \r
338                 [Test]\r
339                 public void BeginResolve_HostName_Null ()\r
340                 {\r
341                         try {\r
342                                 Dns.BeginResolve ((string) null,\r
343                                         new AsyncCallback (ShouldntBeCalled),\r
344                                         null);\r
345                                 Assert.Fail ("#1");\r
346                         } catch (ArgumentNullException ex) {\r
347                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");\r
348                                 Assert.IsNull (ex.InnerException, "#3");\r
349                                 Assert.IsNotNull (ex.Message, "#4");\r
350                                 Assert.AreEqual ("hostName", ex.ParamName, "#5");\r
351                         }\r
352                 }\r
353 \r
354                 [Test]\r
355                 public void Resolve ()\r
356                 {\r
357                         SubTestResolve (site1Name);\r
358                         SubTestResolve (site2Name);\r
359                         SubTestResolve (site1Dot);\r
360                         SubTestResolve (site2Dot);\r
361                 }\r
362 \r
363                 void SubTestResolve (string addr)\r
364                 {\r
365                         IPHostEntry h = Dns.Resolve (addr);\r
366                         SubTestValidIPHostEntry (h);\r
367                 }\r
368 \r
369                 [Test]\r
370                 public void Resolve_HostName_Null ()\r
371                 {\r
372                         try {\r
373                                 Dns.Resolve ((string) null);\r
374                                 Assert.Fail ("#1");\r
375                         } catch (ArgumentNullException ex) {\r
376                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");\r
377                                 Assert.IsNull (ex.InnerException, "#3");\r
378                                 Assert.IsNotNull (ex.Message, "#4");\r
379                                 Assert.AreEqual ("hostName", ex.ParamName, "#5");\r
380                         }\r
381                 }\r
382 \r
383                 [Test] // BeginGetHostEntry (IPAddress, AsyncCallback, Object)\r
384                 public void BeginGetHostEntry1_Address_Null ()\r
385                 {\r
386                         try {\r
387                                 Dns.BeginGetHostEntry (\r
388                                         (IPAddress) null,\r
389                                         new AsyncCallback (ShouldntBeCalled),\r
390                                         null);\r
391                                 Assert.Fail ("#1");\r
392                         } catch (ArgumentNullException ex) {\r
393                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");\r
394                                 Assert.IsNull (ex.InnerException, "#3");\r
395                                 Assert.IsNotNull (ex.Message, "#4");\r
396                                 Assert.AreEqual ("address", ex.ParamName, "#5");\r
397                         }\r
398                 }\r
399 \r
400                 [Test] // BeginGetHostEntry (String, AsyncCallback, Object)\r
401                 public void BeginGetHostEntry2_HostNameOrAddress_Null ()\r
402                 {\r
403                         try {\r
404                                 Dns.BeginGetHostEntry (\r
405                                         (string) null,\r
406                                         new AsyncCallback (ShouldntBeCalled),\r
407                                         null);\r
408                                 Assert.Fail ("#1");\r
409                         } catch (ArgumentNullException ex) {\r
410                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");\r
411                                 Assert.IsNull (ex.InnerException, "#3");\r
412                                 Assert.IsNotNull (ex.Message, "#4");\r
413                                 Assert.AreEqual ("hostName", ex.ParamName, "#5");\r
414                         }\r
415                 }\r
416 \r
417                 [Test] // BeginGetHostEntry (String, AsyncCallback, Object)\r
418                 public void BeginGetHostEntry2_HostNameOrAddress_UnspecifiedAddress ()\r
419                 {\r
420                         // IPv4\r
421                         try {\r
422                                 Dns.BeginGetHostEntry (\r
423                                         "0.0.0.0",\r
424                                         new AsyncCallback (GetHostEntryCallback),\r
425                                         null);\r
426                                 Assert.Fail ("#1");\r
427                         } catch (ArgumentException ex) {\r
428                                 // IPv4 address 0.0.0.0 and IPv6 address ::0 are\r
429                                 // unspecified addresses that cannot be used as\r
430                                 // a target address\r
431                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");\r
432                                 Assert.IsNull (ex.InnerException, "#3");\r
433                                 Assert.IsNotNull (ex.Message, "#4");\r
434                                 Assert.AreEqual ("hostNameOrAddress", ex.ParamName, "#5");\r
435                         }\r
436 \r
437                         // IPv6\r
438                         try {\r
439                                 Dns.BeginGetHostEntry (\r
440                                         "::0",\r
441                                         new AsyncCallback (GetHostEntryCallback),\r
442                                         null);\r
443                                 Assert.Fail ("#1");\r
444                         } catch (ArgumentException ex) {\r
445                                 // IPv4 address 0.0.0.0 and IPv6 address ::0 are\r
446                                 // unspecified addresses that cannot be used as\r
447                                 // a target address\r
448                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#2");\r
449                                 Assert.IsNull (ex.InnerException, "#3");\r
450                                 Assert.IsNotNull (ex.Message, "#4");\r
451                                 Assert.AreEqual ("hostNameOrAddress", ex.ParamName, "#5");\r
452                         }\r
453                 }\r
454 \r
455                 void GetHostEntryCallback (IAsyncResult ar)\r
456                 {\r
457                         IPHostEntry hostEntry = Dns.EndGetHostEntry (ar);\r
458                         Assert.IsNotNull (hostEntry);\r
459                 }\r
460 \r
461                 [Test] // GetHostEntry (IPAddress)\r
462                 public void GetHostEntry1_Address_Null ()\r
463                 {\r
464                         try {\r
465                                 Dns.GetHostEntry ((IPAddress) null);\r
466                                 Assert.Fail ("#1");\r
467                         } catch (ArgumentNullException ex) {\r
468                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");\r
469                                 Assert.IsNull (ex.InnerException, "#3");\r
470                                 Assert.IsNotNull (ex.Message, "#4");\r
471                                 Assert.AreEqual ("address", ex.ParamName, "#5");\r
472                         }\r
473                 }\r
474 \r
475                 [Test] // GetHostEntry (String)\r
476                 public void GetHostEntry2 ()\r
477                 {\r
478                         Dns.GetHostEntry (site1Name); // hostname\r
479                         Dns.GetHostEntry (site1Dot); // IP address\r
480                 }\r
481 \r
482                 [Test] // GetHostEntry (String)\r
483                 public void GetHostEntry2_HostNameOrAddress_Null ()\r
484                 {\r
485                         try {\r
486                                 Dns.GetHostEntry ((string) null);\r
487                                 Assert.Fail ("#1");\r
488                         } catch (ArgumentNullException ex) {\r
489                                 Assert.AreEqual (typeof (ArgumentNullException), ex.GetType (), "#2");\r
490                                 Assert.IsNull (ex.InnerException, "#3");\r
491                                 Assert.IsNotNull (ex.Message, "#4");\r
492                                 Assert.AreEqual ("hostNameOrAddress", ex.ParamName, "#5");\r
493                         }\r
494                 }\r
495 \r
496                 [Test] // GetHostEntry (String)\r
497                 public void GetHostEntry2_HostNameOrAddress_UnspecifiedAddress ()\r
498                 {\r
499                         // IPv4\r
500                         try {\r
501                                 Dns.GetHostEntry ("0.0.0.0");\r
502                                 Assert.Fail ("#A1");\r
503                         } catch (ArgumentException ex) {\r
504                                 // IPv4 address 0.0.0.0 and IPv6 address ::0 are\r
505                                 // unspecified addresses that cannot be used as\r
506                                 // a target address\r
507                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#A2");\r
508                                 Assert.IsNull (ex.InnerException, "#A3");\r
509                                 Assert.IsNotNull (ex.Message, "#A4");\r
510                                 Assert.AreEqual ("hostNameOrAddress", ex.ParamName, "#A5");\r
511                         }\r
512 \r
513                         // IPv6\r
514                         try {\r
515                                 Dns.GetHostEntry ("::0");\r
516                                 Assert.Fail ("#B1");\r
517                         } catch (ArgumentException ex) {\r
518                                 // IPv4 address 0.0.0.0 and IPv6 address ::0 are\r
519                                 // unspecified addresses that cannot be used as\r
520                                 // a target address\r
521                                 Assert.AreEqual (typeof (ArgumentException), ex.GetType (), "#B2");\r
522                                 Assert.IsNull (ex.InnerException, "#B3");\r
523                                 Assert.IsNotNull (ex.Message, "#B4");\r
524                                 Assert.AreEqual ("hostNameOrAddress", ex.ParamName, "#B5");\r
525                         }\r
526                 }\r
527 \r
528                 void SubTestValidIPHostEntry (IPHostEntry h)\r
529                 {\r
530                         Assert.IsNotNull (h.HostName, "HostName not null");\r
531                         Assert.IsNotNull (h.AddressList, "AddressList not null");\r
532                         Assert.IsTrue (h.AddressList.Length > 0, "AddressList.Length");\r
533                 }\r
534 \r
535                 [Test]\r
536                 public void GetHostEntry_StringEmpty ()\r
537                 {\r
538                         Dns.GetHostEntry (string.Empty);\r
539                 }\r
540 \r
541                 /* This isn't used anymore, but could be useful for debugging\r
542                 static void printIPHostEntry(IPHostEntry h)\r
543                 {\r
544                         Console.WriteLine("----------------------------------------------------");\r
545                         Console.WriteLine("Host name:");\r
546                         Console.WriteLine(h.HostName);\r
547                         Console.WriteLine("IP addresses:");\r
548                         IPAddress[] list = h.AddressList;\r
549                         for(int i = 0; i < list.Length; ++i)\r
550                                 Console.WriteLine(list[i]);\r
551                         Console.WriteLine("Aliases:");\r
552                         string[] aliases = h.Aliases;\r
553                         for(int i = 0; i < aliases.Length; ++i)\r
554                                 Console.WriteLine(aliases[i]);\r
555                         Console.WriteLine("----------------------------------------------------");\r
556                 }\r
557                 */\r
558         }\r
559 }\r