aboutsummaryrefslogtreecommitdiffstats
path: root/dumpcap.c
diff options
context:
space:
mode:
authorUlf Lamping <ulf.lamping@web.de>2006-03-13 00:30:51 +0000
committerUlf Lamping <ulf.lamping@web.de>2006-03-13 00:30:51 +0000
commit069b26b2d985bca636c19b4a86875cb91988a368 (patch)
treec52d27261be1ead9d272b2149c5fbbd321632d3c /dumpcap.c
parent4bafab904cc881b14dbabc9aea2f76ef6d1402a9 (diff)
fix bug #803: sync pipe on Win32 wasn't set to binary mode, so error message transport failed between Ethereal and dumpcap.
I've also changed the way the secondary error message is transported from former "header message 0 secondary 0" to "header header message 0 header secondary 0" as that might be a bit more clearer, and I'll need it for further development anyway. I was using this while debugging and not recognizing the real problem - for about four hours :-(. I'll need this feature when doing the interface (and link layer type) browsing later (transferring this data from dumpcap to Ethereal) to get a full blown privilege seperation. svn path=/trunk/; revision=17608
Diffstat (limited to 'dumpcap.c')
-rw-r--r--dumpcap.c81
1 files changed, 42 insertions, 39 deletions
diff --git a/dumpcap.c b/dumpcap.c
index 268f32615e..a972486141 100644
--- a/dumpcap.c
+++ b/dumpcap.c
@@ -337,6 +337,10 @@ main(int argc, char *argv[])
/*** hidden option: Ethereal child mode (using binary output messages) ***/
case 'Z':
capture_child = TRUE;
+#ifdef _WIN32
+ /* set output pipe to binary mode, to avoid ugly text conversions */
+ _setmode(1, O_BINARY);
+#endif
break;
/*** all non capture option specific ***/
@@ -505,51 +509,51 @@ console_log_handler(const char *log_domain, GLogLevelFlags log_level,
/*
* Maximum length of sync pipe message data. Must be < 2^24, as the
* message length is 3 bytes.
- * XXX - this must be large enough to handle a Really Big Filter
+ * XXX - this should be large enough to handle a Really Big Filter
* Expression, as the error message for an incorrect filter expression
* is a bit larger than the filter expression.
*/
#define SP_MAX_MSG_LEN 4096
+/* write a single message header to the recipient pipe */
+static int
+pipe_write_header(int pipe, char indicator, int length)
+{
+ guchar header[1+3]; /* indicator + 3-byte len */
+
+
+ g_assert(length <= SP_MAX_MSG_LEN);
+
+ /* write header (indicator + 3-byte len) */
+ header[0] = indicator;
+ header[1] = (length >> 16) & 0xFF;
+ header[2] = (length >> 8) & 0xFF;
+ header[3] = (length >> 0) & 0xFF;
+
+ /* write header */
+ return write(pipe, header, sizeof header);
+}
/* write a message to the recipient pipe in the standard format
(3 digit message length (excluding length and indicator field),
1 byte message indicator and the rest is the message).
- If msg is NULL, the message has only a length and indicator.
- Otherwise, if secondary_msg isn't NULL, send both msg and
- secondary_msg as null-terminated strings, otherwise just send
- msg as a null-terminated string and follow it with an empty string. */
+ If msg is NULL, the message has only a length and indicator. */
static void
-pipe_write_block(int pipe, char indicator, const char *msg,
- const char *secondary_msg)
+pipe_write_block(int pipe, char indicator, const char *msg)
{
- guchar header[3+1]; /* indicator + 3-byte len */
int ret;
- size_t len, secondary_len, total_len;
+ size_t len;
/*g_warning("write %d enter", pipe);*/
- len = 0;
- secondary_len = 0;
- total_len = 0;
if(msg != NULL) {
- len = strlen(msg) + 1; /* include the terminating '\0' */
- total_len = len;
- if(secondary_msg == NULL)
- secondary_msg = ""; /* default to an empty string */
- secondary_len = strlen(secondary_msg) + 1;
- total_len += secondary_len;
+ len = strlen(msg) + 1; /* including the terminating '\0'! */
+ } else {
+ len = 0;
}
- g_assert(indicator < '0' || indicator > '9');
- g_assert(total_len <= SP_MAX_MSG_LEN);
/* write header (indicator + 3-byte len) */
- header[0] = indicator;
- header[1] = (total_len >> 16) & 0xFF;
- header[2] = (total_len >> 8) & 0xFF;
- header[3] = (total_len >> 0) & 0xFF;
-
- ret = write(pipe, header, sizeof header);
+ ret = pipe_write_header(pipe, indicator, len);
if(ret == -1) {
return;
}
@@ -561,10 +565,6 @@ pipe_write_block(int pipe, char indicator, const char *msg,
if(ret == -1) {
return;
}
- ret = write(pipe, secondary_msg, secondary_len);
- if(ret == -1) {
- return;
- }
} else {
/*g_warning("write %d indicator: %c no value", pipe, indicator);*/
}
@@ -583,7 +583,7 @@ sync_pipe_packet_count_to_parent(int packet_count)
if(capture_child) {
g_snprintf(tmp, sizeof(tmp), "%d", packet_count);
g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, "Packets: %s", tmp);
- pipe_write_block(1, SP_PACKET_COUNT, tmp, NULL);
+ pipe_write_block(1, SP_PACKET_COUNT, tmp);
} else {
count += packet_count;
fprintf(stderr, "\rPackets: %u ", count);
@@ -600,7 +600,7 @@ sync_pipe_filename_to_parent(const char *filename)
g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_MESSAGE, "File: %s", filename);
if(capture_child) {
- pipe_write_block(1, SP_FILE, filename, NULL);
+ pipe_write_block(1, SP_FILE, filename);
}
}
@@ -612,7 +612,7 @@ sync_pipe_cfilter_error_to_parent(const char *cfilter _U_, const char *errmsg)
g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_DEBUG, "Capture filter error: %s", errmsg);
if (capture_child) {
- pipe_write_block(1, SP_BAD_FILTER, errmsg, NULL);
+ pipe_write_block(1, SP_BAD_FILTER, errmsg);
}
}
@@ -620,13 +620,16 @@ void
sync_pipe_errmsg_to_parent(const char *error_msg, const char *secondary_error_msg)
{
- g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_MESSAGE, "Error: %s", error_msg);
- if (secondary_error_msg != NULL)
- g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_MESSAGE, "Secondary error: %s",
- secondary_error_msg);
+ g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_MESSAGE,
+ "Primary Error: %s", error_msg);
+ g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_MESSAGE,
+ "Secondary Error: %s", secondary_error_msg);
if(capture_child) {
- pipe_write_block(1, SP_ERROR_MSG, error_msg, secondary_error_msg);
+ /* first write a "master header" with the length of the two messages plus their "slave headers" */
+ pipe_write_header(1, SP_ERROR_MSG, strlen(error_msg) + 1 + 4 + strlen(secondary_error_msg) + 1 + 4);
+ pipe_write_block(1, SP_ERROR_MSG, error_msg);
+ pipe_write_block(1, SP_ERROR_MSG, secondary_error_msg);
}
}
@@ -640,7 +643,7 @@ sync_pipe_drops_to_parent(int drops)
g_log(LOG_DOMAIN_CAPTURE_CHILD, G_LOG_LEVEL_MESSAGE, "Packets dropped: %s", tmp);
if(capture_child) {
- pipe_write_block(1, SP_DROPS, tmp, NULL);
+ pipe_write_block(1, SP_DROPS, tmp);
}
}