问题
Following up on my question about pcap file creation, I now would like to simulate the saving of a full UDP packet, including the Ethernet, IP and UDP headers.
Which DLT_XXX type should I use? I believe pcap_dump() skips the Ethernet header when using pcap_open_dead(DLT_RAW, 65535).
回答1:
If you want to simulate a full UDP-over-IP-over-Ethernet packet, you want DLT_EN10MB
(the "10MB" in the name is historical; DLT_EN10MB
really means "all types of Ethernet").
(DLT_RAW
is for packets where the lowest-level headers are for IP; it doesn't skip the Ethernet header, it means that you don't have to provide an Ethernet header and, in fact, it requires that you don't provide one - if you do provide one, it'll be written to the file, which will confuse programs reading the file, as they'll expect the packets to begin with an IPv4 or IPv6 header, not an Ethernet header.)
来源:https://stackoverflow.com/questions/10114739/pcap-open-dead-to-simulate-full-udp-packets-capture