如何从 TCP 接收到的数据中获取 CRC?
How can i get CRC from received data by TCP?
我需要通过以太网协议将以太网数据包从一台设备发送到另一台设备。经过一些研究,我决定使用 TCP\IP 协议。我创建了相互通信的 TCP 服务器和 TCP 客户端。为此,我使用了 TcpClient 和 TcpListener 类。它工作正常,但我有一些问题:
- 我需要从收到的消息中检查 CRC,并将其与以某种方式在侦听器端手动计算的进行比较。我怎样才能做到这一点?我怎样才能从收到的消息中得到这个 CRC?我得到的只是我从客户发送的确切消息。
- 如何以这种数据包格式查看我的消息?我在 Listener 端看到的是 "Data" 字段,但我想看到 "raw" 和 headers、CRC(FCS) 等,
like at that picture.
Svemir,您可以查看 SO question here 关于在 C# 中使用套接字的原始通信。
Here is a good SuperUser explanation of the various layers。如果你使用套接字的原始方法,那么你会遇到一些困难
you're going to have to handle the details of TCP if you implement your socket this way.
来自 Microsoft 关于 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
来自 SocketType.Stream
上的 Microsoft 文档
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.
这基本上意味着一切都为您处理,您只能访问超级用户 link 所指的信件内容。
我需要通过以太网协议将以太网数据包从一台设备发送到另一台设备。经过一些研究,我决定使用 TCP\IP 协议。我创建了相互通信的 TCP 服务器和 TCP 客户端。为此,我使用了 TcpClient 和 TcpListener 类。它工作正常,但我有一些问题:
- 我需要从收到的消息中检查 CRC,并将其与以某种方式在侦听器端手动计算的进行比较。我怎样才能做到这一点?我怎样才能从收到的消息中得到这个 CRC?我得到的只是我从客户发送的确切消息。
- 如何以这种数据包格式查看我的消息?我在 Listener 端看到的是 "Data" 字段,但我想看到 "raw" 和 headers、CRC(FCS) 等, like at that picture.
Svemir,您可以查看 SO question here 关于在 C# 中使用套接字的原始通信。
Here is a good SuperUser explanation of the various layers。如果你使用套接字的原始方法,那么你会遇到一些困难
you're going to have to handle the details of TCP if you implement your socket this way.
来自 Microsoft 关于 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
来自 SocketType.Stream
上的 Microsoft 文档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.
这基本上意味着一切都为您处理,您只能访问超级用户 link 所指的信件内容。