user3183586
user3183586

Reputation: 167

C# UdpClient ".Receive" only giving part of packet identified by wireshark

Basically my code is only capturing part of the UDP protocol packet when I need it to get all of it.

UdpClient listener = new UdpClient(43965);
IPEndPoint endpoint = new IPEndPoint(IPAddress.Any, 43965);

long count = 0;

while(1 == 1)
{
    if (listener.Available > 0)
    {
        byte[] data = listener.Receive(ref endpoint);
        Console.WriteLine(Encoding.ASCII.GetString(data));
    }
}

I'm getting (highlighted):

enter image description here

I should be getting:

enter image description here

Upvotes: 0

Views: 177

Answers (1)

user862787
user862787

Reputation:

As Visual Vincent said, "MICS" is followed by 0x10 and then 0x00, so if you treat that part of the packet as a null-terminated string, it's "MICS\x10".

As you've discovered, you have to look at the raw bytes to find the data after it.

The data before it is the UDP header, the IP header, and the Ethernet header. You don't get those headers when reading from a UDP socket, you just get the UDP payload.

Upvotes: 1

Related Questions