summaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorBill Fenner <fenner@gmail.com>2019-04-15 06:25:28 -0700
committerGuy Harris <guy@alum.mit.edu>2019-06-20 02:32:26 -0700
commita335095f361e12c1355bbb547877690f04e0066e (patch)
tree529f5c9f2a46039cdf125e309dc83e4027933195
parentcce2098d7bd6c833d29d0a875d2c1322fc744cb3 (diff)
downloadlibpcap-a335095f361e12c1355bbb547877690f04e0066e.tar.gz
Report the DLT description in error messages
Introduce pcap_datalink_val_to_description_or_dlt, and use that when reporting an error. This was inspired by seeing "tcpdump: no VLAN support for data link type 113". The new equivalent message is "tcpdump: no VLAN support for Linux cooked". (cherry picked from commit 6e95542894f084d831a2da039a1da85d86dc2604)
-rw-r--r--Makefile.in3
-rw-r--r--gencode.c30
-rw-r--r--pcap.c15
-rw-r--r--pcap/pcap.h1
-rw-r--r--pcap_datalink_val_to_name.3pcap12
5 files changed, 43 insertions, 18 deletions
diff --git a/Makefile.in b/Makefile.in
index 0c725db3..5a6b165d 100644
--- a/Makefile.in
+++ b/Makefile.in
@@ -590,6 +590,9 @@ install: install-shared install-archive libpcap.pc pcap-config @INSTALL_RPCAPD@
rm -f pcap_datalink_val_to_description.3pcap && \
$(LN_S) pcap_datalink_val_to_name.3pcap \
pcap_datalink_val_to_description.3pcap && \
+ rm -f pcap_datalink_val_to_description_or_dlt.3pcap && \
+ $(LN_S) pcap_datalink_val_to_name.3pcap \
+ pcap_datalink_val_to_description_or_dlt.3pcap && \
rm -f pcap_dump_fopen.3pcap && \
$(LN_S) pcap_dump_open.3pcap pcap_dump_fopen.3pcap && \
rm -f pcap_freealldevs.3pcap && \
diff --git a/gencode.c b/gencode.c
index df2fc78c..ba2488b7 100644
--- a/gencode.c
+++ b/gencode.c
@@ -3638,14 +3638,9 @@ gen_linktype(compiler_state_t *cstate, int proto)
/*
* No; report an error.
*/
- description = pcap_datalink_val_to_description(cstate->linktype);
- if (description != NULL) {
- bpf_error(cstate, "%s link-layer type filtering not implemented",
- description);
- } else {
- bpf_error(cstate, "DLT %u link-layer type filtering not implemented",
- cstate->linktype);
- }
+ description = pcap_datalink_val_to_description_or_dlt(cstate->linktype);
+ bpf_error(cstate, "%s link-layer type filtering not implemented",
+ description);
/*NOTREACHED */
}
}
@@ -3743,7 +3738,8 @@ gen_llc_internal(compiler_state_t *cstate)
return b0;
default:
- bpf_error(cstate, "'llc' not supported for linktype %d", cstate->linktype);
+ bpf_error(cstate, "'llc' not supported for %s",
+ pcap_datalink_val_to_description_or_dlt(cstate->linktype));
/*NOTREACHED*/
}
}
@@ -8318,8 +8314,8 @@ gen_inbound(compiler_state_t *cstate, int dir)
*/
if (cstate->bpf_pcap->rfile != NULL) {
/* We have a FILE *, so this is a savefile */
- bpf_error(cstate, "inbound/outbound not supported on linktype %d when reading savefiles",
- cstate->linktype);
+ bpf_error(cstate, "inbound/outbound not supported on %s when reading savefiles",
+ pcap_datalink_val_to_description_or_dlt(cstate->linktype));
b0 = NULL;
/*NOTREACHED*/
}
@@ -8331,8 +8327,8 @@ gen_inbound(compiler_state_t *cstate, int dir)
gen_not(b0);
}
#else /* defined(linux) && defined(PF_PACKET) && defined(SO_ATTACH_FILTER) */
- bpf_error(cstate, "inbound/outbound not supported on linktype %d",
- cstate->linktype);
+ bpf_error(cstate, "inbound/outbound not supported on %s",
+ pcap_datalink_val_to_description_or_dlt(cstate->linktype));
/*NOTREACHED*/
#endif /* defined(linux) && defined(PF_PACKET) && defined(SO_ATTACH_FILTER) */
}
@@ -8996,8 +8992,8 @@ gen_vlan(compiler_state_t *cstate, bpf_u_int32 vlan_num, int has_vlan_tag)
break;
default:
- bpf_error(cstate, "no VLAN support for data link type %d",
- cstate->linktype);
+ bpf_error(cstate, "no VLAN support for %s",
+ pcap_datalink_val_to_description_or_dlt(cstate->linktype));
/*NOTREACHED*/
}
@@ -9053,8 +9049,8 @@ gen_mpls(compiler_state_t *cstate, bpf_u_int32 label_num_arg,
* leave it for now */
default:
- bpf_error(cstate, "no MPLS support for data link type %d",
- cstate->linktype);
+ bpf_error(cstate, "no MPLS support for %s",
+ pcap_datalink_val_to_description_or_dlt(cstate->linktype));
/*NOTREACHED*/
}
}
diff --git a/pcap.c b/pcap.c
index da04aa37..e8c1b674 100644
--- a/pcap.c
+++ b/pcap.c
@@ -3107,6 +3107,21 @@ pcap_datalink_val_to_description(int dlt)
return (NULL);
}
+const char *
+pcap_datalink_val_to_description_or_dlt(int dlt)
+{
+ static char unkbuf[40];
+ const char *description;
+
+ description = pcap_datalink_val_to_description(dlt);
+ if (description != NULL) {
+ return description;
+ } else {
+ (void)pcap_snprintf(unkbuf, sizeof(unkbuf), "DLT %u", dlt);
+ return unkbuf;
+ }
+}
+
struct tstamp_type_choice {
const char *name;
const char *description;
diff --git a/pcap/pcap.h b/pcap/pcap.h
index 94d92e52..90614dd0 100644
--- a/pcap/pcap.h
+++ b/pcap/pcap.h
@@ -470,6 +470,7 @@ PCAP_API void pcap_free_datalinks(int *);
PCAP_API int pcap_datalink_name_to_val(const char *);
PCAP_API const char *pcap_datalink_val_to_name(int);
PCAP_API const char *pcap_datalink_val_to_description(int);
+PCAP_API const char *pcap_datalink_val_to_description_or_dlt(int);
PCAP_API int pcap_snapshot(pcap_t *);
PCAP_API int pcap_is_swapped(pcap_t *);
PCAP_API int pcap_major_version(pcap_t *);
diff --git a/pcap_datalink_val_to_name.3pcap b/pcap_datalink_val_to_name.3pcap
index efdbfc63..f42165fb 100644
--- a/pcap_datalink_val_to_name.3pcap
+++ b/pcap_datalink_val_to_name.3pcap
@@ -19,7 +19,8 @@
.\"
.TH PCAP_DATALINK_VAL_TO_NAME 3PCAP "12 October 2016"
.SH NAME
-pcap_datalink_val_to_name, pcap_datalink_val_to_description \- get a
+pcap_datalink_val_to_name, pcap_datalink_val_to_description,
+pcap_datalink_val_to_description_or_dlt \- get a
name or description for a link-layer header type value
.SH SYNOPSIS
.nf
@@ -30,6 +31,7 @@ name or description for a link-layer header type value
.ft B
const char *pcap_datalink_val_to_name(int dlt);
const char *pcap_datalink_val_to_description(int dlt);
+const char *pcap_datalink_val_to_description_or_dlt(int dlt);
.ft
.fi
.SH DESCRIPTION
@@ -52,5 +54,13 @@ link-layer header type.
is returned if the type value does not correspond to a known
.B DLT_
value.
+.PP
+.B pcap_datalink_val_to_description_or_dlt()
+translates a link-layer header type value to a short description of that
+link-layer header type just like pcap_datalink_val_to_description.
+If the type value does not correspond to a known
+.B DLT_
+value, the string "DLT n" is returned, where n is the value of
+the dlt argument.
.SH SEE ALSO
pcap(3PCAP)