When I sniffing to ipv6 addresses, I can only get transport layer headers. However, I got network layer headers when sniffing to ipv4 addresses.
here are my settings:
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);
When I listening to ipv4 addresses, the parameters are AddressFamily.InterNetwork
and SocketOptionLevel.IP
respectively.