VirtualBox

Changeset 97678 in vbox


Ignore:
Timestamp:
Nov 24, 2022 7:09:04 PM (2 years ago)
Author:
vboxsync
Message:

FE/VBoxIntNetPcap: Fix building after the changes done to internal network code for bugref:10297, bugref:9959

Location:
trunk/src/VBox/Frontends
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/VBox/Frontends/Makefile.kmk

    r96407 r97678  
    5757  include $(PATH_SUB_CURRENT)/VirtualBox/Makefile.kmk
    5858 endif
     59 ifdef VBOX_WITH_INTNET_PCAP
     60  include $(PATH_SUB_CURRENT)/VBoxIntNetPcap/Makefile.kmk
     61 endif
    5962 include $(PATH_SUB_CURRENT)/Common/Makefile.kmk
    6063endif # !VBOX_ONLY_DOCS
  • trunk/src/VBox/Frontends/VBoxIntnetPcap/Makefile.kmk

    r96407 r97678  
    3131PROGRAMS += VBoxIntnetPcap
    3232VBoxIntnetPcap_TEMPLATE := VBOXR3EXE
     33VBoxIntnetPcap_DEFS     := \
     34        $(if $(VBOX_WITH_INTNET_SERVICE_IN_R3),VBOX_WITH_INTNET_SERVICE_IN_R3,)
    3335VBoxIntnetPcap_INCS     := \
    3436        ../../NetworkServices/NetLib \
  • trunk/src/VBox/Frontends/VBoxIntnetPcap/VBoxIntnetPcap.cpp

    r96407 r97678  
    4848*   Internal Functions                                                                                                           *
    4949*********************************************************************************************************************************/
    50 static DECLCALLBACK(void) captureFrame(void *pvUser, void *pvFrame, uint32_t cbFrame);
    51 static DECLCALLBACK(void) captureGSO(void *pvUser, PCPDMNETWORKGSO pcGso, uint32_t cbFrame);
    5250
    5351
     
    5553*   Global Variables                                                                                                             *
    5654*********************************************************************************************************************************/
    57 static IntNetIf     g_net;
     55static INTNETIFCTX  g_hIntNetCtx;
    5856static PRTSTREAM    g_pStrmOut;
    5957static uint64_t     g_StartNanoTS;
     
    7068    { "--write",                'w',   RTGETOPT_REQ_STRING },
    7169};
     70
     71
     72static void checkCaptureLimit(void)
     73{
     74    if (g_cCountDown > 0)
     75    {
     76        if (g_cCountDown-- == 1)
     77            IntNetR3IfWaitAbort(g_hIntNetCtx);
     78    }
     79}
     80
     81
     82static DECLCALLBACK(void) captureFrame(void *pvUser, void *pvFrame, uint32_t cbFrame)
     83{
     84    RT_NOREF(pvUser);
     85
     86    int rc = PcapStreamFrame(g_pStrmOut, g_StartNanoTS, pvFrame, cbFrame, g_cbSnapLen);
     87    if (RT_FAILURE(rc))
     88    {
     89        RTMsgError("write: %Rrf", rc);
     90        IntNetR3IfWaitAbort(g_hIntNetCtx);
     91    }
     92
     93    if (g_fPacketBuffered)
     94        RTStrmFlush(g_pStrmOut);
     95
     96    checkCaptureLimit();
     97}
     98
     99
     100static DECLCALLBACK(void) captureGSO(void *pvUser, PCPDMNETWORKGSO pcGso, uint32_t cbFrame)
     101{
     102    RT_NOREF(pvUser, pcGso, cbFrame);
     103
     104    checkCaptureLimit();
     105}
    72106
    73107
     
    167201    }
    168202
    169     /*
    170      * Configure the snooper.
    171      */
    172     g_net.setInputCallback(captureFrame, NULL);
    173     g_net.setInputGSOCallback(captureGSO, NULL);
    174 
    175     /*
    176      * NB: There's currently no way to prevent an intnet from being
    177      * created when one doesn't exist, so there's no way to catch a
    178      * typo...  beware.
    179      */
    180     rc = g_net.init(pszNetworkName);
    181     if (RT_FAILURE(rc))
    182         return RTMsgErrorExitFailure("%s: %Rrf", pszNetworkName, rc);
    183 
    184     rc = g_net.ifSetPromiscuous();
    185     if (RT_FAILURE(rc))
    186         return RTMsgErrorExitFailure("%s: failed to set promiscuous mode: %Rrf", pszNetworkName, rc);
     203    rc = IntNetR3IfCreate(&g_hIntNetCtx, pszNetworkName);
     204    if (RT_FAILURE(rc))
     205        return RTMsgErrorExitFailure("Opening the internal network '%s' failed with %Rrc\n", pszNetworkName, rc);
     206
     207    rc = IntNetR3IfSetPromiscuous(g_hIntNetCtx, true /*fPromiscuous*/);
     208    if (RT_FAILURE(rc))
     209        return RTMsgErrorExitFailure("Enabling promiscuous mode on the internal network '%s' failed with %Rrc\n", pszNetworkName, rc);
     210
     211    rc = IntNetR3IfSetActive(g_hIntNetCtx, true /*fActive*/);
     212    if (RT_FAILURE(rc))
     213        return RTMsgErrorExitFailure("Activating interface on the internal network '%s' failed with %Rrc\n", pszNetworkName, rc);
    187214
    188215    /*
     
    196223        RTStrmFlush(g_pStrmOut);
    197224
    198     g_net.ifPump();
     225    rc = IntNetR3IfPumpPkts(g_hIntNetCtx, captureFrame, NULL /*pvUser*/,
     226                            captureGSO, NULL /*pvUserGso*/);
    199227
    200228    RTEXITCODE rcExit = RT_SUCCESS(RTStrmError(g_pStrmOut)) ? RTEXITCODE_SUCCESS : RTEXITCODE_FAILURE;
     
    204232    return rcExit;
    205233}
    206 
    207 
    208 static void checkCaptureLimit(void)
    209 {
    210     if (g_cCountDown > 0)
    211     {
    212         if (g_cCountDown-- == 1)
    213             g_net.ifAbort();
    214     }
    215 }
    216 
    217 
    218 static DECLCALLBACK(void) captureFrame(void *pvUser, void *pvFrame, uint32_t cbFrame)
    219 {
    220     RT_NOREF(pvUser);
    221 
    222     int rc = PcapStreamFrame(g_pStrmOut, g_StartNanoTS, pvFrame, cbFrame, g_cbSnapLen);
    223     if (RT_FAILURE(rc))
    224     {
    225         RTMsgError("write: %Rrf", rc);
    226         g_net.ifAbort();
    227     }
    228 
    229     if (g_fPacketBuffered)
    230         RTStrmFlush(g_pStrmOut);
    231 
    232     checkCaptureLimit();
    233 }
    234 
    235 
    236 static DECLCALLBACK(void) captureGSO(void *pvUser, PCPDMNETWORKGSO pcGso, uint32_t cbFrame)
    237 {
    238     RT_NOREF(pvUser, pcGso, cbFrame);
    239 
    240     checkCaptureLimit();
    241 }
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