VirtualBox

Changeset 87910 in vbox


Ignore:
Timestamp:
Mar 2, 2021 12:03:17 PM (4 years ago)
Author:
vboxsync
Message:

VBoxIntnetPcap: Dump to stdout if the file name is "-". bugref:9959.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/VBoxIntnetPcap/VBoxIntnetPcap.cpp

    r87908 r87910  
    3535
    3636IntNetIf g_net;
    37 RTFILE g_hPcapFile = NIL_RTFILE;
     37PRTSTREAM g_pStrmOut;
    3838uint64_t g_u64Count;
    3939size_t g_cbSnapLen;
     
    153153
    154154    if (g_cbSnapLen == 0)
    155         g_cbSnapLen = 262144;   /* traditional limit is 256K */
    156 
    157 
    158     rc = RTFileOpen(&g_hPcapFile, strPcapFile.c_str(),
    159                     RTFILE_O_CREATE_REPLACE | RTFILE_O_WRITE | RTFILE_O_DENY_WRITE);
    160     if (RT_FAILURE(rc))
    161         return RTMsgErrorExit(RTEXITCODE_FAILURE,
    162                               "%s: %Rrf", strPcapFile.c_str(), rc);
     155        g_cbSnapLen = 0xffff;
     156
     157
     158    if (strPcapFile == "-")
     159    {
     160        g_pStrmOut = g_pStdOut;
     161    }
     162    else
     163    {
     164        rc = RTStrmOpen(strPcapFile.c_str(), "wb", &g_pStrmOut);
     165        if (RT_FAILURE(rc))
     166            return RTMsgErrorExit(RTEXITCODE_FAILURE,
     167                                  "%s: %Rrf", strPcapFile.c_str(), rc);
     168    }
    163169
    164170    g_net.setInputCallback(captureFrame, NULL);
     
    181187                              strNetworkName.c_str(), rc);
    182188
    183     rc = PcapFileHdr(g_hPcapFile, RTTimeNanoTS());
     189    rc = PcapStreamHdr(g_pStrmOut, RTTimeNanoTS());
    184190    if (RT_FAILURE(rc))
    185191        return RTMsgErrorExit(RTEXITCODE_FAILURE,
     
    187193
    188194    g_net.ifPump();
    189     RTFileClose(g_hPcapFile);
     195    RTStrmClose(g_pStrmOut);
    190196
    191197    return RTEXITCODE_SUCCESS;
     
    211217    RT_NOREF(pvUser);
    212218
    213     rc = PcapFileFrame(g_hPcapFile, RTTimeNanoTS(),
    214                        pvFrame, cbFrame, g_cbSnapLen);
     219    rc = PcapStreamFrame(g_pStrmOut, RTTimeNanoTS(),
     220                         pvFrame, cbFrame, g_cbSnapLen);
    215221    if (RT_FAILURE(rc)) {
    216222        RTMsgError("write: %Rrf", rc);
Note: See TracChangeset for help on using the changeset viewer.

© 2024 Oracle Support Privacy / Do Not Sell My Info Terms of Use Trademark Policy Automated Access Etiquette