我用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();
}
银国徽