Skip to content

win32: fix MR180 - broken "-i -" input pipe

Chuck Craft requested to merge chuckcraft/wireshark:issue/16834A into master

Tested with input scenario from mr180:
C:\Development\wsbuild64\run\RelWithDebInfo>type b6300a.cap | .\Wireshark.exe -k -i -

And when ouput is sent to a pipe or redirected to a file:

C:\Development\wsbuild64\run\RelWithDebInfo>type b6300a.cap | .\Wireshark.exe -k -i - | more
C:\Development\wsbuild64\run\RelWithDebInfo>type b6300a.cap | .\Wireshark.exe -k -i - >out.txt 2>err.txt

Caused by checking a flag before it is set:

main.cpp
--------
int main()

restore_pipes(), checks stdin_capture flag before it has been set by commandline_early_options()

console_win32.c
---------------
void restore_pipes(void)

    if (stdin_capture) {
        /* We've been handed "-i -". Don't mess with stdio. */
        return;
    }

stdin_capture is set by:

void set_stdin_capture(gboolean set_stdin_capture)
{
    stdin_capture = set_stdin_capture;
}

which is called in commandline.c when the options are processed:

void commandline_early_options(int argc, char *argv[])

#ifdef _WIN32
            case 'i':
                if (strcmp(optarg, "-") == 0)
                    set_stdin_capture(TRUE);
                break;
#endif

Merge request reports