0

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.

  • What operating system? Maybe try `ProtocolType.IPv6` on the first line? Also `socket.Bind(new IPEndPoint(IPAddress.Any, 0));` – Charlieface Mar 19 '23 at 04:15
  • @Charlieface like [this problem](https://stackoverflow.com/a/65532858/10965675), after I changing the ```ProtocolType``` to ```ProtocolType.IPv6```, i can not save a packet anymore. And according to jdweng's comments, may be it is impossible to get the ipv6 header with ```Net`` library at all? – Zhao Tianchang Mar 19 '23 at 07:46
  • The .NET library is a fairly bare wrapper over Winsock, so if you can do it in Winsock you should be able to do it in .NET. – Charlieface Mar 19 '23 at 21:22

0 Answers0