locked
Getting whole sctruct in C# defined in custome NPL RRS feed

  • Question

  • Hello,

    I would like to ask, if there is any way how to get complete structure defined in npl to struct in C#.

    For example:

    example.npl

    Protocol TEST{ 

    //[BuildConversationWithParent]
    UINT32 field;
    UINT16 field2;
    Struct test_struct {

    UINT8 field_in_struct1

    UINT16 field_in_struct2

    }

    }

    C# code

    struct testStruct{

    private UInt32 YMSG;
                UInt8 field_in_struct1;
                UInt16 field_in_struct2;

    }

    So is there any way how to copy struct in npl to C#.

    If i try to get it as a Byte[] (NetmonAPI.NmGetFieldValueByteArray) i`m getting it empty.

    Protocol that i`m trying to parse is too much complicated to declarating and accessing field by it`s Distinguished names.

    Thank you for any advice or hint.

    Tuesday, July 10, 2012 10:05 AM

Answers

  • Hi xjack,

    First, the API functions return error codes, so you need to pass in the byte array handle to the function for it to be filled with data.  I'd look at the sample expert example or other expert code linked to on our CodePlex site (http://nmexperts.codeplex.com) for examples of obtaining data using C#.

    Secondly, to do as you propose, assuming your protocol is well structured as would be in your case above (though you forgot field2), then you would probably want to use the NmGetRawFrame or NmGetPartialRawFrame functions to get the bytes for your whole payload at once to try and convert to the structure.

    Thanks,


    Michael Hawker | Program Manager | Network Monitor

    • Marked as answer by Jan Pluskal Wednesday, July 11, 2012 6:54 PM
    Tuesday, July 10, 2012 4:50 PM

All replies

  • Hi xjack,

    First, the API functions return error codes, so you need to pass in the byte array handle to the function for it to be filled with data.  I'd look at the sample expert example or other expert code linked to on our CodePlex site (http://nmexperts.codeplex.com) for examples of obtaining data using C#.

    Secondly, to do as you propose, assuming your protocol is well structured as would be in your case above (though you forgot field2), then you would probably want to use the NmGetRawFrame or NmGetPartialRawFrame functions to get the bytes for your whole payload at once to try and convert to the structure.

    Thanks,


    Michael Hawker | Program Manager | Network Monitor

    • Marked as answer by Jan Pluskal Wednesday, July 11, 2012 6:54 PM
    Tuesday, July 10, 2012 4:50 PM
  • Thank you, for such a quick response.

    I looked into ExpertExample linked to CodePlex and i`ve got an idea how to fill given C# struct.
    By default all fields are sorted sequently by NPL parser and i can iterate this sequence and try to fill given structure.

    I have tried it and it worked fine, until i use optimalization NetmonAPI.NmAddField and NetmonAPI.NmAddProperty.
    When i add for example NmAddField(myFrameParserConfig, L"ethernet", &Ethernet); it adds only field ethernet, but not fieds that ethernet contains.

    So i would like to ask if there is any way or workaround how to add to myFrameParserConfig all fields that contain structure defined in NPL parser without explicitely enumeratin them.

    Thanks
    Thursday, July 12, 2012 9:22 AM
  • Hi xjack,

    The NmAddField and Property functions are for optimization, so by using those you can't enumerate the protocol anymore.  It's either one or the other.

    If you're going to enumerate the full protocol anyway, you probably wouldn't gain any performance by just listing them all ahead of time with the NmAddField/Property functions.

    I hope that answers your questions, otherwise maybe you can provide more details on your end goals and what you're trying to accomplish with your program.

    Thanks,


    Michael Hawker | Program Manager | Network Monitor

    Thursday, July 12, 2012 10:16 PM