Bug 315818 (MONO63265) - When the AddressList for a machine is requested only loopback address is returned
Summary: When the AddressList for a machine is requested only loopback address is retu...
Status: RESOLVED FIXED
Alias: MONO63265
Product: Mono: Runtime
Classification: Mono
Component: misc (show other bugs)
Version: unspecified
Hardware: Other All
: P3 - Medium : Normal
Target Milestone: ---
Assignee: Gonzalo Paniagua Javier
QA Contact: Mono Bugs
URL:
Whiteboard:
Keywords: blocking
Depends on:
Blocks:
 
Reported: 2004-08-18 03:11 UTC by Paco Martinez
Modified: 2007-09-15 21:24 UTC (History)
0 users

See Also:
Found By: ---
Services Priority:
Business Priority:
Blocker: ---
Marketing QA Status: ---
IT Deployment: ---


Attachments

Note You need to log in before you can comment on or make changes to this bug.
Description Thomas Wiest 2007-09-15 18:51:20 UTC


---- Reported by martinf@mfconsulting.com 2004-08-17 20:11:34 MST ----

Description of Problem:
When the AddressList for a machine is requested using Dns.GetHostByName
only the loopback address is returned.

Given the following console application:

using System;
using System.Net;

class Class1
{
	[STAThread]
	static void Main(string[] args)	
	{
		IPAddress[] iparr;
		int i = 0;
		
		iparr = Dns.GetHostByName(
			Dns.GetHostName()
			).AddressList;

		foreach (IPAddress ipA in iparr)	
		{
			Console.WriteLine("IP for Interface {0}: {1}",
				i++, ipA.ToString());
		}
	}
}

Actual Results:
IP for Interface 0: 127.0.0.2

Expected Results:
IP for Interface 0: 10.20.70.44
IP for Interface 1: 10.20.70.43

How often does this happen? 
Every time this code is executed in Linux

Additional Information:
The expected results are achieved when the code is compiled and run using
the MS .NET Framework 1.1 SDK and with Mono 1.0.1 for Win32.  However, the
actual result is what is obtained when ran in Linux using Mono 1.0



---- Additional Comments From martinf@mfconsulting.com 2004-08-17 20:14:00 MST ----

Forgot to include Calvin



---- Additional Comments From dick@ximian.com 2004-08-18 07:00:37 MST ----

Are you sure your DNS setup is correct?  Check that Dns.GetHostName()
isn't returning "localhost".

See https://bugzilla.novell.com/show_bug.cgi?id=MONO62389 58273 61164 and 60070 for similar examples.

Your code works for me - I substituted "www.microsoft.com" for
Dns.GetHostName() (my machines only have one name) and got:

:; mono 63265.exe
IP for Interface 0: 207.46.144.222
IP for Interface 1: 207.46.144.188
IP for Interface 2: 207.46.250.222
IP for Interface 3: 207.46.245.92
IP for Interface 4: 207.46.156.156
IP for Interface 5: 207.46.156.252
IP for Interface 6: 207.46.250.252
IP for Interface 7: 207.46.244.188




---- Additional Comments From gonzalo@ximian.com 2004-08-18 15:50:13 MST ----

Dick, i think the issue here is that MS returns all the local
interfaces IP addresses and we're not doing that.



---- Additional Comments From dick@ximian.com 2004-08-19 06:57:30 MST ----

The code is asking for a DNS lookup.  DNS.GetHostName() returns a
single string.

DNS.GetHostByName() returns as many results as are returned by the DNS
query.  Nothing in the documentation states that if the hostname is
the local machine, to iterate the interfaces too.

Hence my assertion that this is a configuration problem.  Does Paco's
windows machine have multiple A entries in the DNS database? (Bearing
in mind that they might have been added automatically by a DHCP server.)

And I still think the loopback address is being printed because on the
linux machine DNS.GetHostName() is returning "localhost".




---- Additional Comments From gonzalo@ximian.com 2004-08-20 15:45:18 MST ----

Curious:

C:\gonzalo\tests>.\if.exe
NOVELL-FVUVPGKV
IP for Interface 0: 164.99.120.79

And if I unplug the network cable:
C:\gonzalo\tests>.\if.exe
NOVELL-FVUVPGKV
IP for Interface 0: 164.99.120.79

NOVELL-FVUVPGKV is the name of this windows machine.



---- Additional Comments From gonzalo@ximian.com 2004-08-20 15:45:50 MST ----

Ugh, sorry, when i unplug the cable, i get a 127.0.0.1



---- Additional Comments From dick@ximian.com 2004-08-21 08:20:42 MST ----

And what happens if you try and ping NOVELL-FVUVPGKV with the cable
plugged in and unplugged? (ie do a dns lookup from the command line.)



---- Additional Comments From gonzalo@ximian.com 2004-08-21 11:48:33 MST ----

In both cases it works. With the cable connected, it says 'Reply from
164.99.120.79'. Without it, it's 127.0.0.1 the address that replies.



---- Additional Comments From dick@ximian.com 2004-08-21 12:54:20 MST ----

Then in that case it looks like the test code here is just doing a
straight DNS lookup irrespective of what the interface is set to, and
windows is setting the DNS info when the interface state changes.



---- Additional Comments From gonzalo@ximian.com 2004-08-22 18:12:54 MST ----

ok, seems like it's not a bug.



---- Additional Comments From miguel@ximian.com 2005-01-18 20:54:49 MST ----

We could handle the special case where the hostname passed to the 
GetHostByName is the result of `gethostname'.

If so, we could return all of the IPAddresses associated with the
hostname, all of the interfaces on the system.  

This will be highly unportable code though.

Am just reopening to keep this issue around, our behavior is clearly
correct;  but I can see why people will be using this API.

The only portable thing we can do on Unix to find out the IP 
address being used is to connect to a system; and then query the
credentials to extract the ip address that the kernel used to
connect (this is what FTP clients do when they send the PORT command)



---- Additional Comments From dick@ximian.com 2005-01-19 11:49:03 MST ----

Getting the interface list can be done reasonably portably on unixy
machines with a SIOCGIFCONF ioctl.  It has issues with buffer sizes
when the buffer passed to the kernel isnt big enough - some systems
return EINVAL, some just give as much info as there is space.



---- Additional Comments From dick@ximian.com 2005-01-20 09:47:10 MST ----

*** https://bugzilla.novell.com/show_bug.cgi?id=MONO64626 has been marked as a duplicate of this bug. ***



---- Additional Comments From gonzalo@ximian.com 2005-05-30 07:05:04 MST ----

Fixed in svn HEAD r45187.

This bug blocked bug(s) 54234.

Unknown bug field "cf_op_sys_details" encountered while moving bug
   <cf_op_sys_details>tested on Windows XP, Linux SuSe 9.0</cf_op_sys_details>