JD.
JD.

Reputation: 15551

Getting invalid pointer address when binding socket in C#?

On one of our teams desktop, we are getting a strange error when running this code:

IPAddress ipaddress = IPAddress.Parse(sIPDaddress);
var endpoint = new IPEndPoint(ipaddress, m_iPort);
listener.Bind(endpoint);
listener.Blocking = true;
listener.Listen(-1);

We are getting the following 10014 error on the bind command:

WSAEFAULT 10014 Bad address. The system detected an invalid pointer address in attempting to use a pointer argument of a call. This error occurs if an application passes an invalid pointer value, or if the length of the buffer is too small. For instance, if the length of an argument, which is a sockaddr structure, is smaller than the sizeof(sockaddr).

We initially thought it was a network issue but my laptop running the same code works when connected to his network port.

The desktop is ip4 enabled and this is the only machine we are having this issue. We even changed the network card but the error still exists.

Any ideas where to look?

Upvotes: 4

Views: 2218

Answers (1)

JD.
JD.

Reputation: 15551

I found a line above the code above:

Socket listener = new Socket(0, SocketType.Stream, ProtocolType.Tcp);

I switched this to:

Socket listener = new Socket(AddressFamily.InterNetwork, 
                              SocketType.Stream, ProtocolType.Tcp);

and it worked.

Still not sure why this happened on one the developer machines but not on the others.

What I did notice was when I did ipconfig on a working development machine there is a Link-local IPV6 address shown. However on the non-working machine there is no entry for a Link-local IPV6 address. Not sure if this is related.

Upvotes: 2

Related Questions