Fix message printed for --skip-radiotap-header for non-radiotap packets.

If the encapsulation is WTAP_ENCAP_PER_PACKET, all we know about the
file is that it might not include radiotap packets and, if it does, it
also includes non-radiotap packets.

If it's *not* WTAP_ENCAP_PER_PACKET, properly report it
(wtap_file_type_subtype() returns the *file type* of the file, not the
*link-layer header type* - yes, that *happens* to work for a pcap file
with Ethernet packets, because the values of WTAP_ENCAP_ETHERNET and
WTAP_FILE_TYPE_SUBTYPE_PCAP both *happen* to be 1, but that's pure
luck).

While we're at it, test only once for --skip-radiotap-header and put
both tests inside that if.
This commit is contained in:
Guy Harris 2020-10-14 21:22:53 -07:00
parent baebbbce4d
commit 3f412284a2
1 changed files with 20 additions and 13 deletions

View File

@ -1532,20 +1532,27 @@ invalid_time:
wtap_file_type_subtype_string(wtap_file_type_subtype(wth)));
}
if (ignored_bytes != 0 && skip_radiotap == TRUE) {
fprintf(stderr, "editcap: can't skip radiotap headers and %d byte(s)\n", ignored_bytes);
fprintf(stderr, "editcap: at the start of packet at the same time\n");
ret = INVALID_OPTION;
goto clean_exit;
}
if (skip_radiotap) {
if (ignored_bytes != 0) {
fprintf(stderr, "editcap: can't skip radiotap headers and %d byte(s)\n", ignored_bytes);
fprintf(stderr, "editcap: at the start of packet at the same time\n");
ret = INVALID_OPTION;
goto clean_exit;
}
if (skip_radiotap == TRUE && wtap_file_encap(wth) != WTAP_ENCAP_IEEE_802_11_RADIOTAP) {
fprintf(stderr, "editcap: can't skip radiotap header because input file is incorrect\n");
fprintf(stderr, "editcap: expected '%s', input is '%s'\n",
wtap_encap_description(WTAP_ENCAP_IEEE_802_11_RADIOTAP),
wtap_encap_description(wtap_file_type_subtype(wth)));
ret = INVALID_OPTION;
goto clean_exit;
if (wtap_file_encap(wth) != WTAP_ENCAP_IEEE_802_11_RADIOTAP) {
fprintf(stderr, "editcap: can't skip radiotap header because input file has non-radiotap packets\n");
if (wtap_file_encap(wth) == WTAP_ENCAP_PER_PACKET) {
fprintf(stderr, "editcap: expected '%s', not all packets are necessarily that type\n",
wtap_encap_description(WTAP_ENCAP_IEEE_802_11_RADIOTAP));
} else {
fprintf(stderr, "editcap: expected '%s', packets are '%s'\n",
wtap_encap_description(WTAP_ENCAP_IEEE_802_11_RADIOTAP),
wtap_encap_description(wtap_file_encap(wth)));
}
ret = INVALID_OPTION;
goto clean_exit;
}
}
wtap_dump_params_init(&params, wth);