你如何在C#中的原始TCP数据包? [英] How do you get raw TCP packet in C#?

查看:500
本文介绍了你如何在C#中的原始TCP数据包?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我要接收的原始TCP数据包,然后将其用同样的工作负载寄回。

I want to received raw TCP packet and then send it back with same workload.

这应该是这个样子:

void OnPacketReceived(TcpPacket p)
{
    byte [] body = p.GetBody();
}

注:我所需要的TCP数据包,而不是以太网帧

NOTE : I need the TCP packet and not the Ethernet frame.

推荐答案

如果您实现的套接字原始套接字,您可以访问整个数据包(事实上必须处理一切有关数据包自己)。

If you implement the socket as a raw socket, you have access to the whole packet (and in fact must handle everything about the packet yourself).

创建套接字时使用SocketType.Raw和ProtocolType.Raw。

Use SocketType.Raw and ProtocolType.Raw when creating the socket.

要知道,你将不得不处理TCP的详细信息,如果您实现您的插座这样的。

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

有关引用,这里是MSDN文档关于Socket类: <一href="http://msdn.microsoft.com/en-us/library/system.net.sockets.socket.aspx">http://msdn.microsoft.com/en-us/library/system.net.sockets.socket.aspx

For reference, here is the MSDN documentation about the Socket class: http://msdn.microsoft.com/en-us/library/system.net.sockets.socket.aspx

这篇关于你如何在C#中的原始TCP数据包?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆