Page 1 of 1

Unable to add a column to the packet list

Posted: Mon Jul 19, 2010 7:00 pm
by matman13
I'm using OP v6.0.7. I downloaded the Visual Studio 2008 Wizard and generated a plugin called TestPlugin. I have successfully compiled the plugin and see default behavior, namely the counting of TCP SYN and FIN packets. So far so good.

Now I'm trying to add a custom column to the packet list using the DoSetPacketListColumn() API. At first, the return code was -1, but I tracked this down - the PeekPlugin::s_procSetPacketListColumn callback was not being set in the CPeekApp::Init() function (apparently just an oversight in the wizard). I've fixed this, and now the return code is 87. I have no idea what this means and need some direction.

Here's the code I've got:


Code: Select all

int CTestPluginPlugin::OnCreateContext(
    PluginCreateContextParam *ioParams)
{
    CTestPluginContext *pContext = new CTestPluginContext(m_pPeekApp, this);
    if (pContext == NULL) return PLUGIN_RESULT_ERROR;

    if (ioParams->fContextFlags == kContextType_Global) {
        m_pGlobalContext = pContext;
    }

    if (pContext != NULL) {
        pContext->Init(ioParams);
        m_aContextList.Add(pContext);
        if (GetAPIVersion() < kPluginAPIVersion12) {
            AddListener(pContext);
        }
        *(ioParams->fContextPtr) = pContext;

        // Cannot get this to work...
        if (ioParams->fContextFlags == kContextType_CaptureWindow) {
            int nResult = DoSetPacketListColumn(
                pContext,
                &s_ColumnID,
                _T("My Column"),
                _T("My Column"),
                false,
                100,
                kPluginColumnAlighment_Left);
            if (nResult != PLUGIN_RESULT_SUCCESS) {
                int value = nResult; // set breakpoint here...
            }
        }
    }
}


The plugin still loads sucessfully, but the "My Column" is not available to be shown in the packet list from the Options. Any help would be greatly appreciated.

RE: Unable to add a column to the packet list

Posted: Tue Jul 20, 2010 5:59 pm
by gdvc84@motorola.com
Well, looking at the API, it looks like you've set the defaultVisibility to "False". Did you try to right click on the column labels and see whether "My Column" is present or not?

RE: RE: Unable to add a column to the packet list

Posted: Tue Jul 20, 2010 6:28 pm
by gdvc84@motorola.com
OK, I got this to work by putting it inside Init() method of your C*Context class.

Looks like OP does not know about the pContext parameter that you are passing. Will leave it to someone from WildPackets to give a detailed explanation if needed :)

RE: RE: RE: Unable to add a column to the packet list

Posted: Wed Jul 21, 2010 9:10 am
by matman13
Thanks so much, gdvc84!!! That fixed it for me.

RE: RE: RE: RE: Unable to add a column to the packet list

Posted: Wed Jul 21, 2010 11:54 am
by Spacepacket
Thanks gdvc84!

matman13, is you call DoSetPacketListColumn() from within the context object, you do not have to pass the context pointer.

Once you created the column, were you able to put stuff in it?

Here is a sample:


// ----------------------------------------------------------------------------
// OnDrawPacketListCell
// ----------------------------------------------------------------------------

int CMyContext::OnDrawPacketListCell(
PluginDrawPacketListCellParam* ioParams )
{
_tcscpy( ioParams->fOutCellText, _T("Stuff") );
ioParams->fInCellTextMaxLength = _tcslen(ioParams->fOutCellText) * 2;

return 0;
}

-spacepacket

RE: RE: RE: RE: RE: Unable to add a column to the packet lis

Posted: Wed Jul 21, 2010 12:10 pm
by matman13
Spacepacket, yes, I was able to insert text into the column using code very similar to what you've shown. Out of curiosity, does the "fInCellTextMaxLength" need to be set as you've shown? I didn't update the field in my project, and the text shows fine. The field name indicates it is an input parameter, so is there any reason to set this value?

I'm beginning to build up my functionality now. Thanks for the help!

RE: RE: RE: RE: RE: RE: Unable to add a column to the packet

Posted: Wed Jul 21, 2010 1:44 pm
by Spacepacket
I think it needs to be set. Maybe there is random value in there?

RE: RE: RE: RE: RE: RE: RE: Unable to add a column to the pa

Posted: Thu Jul 22, 2010 8:33 am
by matman13
It didn't look random to me. It was set to 1024 when I checked it in the debugger.

RE: RE: RE: RE: RE: RE: RE: RE: Unable to add a column to th

Posted: Thu Jul 22, 2010 3:15 pm
by Spacepacket
I checked the OmniPeek code. Look like I was wrong. That value is the size of the buffer, not the length of the string. It does not look like you need to specify the length of the string. It must do a strlen() on what you give.