Huge thanks to our Platinum Members Endace and LiveAction,
and our Silver Member Veeam, for supporting the Wireshark Foundation and project.

Ethereal-dev: [Ethereal-dev] [PATCH] Set stdout to binary mode when using -w - in tethereal

Note: This archive is from the project's previous web site, ethereal.com. This list is no longer active.

From: Joe Marcus Clarke <marcus@xxxxxxxxxxxxx>
Date: Mon, 26 Apr 2004 17:47:06 -0400
When using tethereal with "-w -" stdout is put in text mode, and this
results in corrupt packet captures.  The attached patch fixes the
problem by setting stdout to binary mode.

Joe

-- 
PGP Key : http://www.marcuscom.com/pgp.asc


This patch is needed to fix tethereal -w - (and thus jet -w -) on Windows.
Currently, tethereal has stdout set in text mode on Windows, and this
corrupts the packet dump.  This patch applies to ethereal-0.10.3.

--- wiretap/file_access.c.orig	Mon Apr 26 16:35:37 2004
+++ wiretap/file_access.c	Mon Apr 26 16:36:30 2004
@@ -537,9 +537,12 @@
 		return NULL;	/* couldn't allocate it */
 
 	/* Empty filename means stdout */
-	if (*filename == '\0')
+	if (*filename == '\0') {
+#ifdef _WIN32
+		setmode(fileno(stdout), O_BINARY);
+#endif
 		wdh->fh = stdout;
-	else {
+	} else {
 		/* In case "fopen()" fails but doesn't set "errno", set "errno"
 		   to a generic "the open failed" error. */
 		errno = WTAP_ERR_CANT_OPEN;

Attachment: signature.asc
Description: This is a digitally signed message part