Пример #1
0
        /// <summary>
        /// Used to ask and then print out extended information about a specific frame
        /// </summary>
        /// <param name="hParsedFrame">Parsed Frame</param>
        /// <param name="frameNumber">Frame Number to Display</param>
        /// <param name="command">Command Line Parameters</param>
        private static void PrintParsedFrameInformation(IntPtr hParsedFrame, uint frameNumber, CommandLineArguments command)
        {
            uint   errno;
            uint   ulFieldCount;
            string ds = "Frame #" + (frameNumber + 1);

            // Is Selected
            if (command.IsSelected(frameNumber))
            {
                ds += " (Selected)";
            }

            // Get Frame Timestamp
            ulong timestamp;

            errno = NetmonAPI.NmGetFrameTimeStamp(hParsedFrame, out timestamp);
            if (errno == ERROR_SUCCESS)
            {
                ds += " " + DateTime.FromFileTimeUtc((long)timestamp).ToString();
            }
            else
            {
                ds += " Timestamp Couldn't be Retrieved.";
            }

            Console.WriteLine(ds);
            Console.Write("Print Frame Info? (y/n) ");

            char key = Console.ReadKey().KeyChar;

            Console.WriteLine();

            if (key == 'y' || key == 'Y')
            {
                errno = NetmonAPI.NmGetFieldCount(hParsedFrame, out ulFieldCount);

                for (uint fid = 0; fid < ulFieldCount; fid++)
                {
                    // Get Field Name
                    char[] name = new char[BUFFER_SIZE * 2];
                    unsafe
                    {
                        fixed(char *pstr = name)
                        {
                            errno = NetmonAPI.NmGetFieldName(hParsedFrame, fid, NmParsedFieldNames.NamePath, BUFFER_SIZE * 2, pstr);
                        }
                    }

                    if (errno == ERROR_SUCCESS)
                    {
                        Console.Write(new string(name).Replace("\0", string.Empty) + ": ");
                    }
                    else
                    {
                        Console.WriteLine("Error Retrieving Field, NmGetFieldName Returned: " + errno);
                        continue;
                    }

                    // Get Field Value as displayed in Netmon UI
                    name = new char[BUFFER_SIZE];
                    unsafe
                    {
                        fixed(char *pstr = name)
                        {
                            errno = NetmonAPI.NmGetFieldName(hParsedFrame, fid, NmParsedFieldNames.FieldDisplayString, BUFFER_SIZE, pstr);
                        }
                    }

                    if (errno == ERROR_SUCCESS)
                    {
                        Console.WriteLine(new string(name).Replace("\0", string.Empty));
                    }
                    else if (errno == ERROR_NOT_FOUND)
                    {
                        Program.PrintParsedFrameFieldValue(hParsedFrame, fid);
                    }
                    else
                    {
                        Console.WriteLine("Error Retrieving Value, NmGetFieldName Returned: " + errno);
                        continue;
                    }
                }

                Console.WriteLine();
            }
        }