You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133
  1. <html>
  2. <head>
  3. <title>C:\M\Projects\MessageSniffer\PKG-SNF-SDK-WIN_Work\PKG-SNF-SDK-WIN\CPPSample\main.cpp</title>
  4. <style>
  5. body { background-color: #ffffff; font-family: "Courier New"; font-size:10.0pt; font-style: normal; font-weight: normal; text-decoration: none; }
  6. .se2 { color: #000000; background-color: #ffffff; } /* Window Text */
  7. .se17 { color: #800080; background-color: #ffffff; } /* Keyword */
  8. .se19 { color: #000080; background-color: #ffffff; } /* Number */
  9. .se20 { color: #008080; background-color: #ffffff; } /* String */
  10. .se22 { color: #808000; background-color: #ffffff; } /* Preprocessor */
  11. .se23 { color: #800000; background-color: #ffffff; } /* Punctuation */
  12. .se24 { color: #c04000; background-color: #ffffff; } /* Library Symbol */
  13. .se25 { color: #000000; background-color: #ffffff; } /* Operator */
  14. .se28 { color: #000000; background-color: #ffffff; font-weight: bolder; } /* Function */
  15. .se49 { color: #008000; background-color: #ffffff; font-style: italic; } /* Comment */
  16. .se50 { color: #004080; background-color: #ffffff; font-style: italic; } /* Comment */
  17. .se55 { color: #000000; background-color: #ffffff; } /* Window Text */
  18. .se57 { color: #000080; background-color: #ffffff; } /* Number */
  19. </style>
  20. </head>
  21. <body>
  22. <pre>
  23. <span class="se49">// main.cpp SNF-SDK-WIN CPP OEM Demonstration Code</span>
  24. <span class="se49">// Copyright (C) 2009 ARM Research Labs, LLC</span>
  25. <span class="se49">//</span>
  26. <span class="se49">// This app simply exercises the API provided by snfmultidll.</span>
  27. <span class="se22">#include</span><span class="se2"> </span><span class="se23">&lt;</span><span class="se2">iostream</span><span class="se23">&gt;</span>
  28. <span class="se22">#include</span><span class="se2"> </span><span class="se23">&lt;</span><span class="se2">string</span><span class="se23">&gt;</span>
  29. <span class="se22">#include</span><span class="se2"> </span><span class="se20">&quot;../include/snfmultidll.h&quot;</span>
  30. <span class="se17">using</span><span class="se2"> </span><span class="se17">namespace</span><span class="se2"> </span><span class="se24">std</span><span class="se25">;</span>
  31. <span class="se50">//// Setup the basics we need to run this test.</span>
  32. <span class="se17">const</span><span class="se2"> </span><span class="se24">string</span><span class="se2"> </span><span class="se55">LicenseID</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se20">&quot;licensid&quot;</span><span class="se25">;</span><span class="se2"> </span><span class="se49">// SNF License ID can be passed</span>
  33. <span class="se17">const</span><span class="se2"> </span><span class="se24">string</span><span class="se2"> </span><span class="se55">Authentication</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se20">&quot;authenticationxx&quot;</span><span class="se25">;</span><span class="se2"> </span><span class="se49">// directly or read from the</span>
  34. <span class="se17">const</span><span class="se2"> </span><span class="se24">string</span><span class="se2"> </span><span class="se55">ConfigurationPath</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se20">&quot;snf_engine.xml&quot;</span><span class="se25">;</span><span class="se2"> </span><span class="se49">// configuration. OEMs go direct!</span>
  35. <span class="se17">const</span><span class="se2"> </span><span class="se17">unsigned</span><span class="se2"> </span><span class="se17">int</span><span class="se2"> </span><span class="se55">IPToTest</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se57">0x0c22384e</span><span class="se25">;</span><span class="se2"> </span><span class="se49">// Same as IP 12.34.56.78</span>
  36. <span class="se17">const</span><span class="se2"> </span><span class="se24">string</span><span class="se2"> </span><span class="se55">SampleMessage</span><span class="se2"> </span><span class="se25">=</span>
  37. <span class="se2"> </span><span class="se20">&quot;Received: from mx-out.example.com [12.34.56.78] (HELO Somebody)\r\n&quot;</span>
  38. <span class="se2"> </span><span class="se20">&quot; by mx-in.example.com (nosuchserver v1.0) for nobody@example.com\r\n&quot;</span>
  39. <span class="se2"> </span><span class="se20">&quot;From: &lt;somebody@example.com&gt;\r\n&quot;</span>
  40. <span class="se2"> </span><span class="se20">&quot;To: &lt;nobody@example.com&gt;\r\n&quot;</span>
  41. <span class="se2"> </span><span class="se20">&quot;Subject: Nothing to see here\r\n&quot;</span>
  42. <span class="se2"> </span><span class="se20">&quot;\r\n&quot;</span>
  43. <span class="se2"> </span><span class="se20">&quot;So this is the big thing that's not here to see.\r\n&quot;</span>
  44. <span class="se2"> </span><span class="se20">&quot;I thought it would be more interesting than this.\r\n&quot;</span>
  45. <span class="se2"> </span><span class="se20">&quot;\r\n&quot;</span>
  46. <span class="se2"> </span><span class="se20">&quot;_M\r\n&quot;</span>
  47. <span class="se2"> </span><span class="se20">&quot;.\r\n&quot;</span><span class="se25">;</span>
  48. <span class="se50">//// Here is a simple example. Startup, exercise the API, shut down.</span>
  49. <span class="se50">//// Note that we're doing this in a very &quot;C&quot; style becuase the DLL API is C</span>
  50. <span class="se17">int</span><span class="se2"> </span><span class="se28">main</span><span class="se2">() </span><span class="se23">{</span>
  51. <span class="se2"> </span><span class="se17">int</span><span class="se2"> </span><span class="se55">Result</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se19">0</span><span class="se25">;</span>
  52. <span class="se2"> </span><span class="se55">Result</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se28">startupSNF</span><span class="se2">(</span><span class="se17">const_cast</span><span class="se25">&lt;</span><span class="se17">char</span><span class="se25">*&gt;</span><span class="se2">(</span><span class="se55">ConfigurationPath</span><span class="se2">.</span><span class="se28">c_str</span><span class="se2">()))</span><span class="se25">;</span>
  53. <span class="se49">// Result = startupSNFAuthenticated(</span>
  54. <span class="se49">// const_cast&lt;char*&gt;(ConfigurationPath.c_str()),</span>
  55. <span class="se49">// const_cast&lt;char*&gt;(LicenseID.c_str()),</span>
  56. <span class="se49">// const_cast&lt;char*&gt;(Authentication.c_str())</span>
  57. <span class="se49">// );</span>
  58. <span class="se2"> </span><span class="se24">cout</span><span class="se2"> </span><span class="se25">&lt;&lt;</span><span class="se2"> </span><span class="se20">&quot;Started with config &quot;</span><span class="se2"> </span><span class="se25">&lt;&lt;</span><span class="se2"> </span><span class="se55">ConfigurationPath</span><span class="se2"> </span><span class="se25">&lt;&lt;</span><span class="se2"> </span><span class="se20">&quot; Result: &quot;</span><span class="se2"> </span><span class="se25">&lt;&lt;</span><span class="se2"> </span><span class="se55">Result</span><span class="se2"> </span><span class="se25">&lt;&lt;</span><span class="se2"> </span><span class="se24">endl</span><span class="se25">;</span>
  59. <span class="se2"> </span><span class="se49">// IP tests can be done asynchrounously - they do not have to be part of any particular scan.</span>
  60. <span class="se2"> </span><span class="se55">Result</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se28">testIP</span><span class="se2">(</span><span class="se55">IPToTest</span><span class="se2">)</span><span class="se25">;</span>
  61. <span class="se2"> </span><span class="se24">cout</span><span class="se2"> </span><span class="se25">&lt;&lt;</span><span class="se2"> </span><span class="se20">&quot;IP test result: &quot;</span><span class="se2"> </span><span class="se25">&lt;&lt;</span><span class="se2"> </span><span class="se55">Result</span><span class="se2"> </span><span class="se25">&lt;&lt;</span><span class="se2"> </span><span class="se24">endl</span><span class="se25">;</span>
  62. <span class="se2"> </span><span class="se17">double</span><span class="se2"> </span><span class="se55">IPReputation</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se28">getIPReputation</span><span class="se2">(</span><span class="se55">IPToTest</span><span class="se2">)</span><span class="se25">;</span>
  63. <span class="se2"> </span><span class="se24">cout</span><span class="se2"> </span><span class="se25">&lt;&lt;</span><span class="se2"> </span><span class="se20">&quot;IP Reputation: &quot;</span><span class="se2"> </span><span class="se25">&lt;&lt;</span><span class="se2"> </span><span class="se55">IPReputation</span><span class="se2"> </span><span class="se25">&lt;&lt;</span><span class="se2"> </span><span class="se24">endl</span><span class="se25">;</span>
  64. <span class="se2"> </span><span class="se49">// Messgae scans happen in a scan, read, close cycle as shown inside this loop.</span>
  65. <span class="se2"> </span><span class="se17">const</span><span class="se2"> </span><span class="se17">int</span><span class="se2"> </span><span class="se55">NumberOfScans</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se19">10</span><span class="se25">;</span>
  66. <span class="se2"> </span><span class="se17">for</span><span class="se2">(</span><span class="se17">int</span><span class="se2"> </span><span class="se55">i</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se19">0</span><span class="se25">;</span><span class="se2"> </span><span class="se55">i</span><span class="se2"> </span><span class="se25">&lt;</span><span class="se2"> </span><span class="se55">NumberOfScans</span><span class="se25">;</span><span class="se2"> </span><span class="se55">i</span><span class="se25">++</span><span class="se2">) </span><span class="se23">{</span>
  67. <span class="se2"> </span><span class="se49">// Show how the IP reputation changes over time.</span>
  68. <span class="se2"> </span><span class="se17">double</span><span class="se2"> </span><span class="se55">IPReputation</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se28">getIPReputation</span><span class="se2">(</span><span class="se55">IPToTest</span><span class="se2">)</span><span class="se25">;</span>
  69. <span class="se2"> </span><span class="se24">cout</span><span class="se2"> </span><span class="se25">&lt;&lt;</span><span class="se2"> </span><span class="se20">&quot;IP Reputation: &quot;</span><span class="se2"> </span><span class="se25">&lt;&lt;</span><span class="se2"> </span><span class="se55">IPReputation</span><span class="se2"> </span><span class="se25">&lt;&lt;</span><span class="se2"> </span><span class="se24">endl</span><span class="se25">;</span>
  70. <span class="se2"> </span><span class="se49">// Scan a message from a buffer.</span>
  71. <span class="se2"> </span><span class="se17">int</span><span class="se2"> </span><span class="se55">SetupTime</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se19">12</span><span class="se25">;</span>
  72. <span class="se2"> </span><span class="se17">int</span><span class="se2"> </span><span class="se55">ScanHandle</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se19">0</span><span class="se25">;</span>
  73. <span class="se2"> </span><span class="se17">unsigned</span><span class="se2"> </span><span class="se17">char</span><span class="se25">*</span><span class="se2"> </span><span class="se55">MsgBuffer</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> (</span><span class="se17">unsigned</span><span class="se2"> </span><span class="se17">char</span><span class="se25">*</span><span class="se2">) </span><span class="se55">SampleMessage</span><span class="se2">.</span><span class="se28">c_str</span><span class="se2">()</span><span class="se25">;</span>
  74. <span class="se2"> </span><span class="se17">unsigned</span><span class="se2"> </span><span class="se17">int</span><span class="se2"> </span><span class="se55">MsgBufferLength</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> (</span><span class="se17">unsigned</span><span class="se2"> </span><span class="se17">int</span><span class="se2">) </span><span class="se55">SampleMessage</span><span class="se2">.</span><span class="se28">length</span><span class="se2">()</span><span class="se25">;</span>
  75. <span class="se2"> </span><span class="se55">ScanHandle</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se28">scanBuffer</span><span class="se2">(</span><span class="se55">MsgBuffer</span><span class="se2">, </span><span class="se55">MsgBufferLength</span><span class="se2">, </span><span class="se20">&quot;TestMessage&quot;</span><span class="se2">, </span><span class="se55">SetupTime</span><span class="se2">)</span><span class="se25">;</span>
  76. <span class="se2"> </span><span class="se24">cout</span><span class="se2"> </span><span class="se25">&lt;&lt;</span><span class="se2"> </span><span class="se20">&quot;Scan Handle: &quot;</span><span class="se2"> </span><span class="se25">&lt;&lt;</span><span class="se2"> </span><span class="se55">ScanHandle</span><span class="se2"> </span><span class="se25">&lt;&lt;</span><span class="se2"> </span><span class="se24">endl</span><span class="se25">;</span>
  77. <span class="se2"> </span><span class="se49">// Retrieve the X-Headers for the scan.</span>
  78. <span class="se2"> </span><span class="se17">char</span><span class="se25">*</span><span class="se2"> </span><span class="se55">XHeadersBuffer</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se19">0</span><span class="se25">;</span>
  79. <span class="se2"> </span><span class="se17">int</span><span class="se2"> </span><span class="se55">XHeadersLength</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se19">0</span><span class="se25">;</span>
  80. <span class="se2"> </span><span class="se17">int</span><span class="se2"> </span><span class="se55">ScanResult</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se19">0</span><span class="se25">;</span>
  81. <span class="se2"> </span><span class="se55">ScanResult</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se28">getScanXHeaders</span><span class="se2">(</span><span class="se55">ScanHandle</span><span class="se2">, </span><span class="se25">&amp;</span><span class="se55">XHeadersBuffer</span><span class="se2">, </span><span class="se25">&amp;</span><span class="se55">XHeadersLength</span><span class="se2">)</span><span class="se25">;</span>
  82. <span class="se2"> </span><span class="se24">string</span><span class="se2"> </span><span class="se28">XHeaders</span><span class="se2">(</span><span class="se55">XHeadersBuffer</span><span class="se2">)</span><span class="se25">;</span>
  83. <span class="se2"> </span><span class="se49">// Close the scan.</span>
  84. <span class="se2"> </span><span class="se55">Result</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se28">closeScan</span><span class="se2">(</span><span class="se55">ScanHandle</span><span class="se2">)</span><span class="se25">;</span>
  85. <span class="se2"> </span><span class="se24">cout</span><span class="se2"> </span><span class="se25">&lt;&lt;</span><span class="se2"> </span><span class="se20">&quot;Scan Close Result: &quot;</span><span class="se2"> </span><span class="se25">&lt;&lt;</span><span class="se2"> </span><span class="se55">Result</span><span class="se2"> </span><span class="se25">&lt;&lt;</span><span class="se2"> </span><span class="se24">endl</span><span class="se25">;</span>
  86. <span class="se2"> </span><span class="se49">// X- headers were captured in a string BEFORE closing the scan so we can</span>
  87. <span class="se2"> </span><span class="se49">// use them here.</span>
  88. <span class="se2"> </span><span class="se24">cout</span><span class="se2"> </span><span class="se25">&lt;&lt;</span><span class="se2"> </span><span class="se20">&quot;Scan result code: &quot;</span><span class="se2"> </span><span class="se25">&lt;&lt;</span><span class="se2"> </span><span class="se55">ScanResult</span><span class="se2"> </span><span class="se25">&lt;&lt;</span><span class="se2"> </span><span class="se24">endl</span><span class="se25">;</span>
  89. <span class="se2"> </span><span class="se24">cout</span><span class="se2"> </span><span class="se25">&lt;&lt;</span><span class="se2"> </span><span class="se20">&quot;Scan X- headers: &quot;</span><span class="se2"> </span><span class="se25">&lt;&lt;</span><span class="se2"> </span><span class="se55">XHeaders</span><span class="se2"> </span><span class="se25">&lt;&lt;</span><span class="se2"> </span><span class="se24">endl</span><span class="se25">;</span>
  90. <span class="se2"> </span><span class="se23">}</span>
  91. <span class="se2"> </span><span class="se49">// Now that all scanning is done we shut down.</span>
  92. <span class="se2"> </span><span class="se55">Result</span><span class="se2"> </span><span class="se25">=</span><span class="se2"> </span><span class="se28">shutdownSNF</span><span class="se2">()</span><span class="se25">;</span>
  93. <span class="se2"> </span><span class="se17">return</span><span class="se2"> </span><span class="se55">Result</span><span class="se25">;</span>
  94. <span class="se23">}</span>
  95. </pre>
  96. </body>
  97. </html>