Main Site Documentation

Socket.RemoteEndPoint only zero values


#1

In 4.3 R5 RemoteEndPoint, both address and port number are zero. In 4.2 the address was also zero but port number was set properly. Is this a bug?


var serverSocket = new Socket(AddressFamily.InterNetwork, SocketType.Dgram, ProtocolType.Udp);
EndPoint localEndPoint = new IPEndPoint(IPAddress.GetDefaultLocalAddress(), 53);
serverSocket.Bind(localEndPoint);
if (serverSocket.Poll(-1, SelectMode.SelectRead))
{
    // Remote endpoint should be available here, but is zero!
}


#2

Yes, you are right. address and port number are part of the ip header. They seem not to be transfered to the socket instance. A listening / accept socket on a TCP connection do receive the endpoint address / port number


#3

Have you tested in the emulator? On non GHI device?


#4

@ andre.m I hope it can be solved by GHI in a short term.


#5

@ Gus - I haven’t tested it on a non-ghi device. But its i good idea to get one and also test in the emulator. Keep you posted with the results


#6

@ Gus It seems that by design the remote endpoint is not transferred to the socket instance in datagram mode. Although the remote endpoint Port number was available in 4.2 and set to zero in 4.3. This is the case in both GHI and Mountaineer hardware.

Not a big deal to switch to RAW sockets and read the endpoint IP and Port number from the UDP header, however another problem arise.

  1. setup raw socket
  2. bind the raw socket to port 53
    So good so far.
    DNS requests perfectly arrive and can be processed and respond to.

BUT when a client sends a dns request (for example by entering a hostname in a browser)
the internal network stack sends an ICMP message to the client that the port (53) is unreachable.

Can this considered to be a bug?

The DNS server code is pure C#. NET and works smooth on a PC.

UPDATE: Bind to port 0 seems to solve the problem :slight_smile: