Skip to main content

You are not logged in. Your edit will be placed in a queue until it is peer reviewed.

We welcome edits that make the post easier to understand and more valuable for readers. Because community members review edits, please try to make the post substantially better than how you found it, for example, by fixing grammar or adding additional resources and hyperlinks.

4
  • Thank you for replying. You're assuming I'm using libpcap..... I'm not. And how do NIC drivers know how many bytes given the PCAP header doesn't exist in real wire traffic? Commented Jul 13, 2024 at 22:36
  • you should be using libpcap, is what my answer says. Also, you already are (in tcpdump), you just don't realize. The NIC driver knows because the card includes that info in however it gets data from device to host memory. (usually, these are ring buffers of packet buffer descriptors, and the packet buffer descriptors are what you'd call a header here). Thing is, in a driver, you're not trying to put the bytes from packets one after the other in a file. The packets are separate to begin with in the driver. Think of it like this: Commented Jul 14, 2024 at 9:03
  • When I speak to you clearly (and assuming your hearing works well), you know where one word starts end ends, and can infer the length of words simply as the thing between the gaps between words. Now, remove all the gaps from my speech (or remove all the spaces from written text), and do the understanding again. That's going to be ambiguous! Worse if what I speak aren't words but I just dictate numbers. You lose all usefulness if you write these down without headers; 102 1003 are simple not the same numbers as 10 21003. So, if you write things to a file, you'll need headers. Like it or not. Commented Jul 14, 2024 at 9:07
  • And now, I frankly don't care about how your headers look, but seeing that the usual interface to capturing packets on most operating systems is pcap, and pcap comes with its headers, and it comes with its header interpreter library, it would be pretty unnecessarily complex to use any other header format. Commented Jul 14, 2024 at 9:09