Thursday, September 17, 2009

Test12

Basic NPL Example

See Also

The following code illustrates a basic NPL parser used as an example in the Writing an NPL Parser section. It is included in the default set of Network Monitor parsers as Hsrp.npl.



Hot Standby Router Protocol

Copy Code

//File name: Hsrp.npl

Table HSRPOpcodeTable

{

switch(value)

{

case 0x00 : "Hello";

case 0x01 : "Coup";

case 0x02 : "Resign";

default : "Unknown Code";

}

}



Table HSRPStateTable

{

switch(value)

{

case 0x00 : "Initial";

case 0x01 : "Learn";

case 0x02 : "Listen";

case 0x04 : "Speak";

case 0x08 : "Standby";

case 0x10 : "Active";

default : "Unknown Code";

}

}



[ RegisterAfter (UDP.http, Hsrp, 1985) ]

Protocol HSRP = FormatString("Opcode = %s, State = %s",

HSRPOpcodeTable(UINT8(FrameData, Offset + 1)),

HSRPStateTable(UINT8(FrameData, Offset + 2)))

{

UINT8 Version;



UINT8 Opcode = FormatString("%s (%u)", HSRPOpcodeTable(this), this);

UINT8 State = FormatString("%s (%d)", HSRPStateTable(this), this)

{

UINT8 Bit0_2:3 = FormatString("(%s) Reserved", this.ToBitString);

UINT8 Bit3:1 = FormatString(" (%s) %s", this.ToBitString, this ? "Active" : "");

UINT8 Bit4:1 = FormatString(" (%s) %s", this.ToBitString, this ? "Standby" : "");

UINT8 Bit5:1 = FormatString(" (%s) %s", this.ToBitString, this ? "Speak" : "");

UINT8 Bit6:1 = FormatString(" (%s) %s", this.ToBitString, this ? "Listen" : "");

UINT8 Bit7:1 = FormatString(" (%s) %s", this.ToBitString, this ? "Learn" : "");

};



switch(Opcode)

{

case 0:

struct

{

UINT8 Hellotime;

UINT8 Holdtime;

}

default:

BLOB(2) ImplementationSpecificData;

}



UINT8 Priority;

UINT8 Group;

UINT8 Reserved;



AsciiString(8) AuthenticationData;

switch

{

case FrameOffset + 4 <= FrameLength:

IPv4Address VirtualIPAddress;

}

}







See Also

Concepts

Writing an NPL Parser



Other Resources

NPL Examples







--------------------------------------------------------------------------------






Constant Definitions

See Also

This example contains definitions for all NPL basic data types. It is included to enable compiling the examples. Sparser lists the files required for compilation.



Copy Code

// File name: constant.npl

// Byte order constants



const LittleEndian = 0;

const BigEndian = 1;



// Bool Constants



const TRUE = 1;

const FALSE = 0;



// Address Constants



const Broadcast = 0xFFFFFFFFFFFF;



// Protocol Class for parser errors



const ParserErrorProtocolClassPublic = 1;

const ParserErrorProtocolClassWindows = 2;

const ParserErrorProtocolClassMsOffice = 3;



// Conversation Status Constants



const UnknownState = 0;

const HalfConnected = 1;

const Connected = 2;

const FinWait1 = 3;

const FinWait2 = 5;

const Disconnected = 4;



// Conversation Timeout Constants



const EnableConversationTimeout = TRUE;

const DefaultConversationTimeout = 180;



const IPv4ConversationTimeout = 180;

const TCPConversationTimeout = 180;

const UDPConversationTimeout = 180;



// Add to property flags



const ADD_TO_PROPERTY_FLAG_NO_DUPLICATES = 0x00000004;

const ADD_TO_PROPERTY_FLAG_NO_ZERO = 0x00000008;







See Also

Other Resources

NPL Examples







--------------------------------------------------------------------------------





TestEnd

2 comments:

  1. pilitangbegin



    [ RegisterAfter (UDP.http, Hsrp, 1985) ]

    Protocol HSRP = FormatString("Opcode = %s, State = %s",

    HSRPOpcodeTable(UINT8(FrameData, Offset + 1)),

    HSRPStateTable(UINT8(FrameData, Offset + 2)))

    {

    UINT8 Version;



    UINT8 Opcode = FormatString("%s (%u)", HSRPOpcodeTable(this), this);

    UINT8 State = FormatString("%s (%d)", HSRPStateTable(this), this)

    {

    UINT8 Bit0_2:3 = FormatString("(%s) Reserved", this.ToBitString);

    UINT8 Bit3:1 = FormatString(" (%s) %s", this.ToBitString, this ? "Active" : "");

    UINT8 Bit4:1 = FormatString(" (%s) %s", this.ToBitString, this ? "Standby" : "");

    UINT8 Bit5:1 = FormatString(" (%s) %s", this.ToBitString, this ? "Speak" : "");

    UINT8 Bit6:1 = FormatString(" (%s) %s", this.ToBitString, this ? "Listen" : "");

    UINT8 Bit7:1 = FormatString(" (%s) %s", this.ToBitString, this ? "Learn" : "");
    pilitangfirstend
    jljjlj
    pilitangend

    ReplyDelete
  2. pilitangbegin



    [ RegisterAfter (UDP.http, Hsrp, 1985) ]

    Protocol HSRP = FormatString("Opcode = %s, State = %s",

    HSRPOpcodeTable(UINT8(FrameData, Offset + 1)),

    HSRPStateTable(UINT8(FrameData, Offset + 2)))

    {

    UINT8 Version;



    UINT8 Opcode = FormatString("%s (%u)", HSRPOpcodeTable(this), this);

    UINT8 State = FormatString("%s (%d)", HSRPStateTable(this), this)

    {

    UINT8 Bit0_2:3 = FormatString("(%s) Reserved", this.ToBitString);

    UINT8 Bit3:1 = FormatString(" (%s) %s", this.ToBitString, this ? "Active" : "");

    UINT8 Bit4:1 = FormatString(" (%s) %s", this.ToBitString, this ? "Standby" : "");

    UINT8 Bit5:1 = FormatString(" (%s) %s", this.ToBitString, this ? "Speak" : "");

    UINT8 Bit6:1 = FormatString(" (%s) %s", this.ToBitString, this ? "Listen" : "");

    UINT8 Bit7:1 = FormatString(" (%s) %s", this.ToBitString, this ? "Learn" : "");
    pilitangfirstend
    jljjlj
    pilitangend

    ReplyDelete