积极答复者
socket.BeginReceive问题

问题
-
我用socket.BeginReceive去抓包,为什么抓回来的包不全呢?我的代码如下
public void Rec()
{
IAsyncResult ar = ygh_icmp.BeginReceive(receive, 0, 4096, SocketFlags.None, new AsyncCallback(Socket_rec), this);//ygh_icmp是socket类
}
public void Socket_rec(IAsyncResult ar)
{
ygh_icmp.EndReceive(ar);
RoutIp = "";
string ds = "";
byte type = 0;
if (receive[9] == 0x1)//如果是ICMP包则获取,当我的包TTL足够大时,我可以收到对方返回的ICMP,但是当TTL等于1的时候网关返回的ICMP却收不到,大虾帮帮忙啊!嘿嘿
{
Array.Copy(receive, 12, dest, 0, 4);
for (int i = 0; i < 4; i++)
{
if (i != 3)
RoutIp = RoutIp + dest[i].ToString() + ".";
else
RoutIp = RoutIp + dest[i].ToString();
}
Array.Copy(receive, 16, dest, 0, 4);
for (int i = 0; i < 4; i++)
{
if (i != 3)
ds = ds + dest[i].ToString() + ".";
else
ds = ds + dest[i].ToString();
}
type = receive[9];
result = "源地址: " + RoutIp + " 目的地址是: " + ds + " 协议类型:" + type.ToString();
if (RoutIp != textBox2.Text)
{
// listBox1.Items.Add(RoutIp);
list = new showlist(showinlist);
listBox1.Invoke(list);
// MessageBox.Show(result);
Rec();
}
else
listBox1.Invoke(list);//委托显示结果
}
else
Rec();
}
银国徽
答案
-
你好:
你可以尝试使用SharpPCap在C#下进行网络抓包
http://www.cnblogs.com/armyao/archive/2010/11/05/1870162.html
http://www.tamirgal.com/home/default.aspx
http://www.cnblogs.com/billmo/archive/2008/11/09/1329972.html希望对你有所帮助。
I am here!- 已标记为答案 执着追求 2010年11月12日 8:47
全部回复
-
你好:
你可以尝试使用SharpPCap在C#下进行网络抓包
http://www.cnblogs.com/armyao/archive/2010/11/05/1870162.html
http://www.tamirgal.com/home/default.aspx
http://www.cnblogs.com/billmo/archive/2008/11/09/1329972.html希望对你有所帮助。
I am here!- 已标记为答案 执着追求 2010年11月12日 8:47
-
错误 1 “SharpPcap.PcapDevice.SetFilter(string)”不可访问,因为它受保护级别限制 F:\Programs\VS2008\VS2008工程项目\CSharpcap\CSharpcap\Form1.cs 49 20 CSharpcap,我看了一下SharpPcap的对象关系图,发现PcapDevice.SetFilter(string)是Protected,而LivePcapDevice是继承PcapDevice类的,因此LivePcapDevice对象应该可以公开使用SetFilter(string),为什么还是说受保护级别限制呢?
银国徽