Search code examples
c#tcpethernet

How can i get CRC from received data by TCP?


I need to send Ethernet packets from one device to another by Ethernet protocol. After some research i decide to use TCP\IP protocol. I created TCP server and TCP client that communicating with each other. I used TcpClient and TcpListener classes for that. It works fine, but i have some questions:

  1. I need to check CRC from received message and compare it with manually calculated on the listener side somehow. How can i do this? How can i get this CRC from received message? All i got it's an exact message that i send from client.
  2. How in common to see my message in this packet format? All that i see at the Listener side it's "Data" field, but i wanna see "raw" with headers, CRC(FCS) etc, like at that picture.

Solution

  • Svemir, you can check SO question here about raw communication using Sockets in C#.

    Here is a good SuperUser explanation of the various layers. If you go with the raw method of the Sockets, then you are in for some hard times

    you're going to have to handle the details of TCP if you implement your socket this way.

    From Microsoft documentation on SocketType.Raw

    Supports access to the underlying transport protocol. Using Raw, you can communicate using protocols like Internet Control Message Protocol (ProtocolType.Icmp) and Internet Group Management Protocol (ProtocolType.Igmp). Your application must provide a complete IP header when sending. Received datagrams return with the IP header and options intact

    From Microsoft documentation on SocketType.Stream

    Supports reliable, two-way, connection-based byte streams without the duplication of data and without preservation of boundaries. A Socket of this type communicates with a single peer and requires a remote host connection before communication can begin. Stream uses the Transmission Control Protocol (ProtocolType.Tcp) and the AddressFamily.InterNetwork address family.

    Which basically means that everything is handled for you and that you can only have access to what the SuperUser link refers to as the letter contents.