Quiet initilization fo decpcap when output_json.

This commit is contained in:
2025-08-05 05:35:27 +02:00
parent 1d8d69bf06
commit 468b055918
5 changed files with 27 additions and 24 deletions

View File

@@ -35,7 +35,7 @@
bool catchall = false;
/* functions to set up a handle (which is basically just a pcap handle) */
struct dp_handle *dp_fillhandle(pcap_t *phandle) {
struct dp_handle *dp_fillhandle(pcap_t *phandle, bool quiet) {
struct dp_handle *retval =
(struct dp_handle *)malloc(sizeof(struct dp_handle));
int i;
@@ -47,6 +47,7 @@ struct dp_handle *dp_fillhandle(pcap_t *phandle) {
retval->linktype = pcap_datalink(retval->pcap_handle);
if((!quiet)){
switch (retval->linktype) {
case (DLT_EN10MB):
fprintf(stdout, "Ethernet link detected\n");
@@ -62,22 +63,23 @@ struct dp_handle *dp_fillhandle(pcap_t *phandle) {
// TODO maybe error? or 'other' callback?
break;
}
}
return retval;
}
struct dp_handle *dp_open_offline(char *fname, char *ebuf) {
struct dp_handle *dp_open_offline(char *fname, char *ebuf, bool quiet) {
pcap_t *temp = pcap_open_offline(fname, ebuf);
if (temp == NULL) {
return NULL;
}
return dp_fillhandle(temp);
return dp_fillhandle(temp, quiet);
}
struct dp_handle *dp_open_live(const char *device, int snaplen, int promisc,
int to_ms, char *filter, char *errbuf) {
int to_ms, char *filter, char *errbuf, bool quiet) {
struct bpf_program fp; // compiled filter program
bpf_u_int32 maskp; // subnet mask
bpf_u_int32 netp; // interface IP
@@ -107,7 +109,7 @@ struct dp_handle *dp_open_live(const char *device, int snaplen, int promisc,
}
}
return dp_fillhandle(temp);
return dp_fillhandle(temp, quiet);
}
/* function to get packet statistics, e.g. dropped packets */

View File

@@ -67,8 +67,8 @@ struct dp_handle {
/* functions to set up a handle (which is basically just a pcap handle) */
struct dp_handle *dp_open_live(const char *device, int snaplen, int promisc,
int to_ms, char *filter, char *errbuf);
struct dp_handle *dp_open_offline(char *fname, char *ebuf);
int to_ms, char *filter, char *errbuf, bool quiet);
struct dp_handle *dp_open_offline(char *fname, char *ebuf, bool quiet);
/* function to get packet statistics, e.g. dropped packets */

View File

@@ -39,7 +39,7 @@ int main(int argc, char **argv) {
char *errbuf = new char[DP_ERRBUF_SIZE];
dp_handle *newhandle = dp_open_offline(argv[1], errbuf);
dp_handle *newhandle = dp_open_offline(argv[1], errbuf, false);
dp_addcb(newhandle, dp_packet_tcp, process_tcp);
int ret = dp_dispatch(newhandle, -1, NULL, 0);
if (ret == -1) {

View File

@@ -102,7 +102,7 @@ static int nethogsmonitor_init(int devc, char **devicenames, bool all,
char errbuf[PCAP_ERRBUF_SIZE];
dp_handle *newhandle = dp_open_live(current_dev->name, BUFSIZ, promiscuous,
to_ms, filter, errbuf);
to_ms, filter, errbuf, false);
if (newhandle != NULL) {
dp_addcb(newhandle, dp_packet_ip, process_ip);
dp_addcb(newhandle, dp_packet_ip6, process_ip6);

View File

@@ -254,8 +254,9 @@ int main(int argc, char **argv) {
forceExit(false, "getifaddrs failed while establishing local IP.");
}
bool quiet = output_json;
dp_handle *newhandle =
dp_open_live(current_dev->name, BUFSIZ, promisc, 100, filter, errbuf);
dp_open_live(current_dev->name, BUFSIZ, promisc, 100, filter, errbuf, quiet);
if (newhandle != NULL) {
dp_addcb(newhandle, dp_packet_ip, process_ip);
dp_addcb(newhandle, dp_packet_ip6, process_ip6);