Only use "libpcap" to refer to the library.

For file formats, say "pcap/pcapng" or "pcap and pcapng" instead; this
code handles both formats.  Use just "pcap_" in structure types.

Change-Id: I2c0e096855ac3736bbfd72480ed4221b3a2f25d1
Reviewed-on: https://code.wireshark.org/review/29835
Reviewed-by: Guy Harris <guy@alum.mit.edu>
This commit is contained in:
Guy Harris 2018-09-25 17:33:31 -07:00
parent c9f19e4af7
commit 5773f2bbca
1 changed files with 50 additions and 48 deletions

View File

@ -467,8 +467,8 @@ static const struct {
/*
* To repeat:
*
* If you need a new encapsulation type for libpcap files, do
* *N*O*T* use *ANY* of the values listed here! I.e., do *NOT*
* If you need a new encapsulation type for pcap and pcapng files,
* do *N*O*T* use *ANY* of the values listed here! I.e., do *NOT*
* add a new encapsulation type by changing an existing entry;
* leave the existing entries alone.
*
@ -492,10 +492,10 @@ static const struct {
*/
/*
* 11 is DLT_ATM_RFC1483 on most platforms; the only libpcaps I've
* seen that define anything other than DLT_ATM_RFC1483 as 11 are
* the BSD/OS one, which defines DLT_FR as 11. We handle it as
* Frame Relay on BSD/OS and LLC-encapsulated ATM on all other
* 11 is DLT_ATM_RFC1483 on most platforms; the only version of
* libpcap I've seen that define anything other than DLT_ATM_RFC1483
* as 11 is the BSD/OS one, which defines DLT_FR as 11. We handle
* it as Frame Relay on BSD/OS and LLC-encapsulated ATM on all other
* platforms.
*/
#if defined(__bsdi__) /* BSD/OS */
@ -623,24 +623,25 @@ static const struct {
* 18 is DLT_CIP in SuSE 6.3 libpcap; if it's the same as the
* DLT_CIP of 16 that the Alexey Kuznetzov patches for
* libpcap/tcpdump define, it's WTAP_ENCAP_LINUX_ATM_CLIP.
* I've not found any libpcap that uses it for any other purpose -
* hopefully nobody will do so in the future.
* I've not found any version of libpcap that uses it for any
* other purpose - hopefully nobody will do so in the future.
*/
{ 18, WTAP_ENCAP_LINUX_ATM_CLIP },
/*
* 19 is DLT_ATM_CLIP in the libpcap/tcpdump patches in the
* recent versions I've seen of the Linux ATM distribution;
* I've not yet found any libpcap that uses it for any other
* purpose - hopefully nobody will do so in the future.
* I've not yet found any version of libpcap file that uses it
* for any other purpose - hopefully nobody will do so in
* the future.
*/
{ 19, WTAP_ENCAP_LINUX_ATM_CLIP },
/*
* To repeat:
*
* If you need a new encapsulation type for libpcap files, do
* *N*O*T* use *ANY* of the values listed here! I.e., do *NOT*
* If you need a new encapsulation type for pcap and pcapng files,
* do *N*O*T* use *ANY* of the values listed here! I.e., do *NOT*
* add a new encapsulation type by changing an existing entry;
* leave the existing entries alone.
*
@ -1007,7 +1008,7 @@ pcap_read_irda_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header,
if (pntoh16(&irda_phdr[IRDA_SLL_PROTOCOL_OFFSET]) != 0x0017) {
*err = WTAP_ERR_BAD_FILE;
if (err_info != NULL)
*err_info = g_strdup("libpcap: IrDA capture has a packet with an invalid sll_protocol field");
*err_info = g_strdup("pcap/pcapng: IrDA capture has a packet with an invalid sll_protocol field");
return FALSE;
}
@ -1043,7 +1044,7 @@ pcap_read_lapd_pseudoheader(FILE_T fh, union wtap_pseudo_header *pseudo_header,
if (pntoh16(&lapd_phdr[LAPD_SLL_PROTOCOL_OFFSET]) != ETH_P_LAPD) {
*err = WTAP_ERR_BAD_FILE;
if (err_info != NULL)
*err_info = g_strdup("libpcap: LAPD capture has a packet with an invalid sll_protocol field");
*err_info = g_strdup("pcap/pcapng: LAPD capture has a packet with an invalid sll_protocol field");
return FALSE;
}
@ -1442,7 +1443,7 @@ pcap_byteswap_nflog_pseudoheader(wtap_rec *rec, guint8 *pd)
* Pseudo-header at the beginning of DLT_BLUETOOTH_HCI_H4_WITH_PHDR frames.
* Values in network byte order.
*/
struct libpcap_bt_phdr {
struct pcap_bt_phdr {
guint32 direction; /* Bit 0 hold the frame direction. */
};
@ -1453,9 +1454,9 @@ static gboolean
pcap_read_bt_pseudoheader(FILE_T fh,
union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
{
struct libpcap_bt_phdr phdr;
struct pcap_bt_phdr phdr;
if (!wtap_read_bytes(fh, &phdr, sizeof (struct libpcap_bt_phdr),
if (!wtap_read_bytes(fh, &phdr, sizeof (struct pcap_bt_phdr),
err, err_info))
return FALSE;
pseudo_header->p2p.sent = ((g_ntohl(phdr.direction) & LIBPCAP_BT_PHDR_RECV) == 0)? TRUE: FALSE;
@ -1466,7 +1467,7 @@ pcap_read_bt_pseudoheader(FILE_T fh,
* Pseudo-header at the beginning of DLT_BLUETOOTH_LINUX_MONITOR frames.
* Values in network byte order.
*/
struct libpcap_bt_monitor_phdr {
struct pcap_bt_monitor_phdr {
guint16 adapter_id;
guint16 opcode;
};
@ -1475,9 +1476,9 @@ static gboolean
pcap_read_bt_monitor_pseudoheader(FILE_T fh,
union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
{
struct libpcap_bt_monitor_phdr phdr;
struct pcap_bt_monitor_phdr phdr;
if (!wtap_read_bytes(fh, &phdr, sizeof (struct libpcap_bt_monitor_phdr),
if (!wtap_read_bytes(fh, &phdr, sizeof (struct pcap_bt_monitor_phdr),
err, err_info))
return FALSE;
@ -1502,7 +1503,7 @@ pcap_read_llcp_pseudoheader(FILE_T fh,
/*
* Pseudo-header at the beginning of DLT_PPP_WITH_DIR frames.
*/
struct libpcap_ppp_phdr {
struct pcap_ppp_phdr {
guint8 direction;
};
@ -1513,9 +1514,9 @@ static gboolean
pcap_read_ppp_pseudoheader(FILE_T fh,
union wtap_pseudo_header *pseudo_header, int *err, gchar **err_info)
{
struct libpcap_ppp_phdr phdr;
struct pcap_ppp_phdr phdr;
if (!wtap_read_bytes(fh, &phdr, sizeof (struct libpcap_ppp_phdr),
if (!wtap_read_bytes(fh, &phdr, sizeof (struct pcap_ppp_phdr),
err, err_info))
return FALSE;
pseudo_header->p2p.sent = (phdr.direction == LIBPCAP_PPP_PHDR_SENT) ? TRUE: FALSE;
@ -1666,7 +1667,7 @@ pcap_process_pseudo_header(FILE_T fh, int file_type, int wtap_encap,
* have a pseudo-header.
*/
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup_printf("pcap: Nokia IPSO ATM file has a %u-byte packet, too small to have even an ATM pseudo-header",
*err_info = g_strdup_printf("pcap/pcapng: Nokia IPSO ATM file has a %u-byte packet, too small to have even an ATM pseudo-header",
packet_size);
return -1;
}
@ -1685,7 +1686,7 @@ pcap_process_pseudo_header(FILE_T fh, int file_type, int wtap_encap,
* have a pseudo-header.
*/
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup_printf("pcap: SunATM file has a %u-byte packet, too small to have even an ATM pseudo-header",
*err_info = g_strdup_printf("pcap/pcapng: SunATM file has a %u-byte packet, too small to have even an ATM pseudo-header",
packet_size);
return -1;
}
@ -1738,7 +1739,7 @@ pcap_process_pseudo_header(FILE_T fh, int file_type, int wtap_encap,
* have a pseudo-header.
*/
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup_printf("pcap: IrDA file has a %u-byte packet, too small to have even an IrDA pseudo-header",
*err_info = g_strdup_printf("pcap/pcapng: IrDA file has a %u-byte packet, too small to have even an IrDA pseudo-header",
packet_size);
return -1;
}
@ -1756,7 +1757,7 @@ pcap_process_pseudo_header(FILE_T fh, int file_type, int wtap_encap,
* have a pseudo-header.
*/
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup_printf("pcap: MTP2 file has a %u-byte packet, too small to have even an MTP2 pseudo-header",
*err_info = g_strdup_printf("pcap/pcapng: MTP2 file has a %u-byte packet, too small to have even an MTP2 pseudo-header",
packet_size);
return -1;
}
@ -1774,7 +1775,7 @@ pcap_process_pseudo_header(FILE_T fh, int file_type, int wtap_encap,
* have a pseudo-header.
*/
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup_printf("pcap: LAPD file has a %u-byte packet, too small to have even a LAPD pseudo-header",
*err_info = g_strdup_printf("pcap/pcapng: LAPD file has a %u-byte packet, too small to have even a LAPD pseudo-header",
packet_size);
return -1;
}
@ -1792,7 +1793,7 @@ pcap_process_pseudo_header(FILE_T fh, int file_type, int wtap_encap,
* have a pseudo-header.
*/
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup_printf("pcap: SITA file has a %u-byte packet, too small to have even a SITA pseudo-header",
*err_info = g_strdup_printf("pcap/pcapng: SITA file has a %u-byte packet, too small to have even a SITA pseudo-header",
packet_size);
return -1;
}
@ -1809,13 +1810,13 @@ pcap_process_pseudo_header(FILE_T fh, int file_type, int wtap_encap,
break;
case WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR:
if (packet_size < sizeof (struct libpcap_bt_phdr)) {
if (packet_size < sizeof (struct pcap_bt_phdr)) {
/*
* Uh-oh, the packet isn't big enough to even
* have a pseudo-header.
*/
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup_printf("pcap: libpcap bluetooth file has a %u-byte packet, too small to have even a pseudo-header",
*err_info = g_strdup_printf("pcap/pcapng: Bluetooth file has a %u-byte packet, too small to have even a pseudo-header",
packet_size);
return -1;
}
@ -1823,17 +1824,17 @@ pcap_process_pseudo_header(FILE_T fh, int file_type, int wtap_encap,
&rec->rec_header.packet_header.pseudo_header, err, err_info))
return -1; /* Read error */
phdr_len = (int)sizeof (struct libpcap_bt_phdr);
phdr_len = (int)sizeof (struct pcap_bt_phdr);
break;
case WTAP_ENCAP_BLUETOOTH_LINUX_MONITOR:
if (packet_size < sizeof (struct libpcap_bt_monitor_phdr)) {
if (packet_size < sizeof (struct pcap_bt_monitor_phdr)) {
/*
* Uh-oh, the packet isn't big enough to even
* have a pseudo-header.
*/
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup_printf("pcap: libpcap bluetooth monitor file has a %u-byte packet, too small to have even a pseudo-header",
*err_info = g_strdup_printf("pcap/pcapng: Bluetooth monitor file has a %u-byte packet, too small to have even a pseudo-header",
packet_size);
return -1;
}
@ -1841,13 +1842,14 @@ pcap_process_pseudo_header(FILE_T fh, int file_type, int wtap_encap,
&rec->rec_header.packet_header.pseudo_header, err, err_info))
return -1; /* Read error */
phdr_len = (int)sizeof (struct libpcap_bt_monitor_phdr);
phdr_len = (int)sizeof (struct pcap_bt_monitor_phdr);
break;
case WTAP_ENCAP_NFC_LLCP:
if (packet_size < LLCP_HEADER_LEN) {
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup("pcap: libpcap llcp file too short");
*err_info = g_strdup_printf("pcap/pcapng: NFC LLCP file has a %u-byte packet, too small to have even a pseudo-header",
packet_size);
return -1;
}
if (!pcap_read_llcp_pseudoheader(fh, &rec->rec_header.packet_header.pseudo_header, err, err_info))
@ -1856,13 +1858,13 @@ pcap_process_pseudo_header(FILE_T fh, int file_type, int wtap_encap,
break;
case WTAP_ENCAP_PPP_WITH_PHDR:
if (packet_size < sizeof (struct libpcap_ppp_phdr)) {
if (packet_size < sizeof (struct pcap_ppp_phdr)) {
/*
* Uh-oh, the packet isn't big enough to even
* have a pseudo-header.
*/
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup_printf("pcap: libpcap ppp file has a %u-byte packet, too small to have even a pseudo-header",
*err_info = g_strdup_printf("pcap/pcapng: PPP file has a %u-byte packet, too small to have even a pseudo-header",
packet_size);
return -1;
}
@ -1870,7 +1872,7 @@ pcap_process_pseudo_header(FILE_T fh, int file_type, int wtap_encap,
&rec->rec_header.packet_header.pseudo_header, err, err_info))
return -1; /* Read error */
phdr_len = (int)sizeof (struct libpcap_ppp_phdr);
phdr_len = (int)sizeof (struct pcap_ppp_phdr);
break;
case WTAP_ENCAP_ERF:
@ -1880,7 +1882,7 @@ pcap_process_pseudo_header(FILE_T fh, int file_type, int wtap_encap,
* have a pseudo-header.
*/
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup_printf("pcap: ERF file has a %u-byte packet, too small to have even an ERF pseudo-header",
*err_info = g_strdup_printf("pcap/pcapng: ERF file has a %u-byte packet, too small to have even an ERF pseudo-header",
packet_size);
return -1;
}
@ -1911,7 +1913,7 @@ pcap_process_pseudo_header(FILE_T fh, int file_type, int wtap_encap,
* header.
*/
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup_printf("pcap: ERF file has a %u-byte packet, too small for a pseudo-header with ex- and sub-headers (%d)",
*err_info = g_strdup_printf("pcap/pcapng: ERF file has a %u-byte packet, too small for a pseudo-header with ex- and sub-headers (%d)",
packet_size, phdr_len);
return -1;
}
@ -1924,7 +1926,7 @@ pcap_process_pseudo_header(FILE_T fh, int file_type, int wtap_encap,
* have a pseudo-header.
*/
*err = WTAP_ERR_BAD_FILE;
*err_info = g_strdup_printf("pcap: I2C file has a %u-byte packet, too small to have even a I2C pseudo-header",
*err_info = g_strdup_printf("pcap/pcapng: I2C file has a %u-byte packet, too small to have even a I2C pseudo-header",
packet_size);
return -1;
}
@ -2095,15 +2097,15 @@ pcap_get_phdr_size(int encap, const union wtap_pseudo_header *pseudo_header)
break;
case WTAP_ENCAP_BLUETOOTH_H4_WITH_PHDR:
hdrsize = (int)sizeof (struct libpcap_bt_phdr);
hdrsize = (int)sizeof (struct pcap_bt_phdr);
break;
case WTAP_ENCAP_PPP_WITH_PHDR:
hdrsize = (int)sizeof (struct libpcap_ppp_phdr);
hdrsize = (int)sizeof (struct pcap_ppp_phdr);
break;
case WTAP_ENCAP_BLUETOOTH_LINUX_MONITOR:
hdrsize = (int)sizeof (struct libpcap_bt_monitor_phdr);
hdrsize = (int)sizeof (struct pcap_bt_monitor_phdr);
break;
default:
@ -2126,9 +2128,9 @@ pcap_write_phdr(wtap_dumper *wdh, int encap, const union wtap_pseudo_header *pse
guint8 erf_hdr[ sizeof(struct erf_mc_phdr)];
guint8 erf_subhdr[sizeof(union erf_subhdr)];
struct i2c_file_hdr i2c_hdr;
struct libpcap_bt_phdr bt_hdr;
struct libpcap_bt_monitor_phdr bt_monitor_hdr;
struct libpcap_ppp_phdr ppp_hdr;
struct pcap_bt_phdr bt_hdr;
struct pcap_bt_monitor_phdr bt_monitor_hdr;
struct pcap_ppp_phdr ppp_hdr;
size_t size;
size_t subhdr_size = 0;