Merged revision(s) 3046 from branches/releases/bacnet-stack-0-8-0:

Inhibited prints to stdout when called from Wireshark as it limits capturing with Wireshark 2.2
........
This commit is contained in:
skarg
2016-09-29 16:01:06 +00:00
parent 54869fa4ef
commit e9a2bfcbef
+28 -15
View File
@@ -76,6 +76,8 @@ static uint8_t RxBuffer[MAX_MPDU];
static uint8_t TxBuffer[MAX_MPDU]; static uint8_t TxBuffer[MAX_MPDU];
/* method to tell main loop to exit from CTRL-C or other signals */ /* method to tell main loop to exit from CTRL-C or other signals */
static volatile bool Exit_Requested; static volatile bool Exit_Requested;
/* flag to indicate Wireshark is running the show - no stdout or stderr */
static bool Wireshark_Capture;
/* statistics derived from monitoring the network for each node */ /* statistics derived from monitoring the network for each node */
struct mstp_statistics { struct mstp_statistics {
@@ -455,7 +457,9 @@ static HANDLE hPipe = INVALID_HANDLE_VALUE; /* pipe handle */
static void named_pipe_create( static void named_pipe_create(
char *pipe_name) char *pipe_name)
{ {
fprintf(stdout, "mstpcap: Creating Named Pipe \"%s\"\n", pipe_name); if (!Wireshark_Capture) {
fprintf(stdout, "mstpcap: Creating Named Pipe \"%s\"\n", pipe_name);
}
/* create the pipe */ /* create the pipe */
while (hPipe == INVALID_HANDLE_VALUE) while (hPipe == INVALID_HANDLE_VALUE)
{ {
@@ -606,7 +610,9 @@ static void write_global_header(
(void) data_write_header(&snaplen, sizeof(snaplen), 1, pipe_enable); (void) data_write_header(&snaplen, sizeof(snaplen), 1, pipe_enable);
(void) data_write_header(&network, sizeof(network), 1, pipe_enable); (void) data_write_header(&network, sizeof(network), 1, pipe_enable);
fflush(pFile); fflush(pFile);
fprintf(stdout, "mstpcap: saving capture to %s\n", filename); if (!Wireshark_Capture) {
fprintf(stdout, "mstpcap: saving capture to %s\n", filename);
}
} else { } else {
fprintf(stderr, "mstpcap[header]: failed to open %s: %s\n", filename, fprintf(stderr, "mstpcap[header]: failed to open %s: %s\n", filename,
strerror(errno)); strerror(errno));
@@ -885,7 +891,9 @@ static bool read_received_packet(
static void cleanup( static void cleanup(
void) void)
{ {
packet_statistics_print(); if (!Wireshark_Capture) {
packet_statistics_print();
}
if (pFile) { if (pFile) {
fflush(pFile); /* stream pointer */ fflush(pFile); /* stream pointer */
fclose(pFile); /* stream pointer */ fclose(pFile); /* stream pointer */
@@ -1045,7 +1053,7 @@ int main(
} }
if (strcmp(argv[argi], "--version") == 0) { if (strcmp(argv[argi], "--version") == 0) {
printf("mstpcap %s\n", BACNET_VERSION_TEXT); printf("mstpcap %s\n", BACNET_VERSION_TEXT);
printf("Copyright (C) 2011 by Steve Karg\n" printf("Copyright (C) 2011-2016 by Steve Karg\n"
"This is free software; see the source for copying conditions.\n" "This is free software; see the source for copying conditions.\n"
"There is NO warranty; not even for MERCHANTABILITY or\n" "There is NO warranty; not even for MERCHANTABILITY or\n"
"FITNESS FOR A PARTICULAR PURPOSE.\n"); "FITNESS FOR A PARTICULAR PURPOSE.\n");
@@ -1103,6 +1111,7 @@ int main(
} }
if (strcmp(argv[argi], "--capture") == 0) { if (strcmp(argv[argi], "--capture") == 0) {
/* do nothing - fall through and start running! */ /* do nothing - fall through and start running! */
Wireshark_Capture = true;
} }
if (strcmp(argv[argi], "--extcap-interface") == 0) { if (strcmp(argv[argi], "--extcap-interface") == 0) {
argi++; argi++;
@@ -1162,8 +1171,10 @@ int main(
atexit(cleanup); atexit(cleanup);
RS485_Initialize(); RS485_Initialize();
timer_init(); timer_init();
fprintf(stdout, "mstpcap: Using %s for capture at %ld bps.\n", if (!Wireshark_Capture) {
RS485_Interface(), (long) RS485_Get_Baud_Rate()); fprintf(stdout, "mstpcap: Using %s for capture at %ld bps.\n",
RS485_Interface(), (long) RS485_Get_Baud_Rate());
}
#if defined(_WIN32) #if defined(_WIN32)
SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), ENABLE_PROCESSED_INPUT); SetConsoleMode(GetStdHandle(STD_INPUT_HANDLE), ENABLE_PROCESSED_INPUT);
SetConsoleCtrlHandler((PHANDLER_ROUTINE) CtrlCHandler, TRUE); SetConsoleCtrlHandler((PHANDLER_ROUTINE) CtrlCHandler, TRUE);
@@ -1215,15 +1226,17 @@ int main(
Invalid_Frame_Count++; Invalid_Frame_Count++;
} }
} }
if (!(packet_count % 100)) { if (!Wireshark_Capture) {
fprintf(stdout, "\r%hu packets, %hu invalid frames", packet_count, if (!(packet_count % 100)) {
Invalid_Frame_Count); fprintf(stdout, "\r%hu packets, %hu invalid frames", packet_count,
} Invalid_Frame_Count);
if (packet_count >= 65535) { }
packet_statistics_print(); if (packet_count >= 65535) {
packet_statistics_clear(); packet_statistics_print();
filename_create_new(); packet_statistics_clear();
packet_count = 0; filename_create_new();
packet_count = 0;
}
} }
if (Exit_Requested) { if (Exit_Requested) {
break; break;