当我嗅探 ipv6 地址时,我只能得到传输层标头。但是,我在嗅探 ipv4 地址时得到了网络层标头。
这是我的设置:
socket = new System.Net.Sockets.Socket(AddressFamily.InterNetworkV6, SocketType.Raw, ProtocolType.IP);
byteBufferData = new byte[1024 * 64];
socket.Bind(new IPEndPoint(IP, 0)); // a certain address
socket.SetSocketOption(SocketOptionLevel.IPv6, SocketOptionName.HeaderIncluded, true);
byte[] byteTrue = new byte[4] { 1, 0, 0, 0 };
byte[] byteOut = new byte[4];
socket.IOControl(IOControlCode.ReceiveAll, byteTrue, byteOut);
socket.BeginReceive(byteBufferData, 0, byteBufferData.Length, SocketFlags.None, new AsyncCallback(this.ReceiveData), null);
我监听ipv4地址时,参数分别是
AddressFamily.InterNetwork
和SocketOptionLevel.IP