Why does LocalEndpoint = 0.0.0.0 at this point? According to the docs it should be the appropiate address selected by the system. Note: This only occurrs on some machines. Most machines return the IP Address I would expect. Is this a bug in .NET?
using (Socket s = new Socket(AddressFamily.InterNetwork,
SocketType.Stream, ProtocolType.Tcp))
{
Console.WriteLine("Connecting");
s.Connect("www.google.com", 80);
Console.WriteLine("Connected OK");
s.Send(new byte[] { 1 });
Console.WriteLine("Sent Byte OK");
Console.WriteLine("Local EndPoint = " +
s.LocalEndPoint.ToString());
}
//Local EndPoint = 0.0.0.0
I have also tried doing
s.Bind(new IPEndPoint(IPAddress.Any, 0));
directly after creating the socket and it made no difference. The "problem" machine always returns 0.0.0.0.
Here is the result of an ipconfig /all
Windows IP Configuration
Host Name . . . . . . . . . . . . : andrepc
Primary Dns Suffix . . . . . . . :
Node Type . . . . . . . . . . . . : Unknown
IP Routing Enabled. . . . . . . . : No
WINS Proxy Enabled. . . . . . . . : No
Ethernet adapter Local Area Connection 2:
Media State . . . . . . . . . . . : Media disconnected
Description . . . . . . . . . . . : VIA VT6105 Rhine Fast Ethernet Adapter
Physical Address. . . . . . . . . : 00-30-18-67-A0-EB
Ethernet adapter Local Area Connection:
Connection-specific DNS Suffix . :
Description . . . . . . . . . . . : Realtek RTL8029 PCI Ethernet Adapter
Physical Address. . . . . . . . . : 00-C0-DF-E7-C9-5D
Dhcp Enabled. . . . . . . . . . . : Yes
Autoconfiguration Enabled . . . . : Yes
IP Address. . . . . . . . . . . . : 10.0.0.6
Subnet Mask . . . . . . . . . . . : 255.0.0.0
Default Gateway . . . . . . . . . : 10.0.0.2
DHCP Server . . . . . . . . . . . : 10.0.0.2
DNS Servers . . . . . . . . . . . : 10.0.0.2
Lease Obtained. . . . . . . . . . : Wednesday, May 20, 2009 5:39:06 PM
Lease Expires . . . . . . . . . . : Thursday, May 21, 2009 5:39:06 PM
10.0.0.6 Would be the IP I would expect as a result.