📄 dcomshow.cpp
字号:
/* dcomShow.cpp - DCOM extended show routines *//* Copyright (c) 2001 Wind River Systems, Inc. *//*modification history--------------------01j,22apr02,nel SPR#76087. Make read routine return 0 when buffer empty instead of ee to make sure that long loops don't occur.01i,18feb02,nel SPR#73368. Add mutex to packet processing routines to prevent mixed output to telnet/serial port.01h,17dec01,nel Add include symbol for diab build.01g,10dec01,dbs diab build01f,06dec01,nel Add listener socket to enable retrieval of information via telnet.01e,19oct01,nel Correct minor typo.01d,03oct01,nel Add in direction indication.01c,28sep01,nel Add remaining code comments.01b,25sep01,nel Correct logic in ReadBytes routine.01a,20aug01,nel written*//*DESCRIPTIONThis module implements a packet decoding mechanism that allows VxDCOM networktraffic to be displayed. Network data is captured directly before anymarshalling/unmarshalling. This data is then decoded by a separate algorithmfrom the VxDCOM marshalling/unmarshalling code.All system GUIDs are decoded into their symbolic representations. To haveGUIDs decoded for user CoClasses the COM Track mechanism must be enabled. Thefollowing should be added to the build settings for each CoClass:-DVXDCOM_COMTRACK_LEVEL=1There are no user callable functions in this module. Including the symbolINCLUDE_DCOM_SHOW in the kernel will enable the facility and all receivedDCOM network traffic will be decoded and output. Output goes by defaultto the console device.If the configuration parameter VXDCOM_DCOM_SHOW_PORT is set to a valid,unused port number a telnet style client can be connected to this portand all output will be directed to this client. Only one client can beconnected at one time. If a port number of zero is given then this facilitywill be disabled and all output will be directed to the console device.This facility carries a high performance penalty and is only intendedto provide debug information to Wind River Customer Support. It shouldnot be included otherwise.*//* includes */#include <stdio.h>#include <string>#include <iostream>#include "ReactorTypes.h"#include "vxidl.h"#include "private/comMisc.h"#include "private/DebugHooks.h"#include "rpcDceProto.h"#include "comShow.h"#include "private/comStl.h"#include "dcomLib.h"#include "taskLib.h"#include "opccomn.h"#include "opcda.h"#include "opc_ae.h"#include "orpc.h"#include "OxidResolver.h"#include "RemoteActivation.h"#include "RemUnknown.h"#include "rpcDceProto.h"/* Include symbol for diab */extern "C" int include_vxdcom_dcomShow (void) { return 0; }/* defines *//* Entry in the lookup table */#define TABLE_ENTRY(name) {#name, name}/* Entry in common GUID search table */#define GUID_STR(c) {&c, #c}/* Output and indented packet header */#define NAME(n) RpcIndentBlock _name (n)/* Output a field name, doesn't increase indent */#define FIELD(n,v) {RpcName _name(n); output(v, false); _name.dummy (); }/* Common virtual functions defined in all the base classes of DataPacket */#define COMMON_VIRTUALS() \ private: \ virtual BYTE ReadBYTE \ ( \ const char * pName, \ TABLE * pDecodeTable = NULL \ ) = NULL; \ virtual void ReadARRAY \ ( \ const char * pName, \ ULONG number) = NULL; \ virtual USHORT ReadUSHORT \ ( \ const char * pName, \ bool swap = true, \ TABLE * pDecodeTable = NULL, \ bool doEndOfLine = true \ ) = NULL; \ virtual ULONG ReadULONG \ ( \ const char * name, \ bool swap = true, \ TABLE * pDecodeTable = NULL \ ) = NULL; \ virtual void setFlags (const BYTE flags) = NULL; \ virtual BYTE getFlags () = NULL; \ virtual BYTE * ReadBytes (DWORD number, bool swap = true) = NULL; \ virtual const char * getChannelBinding () = NULL; \ virtual DWORD BytesRemaining () = NULL;#define PRINT_STR(str) \ if CHECKHOOK(pDcomShowPrintStr) \ HOOK(pDcomShowPrintStr)(str); \ else \ printf (str)/* typedefs */typedef STL_MAP(string, GUID) CTXID_MAP;typedef struct tagTable { char * m_name; ULONG m_value; } TABLE;typedef struct _GUID_ELEM { const GUID * guid; const char * pName; } GUID_ELEM;/* locals *//* Mutext used to lock critcal sections */static VxMutex s_mutex;/* presCtxID lookp table */static CTXID_MAP ctxIdMap;/* Message name lookup table */static TABLE rpcCnTypesTable [] = { TABLE_ENTRY(RPC_CN_PKT_REQUEST), TABLE_ENTRY(RPC_CN_PKT_RESPONSE), TABLE_ENTRY(RPC_CN_PKT_FAULT), TABLE_ENTRY(RPC_CN_PKT_BIND), TABLE_ENTRY(RPC_CN_PKT_BIND_ACK), TABLE_ENTRY(RPC_CN_PKT_BIND_NAK), TABLE_ENTRY(RPC_CN_PKT_ALTER_CONTEXT), TABLE_ENTRY(RPC_CN_PKT_ALTER_CONTEXT_RESP), TABLE_ENTRY(RPC_CN_PKT_AUTH3), TABLE_ENTRY(RPC_CN_PKT_SHUTDOWN), TABLE_ENTRY(RPC_CN_PKT_REMOTE_ALERT), TABLE_ENTRY(RPC_CN_PKT_ORPHANED), {NULL, 0} };/* Common GUID lookup table */static GUID_ELEM guidList [] = { GUID_STR(GUID_NULL), GUID_STR(CLSID_StdMarshal), GUID_STR(IID_IWindTypes), GUID_STR(IID_IUnknown), GUID_STR(IID_IClassFactory), GUID_STR(IID_IMultiQI), GUID_STR(IID_IRegistry), GUID_STR(IID_IEnumGUID), GUID_STR(IID_IEnumString), GUID_STR(IID_IEnumUnknown), GUID_STR(IID_IMalloc), GUID_STR(IID_IConnectionPoint), GUID_STR(IID_IConnectionPointContainer), GUID_STR(IID_IEnumConnections), GUID_STR(IID_IEnumConnectionPoints), GUID_STR(IID_IOPCEventServer), GUID_STR(IID_IOPCEventSubscriptionMgt), GUID_STR(IID_IOPCEventAreaBrowser), GUID_STR(IID_IOPCEventSink), GUID_STR(IID_IOPCShutdown), GUID_STR(IID_IOPCCommon), GUID_STR(IID_IOPCServerList), GUID_STR(IID_IOPCServer), GUID_STR(IID_IOPCServerPublicGroups), GUID_STR(IID_IOPCBrowseServerAddressSpace), GUID_STR(IID_IOPCGroupStateMgt), GUID_STR(IID_IOPCPublicGroupStateMgt), GUID_STR(IID_IOPCSyncIO), GUID_STR(IID_IOPCAsyncIO), GUID_STR(IID_IOPCItemMgt), GUID_STR(IID_IEnumOPCItemAttributes), GUID_STR(IID_IOPCDataCallback), GUID_STR(IID_IOPCAsyncIO2), GUID_STR(IID_IOPCItemProperties), GUID_STR(IID_IMarshal), GUID_STR(IID_ISequentialStream), GUID_STR(IID_IStream), GUID_STR(IID_ORPCTypes), GUID_STR(IID_IOrpcProxy), GUID_STR(IID_IOrpcClientChannel), GUID_STR(IID_IOXIDResolver), GUID_STR(IID_ISystemActivator), GUID_STR(IID_IRemoteActivation), GUID_STR(IID_IRemUnknown), GUID_STR(IID_IRpcDceTypes), {{0,}, NULL}};/* Current level of indentation */static int indentLevel = 0;static int s_listenPort = 0;static int s_outputSocket = 0;/* Forwards definitions */extern "C" void networkPrint (const char * str);extern "C" void startListenerTask (void);/* Common functions *//**************************************************************************** findGuid - finds a symbolic rep of a GUID.** Looks up the supplied GUID and returns a symbolic rep of it. The lookup* first looks in an internal table of well known GUIDs. If it isn't found * in this it then looks it up in the list of GUIDs collected by the COM Track* mechanism. If it isn't found in this then the GUID is converted into a * string and returned.** RETURNS: a symbolic string rep of the given GUID.* NOMANUAL*/static const char * findGuid ( REFGUID value /* GUID to find */ ) { GUID_ELEM * pPtr = &(guidList [0]); /* search list of well known GUIDS */ while (pPtr->pName) { if (value == *(pPtr->guid)) { return pPtr->pName; } pPtr++; } /* Not in well known list so search the COMTRACK list */ const char * pStr = VxComTrack::theInstance ()->findGUID (value); if (pStr) return pStr; /* All else has failed, return the GUID as a string */ return vxcomGUID2String (value); }/**************************************************************************** updateCtxTable - Adds/updates a ip/port/ctx id to the table.** This function adds an ip/port/ctx id to the table. The ip/port combination* is unique to a channel and the ctx id is unique to a channel.** RETURNS: nothing.* NOMANUAL*/static void updateCtxTable ( USHORT presCtxId, /* context id */ GUID id, /* GUID attached to ctx id */ const char * pChannelBinding /* ip/port combination */ ) { string key; key += pChannelBinding; key += ":"; key += presCtxId; ctxIdMap [key] = id; }/**************************************************************************** getFromCtxTable - get's the GUID from the map.** This function retrieves a GUID from the map based on ip/port/ctx id. If * the combination isn't present the string "UNKNOWN" is returned,* otherwise the output from findGUID is returned.** RETURNS: The symbolic rep of the GUID or "UNKNOWN".* NOMANUAL*/static const char * getFromCtxTable ( USHORT presCtxId, /* Context id */ const char * pChannelBinding /* ip/port binding */ ) { string key; CTXID_MAP::iterator it; key = pChannelBinding; key += ":"; key += presCtxId; it = ctxIdMap.find (key); if (it == ctxIdMap.end ()) { return "UNKNOWN"; } return findGuid (it->second); }/* Output functions *//**************************************************************************** indent - output the correct number of spaces to indent a line.** Output the correct number of spaces to indent a line.** RETURNS: None.* NOMANUAL*/static void indent () { int i; for (i = 0; i < indentLevel; i++) { PRINT_STR(" "); } }/**************************************************************************** indent - increases the current indent level by four.** Increases the current indent level by four.** RETURNS: None.* NOMANUAL*/static void padUp () { indentLevel += 4; }/**************************************************************************** padDown - decreases the current indent level by four.** Decreases the current indent level by four.** RETURNS: None.* NOMANUAL*/static void padDown () { indentLevel -= 4; if (indentLevel < 0) indentLevel = 0; }/**************************************************************************** output - output a string, with optional indent.** This function output's a string. If the indentLine parameter is set the* current indent number of spaces are output.** RETURNS: None.* NOMANUAL*/static void output ( const char * pValue, /* Data to output */ bool indentLine = false /* Indent line or not */ ) { if (indentLine) indent (); PRINT_STR(pValue); }/**************************************************************************** output - output a BYTE, with optional indent.** This function output's a BYTE. If the indentLine parameter is set the* current indent number of spaces are output.** RETURNS: None.* NOMANUAL*/static void output ( const BYTE value, /* Data to output */ bool indentLine = false /* Indent line or not */ ) { char line [3]; if (indentLine) indent (); sprintf (line, "%02X", ((int)value) & 0xFF); PRINT_STR(line); }/**************************************************************************** output - output an array of BYTE, with optional indent.** This function output's an array of BYTE. If the indentLine parameter is * set the current indent number of spaces are output.** RETURNS: None.* NOMANUAL*/static void output ( const BYTE value [], /* Data to output */ int length, /* Number of elements */ bool indentLine = false /* Indent line or not */ ) { int i; if (indentLine) indent (); for (i = 0; i < length; i++) output (value [i]); }/**************************************************************************** output - output a USHORT, with optional indent.** This function output's a USHORT. If the indentLine parameter is set the* current indent number of spaces are output.** RETURNS: None.* NOMANUAL*/static void output ( const USHORT value, /* Data to output */ bool indentLine = false /* Indent line or not */ ) { char line [5]; if (indentLine) indent (); sprintf (line, "%04X", ((int)value) & 0xFFFF); PRINT_STR(line); }/**************************************************************************** output - output a ULONG, with optional indent.** This function output's a ULONG. If the indentLine parameter is set the* current indent number of spaces are output.** RETURNS: None.* NOMANUAL*/static void output ( const ULONG value, /* Data to output */ bool indentLine = false /* Indent line or not */ ) { char line [9]; if (indentLine) indent (); sprintf (line, "%08lX", value); PRINT_STR(line); }/**************************************************************************** output - output an end of line.** Output's an end of line character.** RETURNS: None.* NOMANUAL*/static void endOfLine () { PRINT_STR ("\n"); }/**************************************************************************** output - output a space.** Output's a space.** RETURNS: None.* NOMANUAL*/static void outputSpace () { PRINT_STR (" "); }/**************************************************************************** output - output a dash.** Output's a dash.** RETURNS: None.* NOMANUAL*/static void outputDash () { PRINT_STR ("-"); }/* Utility class to display and indent a field name */class RpcName { public: /***************************************************************** * * RpcName::RpcName - Constructor. * * Output's the given name and indents if required. * * RETURNS: None. * NOMANUAL */ RpcName ( const char * pName, /* Field name */ bool indent = false /* Indent this name? */ ) { output (pName, true); output (":", false); if (indent) padUp (); } /***************************************************************** * * RpcName::RpcName - dummy. * * Dummy function that is used to get rid of a compiler warning. * * RETURNS: None. * NOMANUAL */ void dummy () {} };/*Utility class to display and indent a field name. The indentation is removed by the destructor*/ class RpcIndentBlock : RpcName {
⌨️ 快捷键说明
复制代码
Ctrl + C
搜索代码
Ctrl + F
全屏模式
F11
切换主题
Ctrl + Shift + D
显示快捷键
?
增大字号
Ctrl + =
减小字号
Ctrl + -