Source code of Windows XP (NT5)
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.

1110 lines
43 KiB

  1. WinSNMP v2.0 Addendum
  2. Document version information:
  3. November 1, 1997 - Initial Release Version
  4. December 5, 1997 - Typos wrt SnmpListen() params fixed
  5. Document contents information:
  6. I - Introduction
  7. II - Clarifications for WinSNMP v2.0:
  8. 1. Version 2.0
  9. 2. Level definitions
  10. 3. Operating system dependencies
  11. 4. Retransmission support
  12. 5. Timeout notification methods
  13. 6. SNMPv1 Trap-PDU generation
  14. 7. Notification port usage
  15. 8. Request-ID/SnmpCreatePdu()/SnmpSetPdu()
  16. 9. SnmpGetPduData() and hVbl
  17. 10. GetBulk -> GetNext mapping
  18. 11. IPX support in SnmpStrToEntity()
  19. 12. SnmpDecodeMsg() outputs
  20. 13. Inform processing
  21. 14. Thread-safeness
  22. 15. WinSNMP++ -> SNMP++ change
  23. 16. SnmpRegister()
  24. III - New functions for WinSNMP v2.0:
  25. 1. SnmpCreateSession()
  26. 2. SnmpCreateEntity()
  27. 3. SnmpCreateContext()
  28. 4. SnmpCancelMsg()
  29. 5. SnmpSetPort()
  30. 6. SnmpListen()
  31. 7. SnmpGetVendorInfo()
  32. 8. SnmpOpen() [Re-written for v2.0]
  33. I - Introduction
  34. This document is an update Addendum to the WinSNMP/Manager
  35. API Specification, v1.1a, dated August 9, 1995). In some
  36. places (Section II below, especially) it modifies (via
  37. clarifying text) that earlier document; in other places
  38. (Section III below, especially) it adds completely new
  39. functionality. Users of the WinSNMP API--implementors
  40. and application developers must be familiar with both
  41. documents until such time as the new WinSNMP API v2.0
  42. specification document is published. Said document will
  43. incorporate all of the text in the final version of this
  44. update Addendum.
  45. Like the WinSNMP API specification document itself, this
  46. document is intended to be freely available for use by
  47. all interested parties. It is the product of an open,
  48. collaborative effort via the ad hoc WinSNMP Industry Forum
  49. e-mail discussion list ([email protected]).
  50. Numerous individuals have contributed to the WinSNMP API
  51. since this work was started in the 1992/93 time frame.
  52. II - Clarifications
  53. 1. Version 2.0
  54. The collection of clarifications to v1.1a of the
  55. WinSNMP/Manager API specification described herein defines
  56. v2.0 of the WinSNMP API specification.
  57. A compliant v2.0 implementation MUST support ALL of the
  58. functions and operations defined in both the WinSNMP v1.1a
  59. specification and is this WinSNMP v2.0 Addendum.
  60. Where this WinSNMP v2.0 Addendum differs from the WinSNMP
  61. v1.1a specification, this Addendum has precedence.
  62. Note that for v2.0, the SnmpStartup() function must return a
  63. value of 2 for the lMajor parameter and a value of 0 for the
  64. lMinor parameter.
  65. Note also that the "/Manager" qualifier is dropped for v2.0.
  66. This version explicitly supports agent-side SNMP operations,
  67. in addition to the manager-side SNMP operations.
  68. 2. Level definitions
  69. The concept of "levels of support" is deprecated for v2.0.
  70. Implementations must report a value of 2 for the lLevel
  71. parameter of SnmpStartup().
  72. Level 2 equates to full support for the IETF standard SNMPv2
  73. protocol as defined in RFCs 1902-1908 with the community-
  74. based message wrapper as defined in RFC 1901 (SNMPv2c).
  75. Levels 0 and 1 are fully subsumed under Level 2. That is,
  76. in addition to full SNMPv2 support (as defined in the
  77. previous paragraph), all WinSNMP v2.0 implementations must
  78. implement the SnmpEncodeMsg() and SnmpDecodeMsg() functions
  79. (since no WinSNMP functions are optional in any case) and
  80. must also support all SNMPv1 protocol operations (except
  81. that, as always, all received SNMPv1 traps are converted
  82. to SNMPv2 Trap-PDU format for delivery to registered WinSNMP
  83. applications).
  84. Level 3, as originally defined, is no longer germane since the
  85. "Manager-to-Manager" MIB of "SNMPv2-Classic" was deprecated to
  86. "Historic" status by the IESG and, on the positive side, the
  87. combination of SNMPv2 support (especially, InformRequest-PDUs
  88. and their associated Response-PDUs) and the new functions to
  89. support agent applications under WinSNMP v2.0 (especially, the
  90. SnmpListen() function) now provide the basis for building
  91. Mid-Level Manager (MLM) solutions using WinSNMP. Additionally,
  92. it is envisioned that the next major revision of WinSNMP (v3)
  93. will correspond to adding support for the eventual IETF SNMPv3.
  94. (You will note that the proposed SnmpCreateEntity() and
  95. SnmpCreateContext() functions which were included in the
  96. earlier drafts of this Addendum have been dropped. It is
  97. anticipated that they will be added in WinSNMP v3 to support
  98. the corresponding constructs which will (almost surely!) be
  99. included in SNMPv3.)
  100. "SNMPAPI_UNTRANSLATED_V2" mode now means "SNMPv2c"; all
  101. the party stuff is gone (deprecated to "Historic" RFCs)
  102. and this mode uses community names in a manner identical
  103. to "SNMPAPI_UNTRANSLATED_V1" in terms of entity and context
  104. definitions. The only difference is that messages built
  105. for SNMPv2 destination entities will use the SNMPv2 value
  106. [1] in the "version" member of the SNMP message in the
  107. PDUs on the wire.
  108. 3. Operating system dependencies
  109. WinSNMP v1 was targeted at the Microsoft Windows family of
  110. operating systems.
  111. WinSNMP v2 is not targeted at any particular operating
  112. systems or environments; however, to ensure backward
  113. compatibility with fielded WinSNMP v1 applications, the
  114. fundamental design objectives and architectural constructs
  115. of WinSNMP v1 are retained.
  116. The degree of operating system independence targeted in
  117. WinSNMP v2 is realized via the new SnmpCreateSession()
  118. function (specified in Section III.1 of this document).
  119. The original session creation function--SnmpOpen()--is
  120. retained and comprises a proper subset of the possible forms
  121. of using SnmpCreateSession(). Some minor clarifying text
  122. has been added to SnmpOpen() for WinSNMP v2 (specified in
  123. Section III.8 of this document).
  124. 4. Retransmission support
  125. Execution of the retransmission policy was optional for
  126. implementations in WinSNMP v1. It is mandatory capability
  127. for implementations in WinSNMP v2.
  128. Implementations may still announce their "default" mode of
  129. operation at each call to SnmpStartup(). The default mode
  130. is whatever the implementation says it is in response to
  131. the given call to SnmpStartup().
  132. Applications may elect to operate with the RetransmitMode
  133. set to SNMPAPI_ON or SNMPAPI_OFF at any given point in time.
  134. The RetransmitMode setting is evaluated by the implementation
  135. at SnmpSendMsg() time.
  136. Unless and until a response is received, a message sent when
  137. the RetransmitMode is "on" will result in retries (if a non-
  138. zero retry count is specified for the dstEntity at the time
  139. SnmpSendMsg() is called) and issuance of a timeout notification
  140. to the associated session (when no response is received within
  141. the timeout interval and the retry count is exhausted).
  142. A message sent when RetransmitMode is "off" does not result
  143. in retries and no timeout notification is sent to the
  144. associated session.
  145. See the "Timeout notification methods" clarification for
  146. related information.
  147. See the new SnmpCancelMsg() function for associated
  148. functionality.
  149. 5. Timeout notification methods
  150. The method for notifying a session of a timed out request
  151. message was not specified for WinSNMP v1.
  152. It is specified for WinSNMP v2.
  153. The implementation must return the SNMPAPI_TL_TIMEOUT error
  154. value in wParam and the RequestID of the timed out PDU in
  155. lParam (this is true regardless of the notification mode of
  156. the session...i.e., message-based or callback-based).
  157. Note that for normal request, response, or trap delivery,
  158. the implementation must set wParam to zero and lParam to the
  159. RequestID of the PDU to be retrieved.
  160. Applications should check wParam on all notifications,
  161. regardless of notification mode (message or callback).
  162. If it is non-zero, then its value is one of the "transport
  163. layer" (SNMPAPI_TL_<n>) error codes and the application
  164. does not need to (and should not) call SnmpRecvMsg() in
  165. response to this notification.
  166. However, if the application elects to make the SnmpRecvMsg()
  167. call, then one of three results may occur:
  168. 1. If there is a pending message for this
  169. session, the DLL may deliver it at this
  170. time; or,
  171. 2. If there is no pending message for this
  172. session, then SnmpRecvMsg() must return
  173. SNMPAPI_FAILURE, with SnmpGetLastError()
  174. set to:
  175. a. SNMPAPI_NOOP [8], or
  176. b. SNMPAPI_TL_TIMEOUT [108].
  177. Note that if Result 1 obtains, the session may eventually
  178. receive a notification that will yield Result 2a, since
  179. that notification may have happened asynchronously to the
  180. early retrieval of the message.
  181. Note to implementors: If there is no message pending for the
  182. calling application, then Result 2a is the preferred error
  183. setting. Result 2b is allowed for backward compatibility
  184. with certain fielded applications.
  185. 6. SNMPv1 Trap-PDU generation
  186. The WinSNMP API is oriented towards SNMPv2. No standard
  187. function is provided to accommodate the unique fields of an
  188. SNMPv1 Trap-PDU (SNMP_PDU_V1TRAP). All SNMPv1 and SNMPv2
  189. Trap-PDUs which are received by a WinSNMP implementation
  190. and delivered to applications who requested them via
  191. SnmpRegister(), are delivered as SNMPv2 traps (SNMP_PDU_TRAP).
  192. Furthermore, only SNMPv2 Trap-PDUs can be assembled directly
  193. via SnmpCreatePdu() and/or SnmpSetPduData().
  194. However, WinSNMP entities operating in an agent role may
  195. need to emit traps to non-WinSNMP SNMPv1 targets. To
  196. accommodate this requirement, the SnmpSendMsg() must
  197. evaluate the SNMP-version level of the dstEntity parameter
  198. of any out-going SNMP_PDU_TRAP message. If the dstEntity is
  199. an SNMPv1 entity, then the message must be automatically and
  200. transparently converted to an SNMP_PDU_V1TRAP message via
  201. the following procedure:
  202. The WinSNMP API is intended to be a common interface that
  203. provides bilingual protocol support as transparently as
  204. possible. To this end, the API takes on a "v2-style
  205. interface" in all other areas, and "downgrades" a request
  206. appropriate to communicate with either v1 or v2 agents using
  207. the *SAME* interface.
  208. For example, WinSNMP v1.1a specified that all implementations
  209. (level 1 or 2) must support the GetBulk operator. However,
  210. if the request is sent to a v1 entity, then the WinSNMP
  211. implementation transparently "downgrades" the GetBulk to a
  212. GetNext request per RFC 1908. This enables an application
  213. to be coded to always use GetBulk and not care whether the
  214. dstEntity is a v1 or a v2 entity, especially in "translated
  215. mode".
  216. While RFC 1908 does not specify how to "downgrade" an
  217. SNMP_PDU_TRAP message into an SNMP_PDU_V1TRAP message, the
  218. translation is straight forward. As such, the WinSNMP
  219. interface for sending traps--whether to a v1 or a v2
  220. destination-is stipulated hereby as an SNMPv2 Trap-PDU
  221. (SNMP_PDU_TRAP).
  222. If the dstEntity of an SNMP_TRAP_PDU submitted to
  223. SnmpSendMessage() or SnmpEncodeMsg() is a v1 entity, then
  224. the WinSNMP implementation must "downgrade" (translate)
  225. the trap into an SNMP_PDU_V1TRAP during assembly of the
  226. corresponding SNMP message.
  227. This action taken on out-going SNMP trap messages has no
  228. bearing on SNMP traps received by an implementation. As
  229. with v1 of the WinSNMP API specification, in all cases,
  230. received traps are presented to WinSNMP applications as
  231. SNMPv2 traps (SNMP_PDU_TRAP).
  232. The translation procedure (e.g., during serialization) is
  233. simply the converse of the v1-to-v2 trap translation that
  234. is already done by WinSNMP implementations when v1traps
  235. are received and presented to the application. The steps
  236. are defined in Section 3.3 of RFC 2089, "V2ToV1 Mapping
  237. SNMPv2 onto SNMPv1 within a bi-lingual SNMP agent" by Bert
  238. Wijnen and David Levi.
  239. From an implementation perspective, it is straight-forward
  240. and rather easy to implement. From an application developer
  241. perspective, eliminating the need for the application to
  242. know/care about differences in v1 vs v2 traps enormously
  243. simplifies the application.
  244. The bottom line is that this approach preserves the "single
  245. interface / bilingual protocol" value proposition that
  246. WinSNMP was founded on. It also eliminates the need for a
  247. new / additional function in the WinSNMP API.
  248. 7. Notification port usage
  249. The term "notification" as used here applies to both traps
  250. (SNMPv1 and SNMPv2c) and informs (SNMPv2c only). Trap
  251. mapping between entities of different SNMP versions is
  252. described above. Important details wrt Inform requests are
  253. given in Section II.13, "Inform Processing", below.
  254. InformRequest-PDUs may only be sent to a destination entity
  255. that supports SNMPv2c. An attempt by an application to send
  256. an InformRequest-PDU to an SNMPv1 destination entity using
  257. SnmpSendMsg() results in SNMPAPI_FAILURE, with SnmpGetLastError()
  258. set to return SNMPAPI_OPERATION_INVALID.
  259. The well-known notification port for any protocol supported
  260. by an implementation (e.g., 162 for UDP and 36880 for IPX)
  261. should be held by an implementation of this WinSNMP API, if
  262. at all, only when there are active SnmpRegister() entries
  263. that might accept an incoming notification message.
  264. Where possible, an implementation should use some de facto or
  265. de jure standard "system service" for receiving notification
  266. messages to be dispatched to registered WinSNMP applications,
  267. such that other (non-WinSNMP) notification targets may operate
  268. concurrently with it. For Microsoft Windows NT, this standard
  269. mechanism is the "SNMPTRAP" system service.
  270. 8. Request-ID/SnmpCreatePdu()/SnmpSetPdu()
  271. Applications should specify "meaningful" Request-ID values
  272. via SnmpCreatePdu() and/or SnmpSetPduData().
  273. Implementations will automatically assign an arbitrary
  274. Request-ID value when SnmpCreatePdu() is called without a
  275. specified Request-ID value (i.e., the value is zero). The
  276. SnmpSetPduData() function may be used by an application to
  277. assign any Request-ID value it wants, including a value of
  278. zero.
  279. Implementations must use the resulting Request-ID value at
  280. SnmpSendMsg() time to return the eventual Response-PDU or
  281. timeout notification (if a corresponding Response-PDU is
  282. not received) to the application.
  283. Note that the Request-ID used in the "on-the-wire" messages
  284. is assigned by the implementation independently and may or
  285. may not be the same as the Request-ID used at the application
  286. level for any given message.
  287. 9. SnmpGetPduData() and hVbl
  288. If an hVbl output parameter is specified on a call to
  289. SnmpGetPduData() it will return a new instance of the
  290. VarBindList associated with the corresponding hPdu.
  291. This behavior is consistent with both the basic purpose of
  292. SnmpGetPduData()--which is to de-reference the components of
  293. a received PDU--and a basic characteristic of all WinSNMP
  294. functions which return WinSNMP resource objects (sessions,
  295. entities, contexts, PDUs, and VarBindLists) as outputs...
  296. namely, each output represents a new "instance" (used loosely)
  297. of the object. Such a new "instance" may be either a new
  298. unique value for that object type or may correspond to some
  299. internal, implementation-specific mechanism (such as a
  300. "reference count").
  301. The key underlying principle is that actual value of a
  302. WinSNMP resource object is not meaningful to the
  303. application, but is meaningful to the implementation.
  304. Applications need only be certain to match up each WinSNMP
  305. resource object creation operation with a corresponding
  306. "free" operation or, as may be appropriate, to free them via
  307. calls to SnmpClose() or SnmpCleanup().
  308. 10. GetBulk -> GetNext mapping
  309. When the dstEntity used in an SnmpSendMsg() operation is an
  310. SNMPv1 entity and the PDU type is SNMP_PDU_GETBULK, the
  311. implementation must automatically and transparently modify
  312. the PDU type to SNMP_PDU_GETNEXT, per RFC 1908. Note that
  313. this "translation" occurs during serialization of the
  314. WinSNMP components (hContext, hPdu, and hVbl, in this case)
  315. into the SNMP message that will be transmitted. It does
  316. NOT alter the submitted components themselves.
  317. 11. IPX support in SnmpStrToEntity()
  318. WinSNMP v1 was highly oriented toward IP/UDP, but was not
  319. meant to exclude the compatible, symmetrical use of other
  320. transport protocols by specific implementations. As a
  321. result, some implementations accepted alternative string
  322. formats as arguments to SnmpStrToEntity()--when called by
  323. an application operating in "untranslated" mode--to signal
  324. the use of protocols other than UDP.
  325. In particular, the use of "<netnum><sep><nodenum>" for the
  326. IPX protocol found a significant degree of usage. Hence, it
  327. is considered helpful to the community to specify a standard
  328. format for this purpose and to explicitly allow its use in
  329. SnmpStrToEntity(). This standard format consists of three
  330. collated parts:
  331. 1. A "network number" <netnum>, consisting of eight
  332. hexadecimal digits (zero-filled, if necessary).
  333. 2. A separator (i.e., either ":" or "-").
  334. 3. A "node number" <nodenum>, consisting of twelve
  335. hexadecimal digits (zero-filled, if necessary).
  336. For example: "00000001:00080A0D01C2"
  337. or: "00000001-00008A0D01C2"
  338. Note that SnmpEntityToStr() is also modified to return a
  339. properly formatted IPX address string, per above, for any
  340. IPX entity--when called by an application operating in
  341. "untranslated" mode at the time, or in "translated" mode
  342. but with no "friendlyName" value available.
  343. The ":" separator is the recommended default for use in
  344. the output string.
  345. 12. SnmpDecodeMsg() outputs
  346. This clarification has to do with return values for the hSrc
  347. and hDst output parameters. The key point is that an
  348. implementation cannot be required to supply information that
  349. is not unambiguously available to it. When WinSNMP v1 was
  350. designed, party-based SNMPv2 (since deprecated to "Historic"
  351. status) was being actively considered by the IETF. That
  352. form of the protocol might have included more address-type
  353. information in the encoded SNMP messages. If it had, then
  354. this information could have been used by the implementation
  355. of the SnmpDecodeMsg() function to instantiate hSrc and hDst
  356. entity values.
  357. However, the IETF adopted a different form of SNMPv2 (SNMPv2c,
  358. as defined in RFCs 1901-1908) and this form retains the same
  359. message format as SNMPv1 and that message format does not
  360. include the addressing information needed to properly create
  361. WinSNMP entity resources.
  362. Therefore, SnmpDecodeMsg() cannot return meaningful values
  363. for the hSrc or hDst parameter for SNMPv1 or SNMPv2 messages
  364. submitted to it and must return a value of zero in these
  365. output parameters.
  366. 13. Inform processing
  367. SNMPv2 Inform requests are only supported to a destination
  368. entity that supports SNMPv2. An attempt to send an Inform
  369. request to an SNMPv1 destination using SnmpSendMsg() must
  370. return SNMPAPI_FAILURE, with SnmpGetLastError() set to
  371. return SNMPAPI_OPERATION_INVALID.
  372. The implementation is responsible for generating and
  373. transmitting the (single) Response-PDU for any received
  374. InformRequest-PDU.
  375. Applications that receive an InformRequest-PDU via a WinSNMP
  376. session must not issue a corresponding Response-PDU.
  377. 14. Thread-safeness
  378. A multi-threaded application must ensure the thread-safeness
  379. of its own WinSNMP operations.
  380. The implementation must ensure "thread-safeness" at the
  381. application (process) level. That is, the implementation
  382. must ensure that the WinSNMP operations of one process do
  383. not unilaterally modify the WinSNMP settings of any other
  384. process.
  385. The WinSNMP operations that might merit attention on the
  386. part of a multi-threaded application are those which set
  387. application-level parameters. At this time, there are
  388. only two such settings:
  389. - SnmpSetTranslateMode()
  390. - SnmpSetRetransmitMode()
  391. It is often, not always, the case that an application--
  392. multi-threaded or not--will operate with a single constant
  393. value for each of these settings, with this value normally
  394. being either the default supplied by the SnmpStartup() call
  395. or an application-specified value (via SnmpSetTranslateMode()
  396. and/or SnmpSetRetransmitMode()) before any calls to the
  397. WinSNMP entity or context creation functions (for "translate"
  398. mode) or calls to SnmpSendMsg() (for "retransmit" mode).
  399. Nonetheless, implementors providing WinSNMP for operating
  400. environments which support multi-threaded applications
  401. are encouraged to include guidance on this issue in their
  402. developer-oriented documentation.
  403. 15. WinSNMP++ -> SNMP++ change
  404. The embryonic WinSNMP++ appendix to the WinSNMP v1
  405. specification has been deprecated and deleted from the
  406. WinSNMP v2 specification.
  407. Implementors are now directed to the open SNMP++
  408. specification (and reference code) published by Hewlett-
  409. Packard (http://rosegarden.external.hp.com/snmp++).
  410. 16. SnmpRegister()
  411. The primary purpose of SnmpRegister() is to enable an
  412. application to indicate that it wants to receive traps
  413. that arrive at the default SNMP trap port(s) (UDP 162
  414. and/or IPX 36880) on the local machine. This can be
  415. accomplished by passing the following parameter values
  416. in the call to SnmpRegister():
  417. session - a valid session handle
  418. srcEntity - NULL
  419. dstEntity - NULL
  420. context - NULL
  421. notification - NULL
  422. status - SNMPAPI_ON
  423. This sequence of parameter values, assuming the call is
  424. otherwise successful, will result in all notifications
  425. (traps and informs) received by the WinSNMP implementation
  426. being delivered to the session. We will refer to the
  427. above setting as an "unfiltered" registration.
  428. A secondary purpose of SnmpRegister() is to function as
  429. a minimal "trap filter" on notifications received by the
  430. WinSNMP implementation. In this mode, non-NULL values
  431. for any combination of one or more of the srcEntity,
  432. dstEntity, context, or notification parameters, will be
  433. used to form a filter to be applied to traps received by
  434. the WinSNMP implementation for the indicated session.
  435. We will refer to any such operation as a "filtered"
  436. registration.
  437. Note that while an "unfiltered" registration is in
  438. effect for a session, it makes no sense to issue any
  439. "filtered" registration requests for that same session.
  440. They would be totally superfluous--since all notifications
  441. would already be delivered to the session anyway due to
  442. the "unfiltered" registration. This is one of three types
  443. of "redundant" registrations. Another type of "redundant"
  444. registration is a duplicate call to SnmpRegister()--that
  445. is, one in which the parameter list is identical to the
  446. parameter list used to instantiate an active registration
  447. for the same session. The third type of "redundant"
  448. registration is one in which the notification parameter
  449. (when dereferenced) fully contains (as a prefix) a
  450. notification parameter used on an active registration
  451. for the same session. This is redundant due to the
  452. wildcard interpretation of the notification parameter
  453. specified in the WinSNMP v1.1a spec.
  454. In all cases of "redundant" registrations, SnmpRegister()
  455. should return SNMPAPI_SUCCESS, since the action requested
  456. by the application--namely, to deliver the specified
  457. notifications to the indicated session--will be carried
  458. out. [Yes, we could have gone with SNMPAPI_FAILURE in
  459. these cases and setting SnmpGetLastError() to return
  460. SNMPAPI_NOOP, but the incidence of problems resulting
  461. form such "redundant" calls has proven to be close to
  462. zero in practice and, therefore, we are taking a more
  463. streamlined approach.]
  464. Also, note that such redundant "register" requests are
  465. idempotent, meaning that only a single corresponding
  466. "unregister" call is required. To "unregister" means
  467. to call SnmpRegister() with a status parameter value of
  468. SNMPAPI_OFF and with the first five parameters having
  469. the same effective values as some previously successful
  470. call with a status parameter of SNMPAPI_ON.
  471. Implementations do not maintain a "count" of redundant
  472. registrations that must be matched with an equal number
  473. of corresponding unregistrations.
  474. Of course, each unique (non-redundant) register must
  475. be matched with an unregister call to remove it, if
  476. desired by the application.
  477. III - New Functions:
  478. 1. SnmpCreateSession()
  479. The SnmpCreateSession() function is used to create a WinSNMP
  480. "session" and to specify the notification mode-either a
  481. "window/message" pair or callback function--that will be
  482. used for the session.
  483. With this function, Windows programmers now have the option
  484. of having the implementation use either the standard Windows
  485. message notification method (as in SnmpOpen()) or a direct
  486. callback into a session-specific function. As a by-product
  487. of this enhanced flexibility for Windows programmers, the
  488. WinSNMP API can now also be used in some non-Windows
  489. operating environments (some examples are given below).
  490. This function is a superset of the SnmpOpen() function.
  491. That is, when used to create a session with window/message
  492. notification, it provides the exact same functionality as
  493. SnmpOpen(). (Refer to the descriptive text for SnmpOpen()
  494. elsewhere in this alphabetical "Function Reference" chapter
  495. for more information.)
  496. Developers writing new applications for WinSNMP v2.0 are
  497. encouraged to use SnmpCreateSession() for all session
  498. creation, even when selecting the window/message
  499. notification mode (i.e., instead of using SnmpOpen()).
  500. Developers upgrading applications written for earlier
  501. versions of WinSNMP to take advantage of other WinSNMP v2.0
  502. features are encouraged to change all SnmpOpen() calls to
  503. the equivalent form of SnmpCreateSession().
  504. HSNMP_SESSION SnmpCreateSession (IN HWND hWnd,
  505. IN UINT wMsg,
  506. IN SNMPAPI_CALLBACK fCallBack,
  507. IN LPVOID lpClientData);
  508. WINSNMP.DEF category = Communications Functions;
  509. ordinal value = 220.
  510. Parameter Description
  511. hWnd Identifies a notification window.
  512. wMsg Identifies a notification message.
  513. fCallBack Identifies a notification callback function;
  514. may be NULL.
  515. lpClientData Identifies a pointer to optional application
  516. data to pass to the fCallBack function; may be
  517. NULL.
  518. Returns:
  519. If the SnmpCreateSession() function is successful, the return
  520. value is an HSNMP_SESSION handle which identifies the WinSNMP
  521. session opened by the implementation on behalf of the calling
  522. application.
  523. If the function fails, the return value is SNMPAPI_FAILURE
  524. and SnmpGetLastError() will be set to return extended error
  525. information as follows:
  526. SnmpGetLastError() Description
  527. "Common Error Codes" See Section 2.10.1. Common Error
  528. Codes.
  529. SNMPAPI_HWND_INVALID hWnd is not a valid window value.
  530. SNMPAPI_MSG_INVALID wMsg is not a valid message value.
  531. SNMPAPI_MODE_INVALID The combination of values passed
  532. is mutually incompatible or
  533. incomplete.
  534. SNMPAPI_OPERATION_INVALID The combination of values passed
  535. does not identify a valid
  536. notification mode for this
  537. implementation.
  538. As will be explained below, the conditions leading to any of
  539. the three specific error codes listed above are somewhat
  540. environment-specific.
  541. Comments:
  542. If fCallBack is NULL, SnmpCreateSession() is equivalent to
  543. the SnmpOpen() function. In this window/notification mode,
  544. the values of hWnd and wMsg must both be valid in the
  545. implementation's operating environment.
  546. If the value of hWnd is invalid, then the function returns
  547. SNMPAPI_FAILURE, and SnmpGetLastError() is set to return
  548. SNMPAPI_HWND_INVALID.
  549. Else, if the value of wMsg is invalid, then the function
  550. returns SNMPAPI_FAILURE, and SnmpGetLastError() is set to
  551. return SNMPAPI_WMSG_INVALID.
  552. Else, if both values are individually valid but are mutually
  553. incompatible in a given windowing environment, then the
  554. function returns SNMPAPI_FAILURE, and SnmpGetLastError() is
  555. set to return SNMPAPI_MODE_INVALID.
  556. If fCallBack is non-NULL, it represents the address of a
  557. function to be called whenever the implementation has a
  558. notification to deliver to the session. The notification
  559. may signal the presence of an SNMP message for the session
  560. or it may signal the existence of an asynchronous error
  561. condition (for example, a transport layer timeout error).
  562. (Refer to the discussion of "Retransmission and Timeout
  563. Notification" in the "Programming with WinSNMP" chapter
  564. and the descriptive text for SnmpRecvMsg() elsewhere in
  565. this alphabetical "Function Reference" chapter for more
  566. information.) When fCallBack is non-NULL, a given operating
  567. environment may require valid values for any or all of hWnd,
  568. wMsg, and/or lpClientData and should return one of the three
  569. function-specific error codes in a manner consistent with
  570. that outlined above.
  571. The callback function prototype must be:
  572. typedef SNMPAPI_STATUS (CALLBACK *SNMPAPI_CALLBACK)(
  573. IN HSNMP_SESSION session,
  574. IN HWND hWnd,
  575. IN UINT wMsg,
  576. IN WPARAM wParam,
  577. IN LPARAM lParam,
  578. IN LPVOID lpClientData);
  579. Parameter Description
  580. session Identifies the session being notified.
  581. hWnd Identifies the session's notification window.
  582. wMsg Identifies the session's notification message.
  583. wParam Identifies the purpose of the notification.
  584. lParam Identifies the RequestID of the subject PDU.
  585. lpClientData Identifies a pointer to optional application
  586. data, if such a pointer was specified in the
  587. session's SnmpCreateSession() call.
  588. Note: If fCallBack is non-NULL on a successful call to the
  589. SnmpCreateSession() function, then the session operates in
  590. callback notification mode and the values of hWnd and wMsg
  591. passed to the SnmpCreateSession() function may or may not be
  592. significant depending upon the operating environment, but
  593. are always passed to the callback function for its possible
  594. use.
  595. Note: If a callback function has been assigned to a session
  596. in this manner, then upon receipt of an SNMP message for the
  597. session the implementation will call the callback function--
  598. instead of sending the wMsg notification message to the hWnd
  599. as it would in the window/message notification mode--and
  600. pass it the session identifier and two values representing
  601. the wParam and lParam values that would have been used if
  602. operating in the window/message notification mode. (See the
  603. descriptive text for the SnmpOpen() function elsewhere in
  604. the alphabetical "Function Reference" chapter for additional
  605. background information.)
  606. Note: The fCallBack function must return SNMPAPI_SUCCESS to
  607. indicate continued viability. Any other returned value will
  608. be interpreted as SNMPAPI_FAILURE and will result in the
  609. implementation doing an implicit SnmpClose() operation on
  610. the session.
  611. Note: If the fCallBack parameter to SnmpCreateSession() is
  612. NULL, any non-NULL value of lpClientData is meaningless and,
  613. therefore, will be ignored by the implementation.
  614. Note: When the callback function is called for the purpose
  615. of notifying the session of the presence of an SNMP message
  616. for it, the value passed for wParam must be 0. Otherwise,
  617. any non-zero value of wParam will signal an asynchronous
  618. error notification for the session. The most common example
  619. of such an error notification is a "no response from agent"
  620. timeout when the implementation is executing retransmission
  621. policy for the application; in which case, the value of
  622. wParam will be SNMPAPI_TL_TIMEOUT [108]. The value passed
  623. in the lParam parameter will always indicate the RequestID
  624. of the affected PDU. (See the descriptive text for the
  625. SnmpRecvMsg() function elsewhere in the alphabetical
  626. "Function Reference" chapter for more information about the
  627. general use of these two parameters.)
  628. Following are some sample calling modes for different
  629. operating environments:
  630. MS-Windows, Window/Message notification mode:
  631. hSession = SnmpCreateSession (myWnd, myMsg, NULL, NULL);
  632. MS-Windows, Callback notification mode:
  633. hSession = SnmpCreateSession (0, 0, myFunc, <NULL|myData>);
  634. UNIX X-Windows, Callback notification mode:
  635. hSession = SnmpCreateSession (myWnd, 0, myFunc, <NULL|myData>);
  636. Any non-window Command Line Environment, Callback mode:
  637. hSession = SnmpCreateSession (0, 0, myFunc, <NULL|myData>);
  638. Note: The first example above is equivalent to a standard
  639. WinSNMP SnmpOpen() call.
  640. Note: For non-MS-Windows operating environments,
  641. implementors may (and will likely have to) supply
  642. definitions for the Windows-specific data types used in the
  643. standard WinSNMP.h file, which originate from <windows.h>
  644. (which is #include'd in WinSNMP.h).
  645. A possible example of a "windows.h" file for a generic
  646. X-Windows operating environment follows:
  647. // windows.h
  648. // #include'd in WinSNMP.h
  649. // typedef's for the SnmpCreateSession function
  650. typedef XtAppContext HWND; // X-Window id
  651. typedef unsigned int UINT; // Not used
  652. typedef void *CALLBACK; // Callback function
  653. typedef void *LPVOID; // Callback user data
  654. // additional typedef's for the fCallBack prototype
  655. typedef unsigned int WPARAM; // Notification code
  656. typedef unsigned int LPARAM; // RequestID
  657. See also: SnmpOpen() and SnmpRecvMsg() in the alphabetical
  658. function reference section, and "Retransmission and Timeout
  659. Notification" in the "Programming with WinSNMP" section.
  660. 2. SnmpCreateEntity()
  661. Due to the on-going work in the IETF SNMPv3 WG, this function
  662. will be deferred to the WinSNMP v3 time frame.
  663. This "placeholder" is being retained here as a signal to
  664. interested parties to monitor the SNMPv3 output for future
  665. incorporation in WinSNMP v3.
  666. 3. SnmpCreateContext()
  667. Due to the on-going work in the IETF SNMPv3 WG, this function
  668. will be deferred to the WinSNMP v3 time frame.
  669. This "placeholder" is being retained here as a signal to
  670. interested parties to monitor the SNMPv3 output for future
  671. incorporation in WinSNMP v3.
  672. 4. SnmpCancelMsg()
  673. The SnmpCancelMsg() function requests cancellation of any
  674. further retransmissions or timeout notification for the PDU
  675. identified by the requestId parameter for the specified
  676. session.
  677. SNMPAPI_STATUS SnmpCancelMsg (IN HSNMP_SESSION session,
  678. IN smiINT32 requestId);
  679. WINSNMP.DEF category = Communications Functions;
  680. ordinal value = @222.
  681. Parameter Description
  682. session Identifies the session which submitted the
  683. message to be canceled.
  684. requestId Identifies the Request-ID value of the
  685. hPdu used in the corresponding call to
  686. SnmpSendMsg().
  687. Returns:
  688. If the function executes successfully, the return value is
  689. SNMPAPI_SUCCESS.
  690. If the function fails, the return value is SNMPAPI_FAILURE.
  691. Use SnmpGetLastError() to obtain extended error information.
  692. SnmpGetLastError() Description
  693. SNMPAPI_SESSION_INVALID The session parameter is invalid.
  694. SNMPAPI_PDU_INVALID The requestId parameter does not
  695. identify a message with outstanding
  696. retransmissions for the specified
  697. session.
  698. Comments:
  699. Successful execution of this function is analogous to
  700. setting RetransmitMode to SNMPAPI_OFF for the affected
  701. message.
  702. Note: Applications must be aware that--due to transaction
  703. queuing at various levels--it is possible that the subject
  704. destination entity may still receive and/or respond to a
  705. corresponding SNMP message even following successful
  706. execution of SnmpCancelMsg(). But the implementation must
  707. not transmit any retries or submit a Response-PDU or timeout
  708. notification to the application for the subject message
  709. following successful execution of this function.
  710. Note: Successful execution of this function applies to a
  711. single message instance. This point illustrates another
  712. reason why applications should use "meaningful" Request-ID
  713. values for their respective PDUs.
  714. Note: Implementations must effectively execute
  715. SnmpCancelMsg() on any outstanding messages for a session
  716. when SnmpClose() is called, whether directly or indirectly
  717. via SnmpCleanup().
  718. 5. SnmpSetPort()
  719. The SnmpSetPort() function permits an application to change
  720. the port assignment of a given destination entity.
  721. SNMPAPI_STATUS SNMPAPI_CALL SnmpSetPort
  722. (IN HSNMP_ENTITY hEntity,
  723. IN UINT nPort);
  724. WINSNMP.DEF category = Entity/Context Functions;
  725. ordinal value = @320.
  726. Note: "Destination entity" includes entities used as
  727. agent applications via the local WinSNMP implementation
  728. (see Section III.6, "SnmpListen()", below).
  729. Note: If the hEntity parameter identifies an entity which
  730. is already operating in an agent mode for this application
  731. (via the new SnmpListen() function outlined below), then
  732. this function will return SNMPAPI_FAILURE, with SnmpGetLastError()
  733. set to return SNMPAPI_ENTITY_INVALID, since such an entity is
  734. already bound to a port. The proper sequence of events for
  735. such an entity is:
  736. hAgent = SnmpStrToEntity (hSession, <addrString>);
  737. lStatus = SnmpSetPort (hAgent, <nPort>);
  738. lStatus = SnmpListen (hAgent, SNMPAPI_ON);
  739. The implementation will have "assigned" a port value to the
  740. entity as part of the SnmpStrToEntity() operation. This will
  741. normally be the standard SNMP request port for the respective
  742. protocol family (e.g., UDP 161 or IPX 36879) for an entity
  743. created in "untranslated" mode or whatever may be specified in
  744. the local database for an entity created in "translated" mode.
  745. So, if the agent is to listen on a different port, or just to
  746. be safe, the app can use SnmpSetPort() to arrange that.
  747. 6. SnmpListen()
  748. This new function permits the "attachment" of an agent
  749. application using the [local] address and port settings
  750. in effect for the hEntity parameter.
  751. SNMPAPI_STATUS SNMPAPI_CALL SnmpListen
  752. (IN HSNMP_ENTITY hEntity,
  753. IN SNMPAPI_STATUS lStatus);
  754. WINSNMP.DEF category = Communications Functions;
  755. ordinal value = @221.
  756. "hEntity" will indicate the session to be notified (via
  757. callback or window/message) when an in-coming request
  758. is received for this agent application, and the address
  759. family, interface address, and port to use for this
  760. "agent". Note that all of these attributes already exist
  761. as aspects of a WinSNMP "entity".
  762. "lStatus" will take either of two values: SNMPAPI_ON
  763. or SNMPAPI_OFF. If it is SNMPAPI_ON, all else passing,
  764. the "agent" will then bind to its af:addr:port and
  765. listen for incoming requests, which will be transferred
  766. to it via the normal WinSNMP mechanisms. It will then
  767. "do its thing" with the request, form the response,
  768. reverse the srcEntity and dstEntity parameters it
  769. received on the SnmpRecvMsg() call, and transmit the
  770. response back to the requester via SnmpSendMsg().
  771. If the entity's port is already in use, the call to
  772. SnmpListen() will fail with an appropriate error
  773. via SnmpGetLastError(). When an entity no longer
  774. wants to function as an agent, it should call
  775. SnmpListen() with an "lStatus" value of SNMPAPI_OFF
  776. to release the port (and other resources). Both
  777. SnmpClose() for the session and SnmpCleanup() for
  778. the app must release all affected agent ports.
  779. 7. SnmpGetVendorInfo()
  780. This new function returns vendor identification information
  781. to the application using a new structure defined in winsnmp.h:
  782. #define MAXVENDORINFO 32
  783. typedef struct
  784. {
  785. char vendorName[MAXVENDORINFO*2];
  786. char vendorContact[MAXVENDORINFO*2];
  787. char vendorVersionId[MAXVENDORINFO];
  788. char vendorVersionDate[MAXVENDORINFO];
  789. smiUINT32 vendorEnterprise;
  790. } smiVENDORINFO, FAR *smiLPVENDORINFO;
  791. SNMPAPI_STATUS SNMPAPI_CALL SnmpGetVendorInfo
  792. (OUT smiLPVENDORINFO vendorInfo);
  793. WINSNMP.DEF category = Local Database Functions;
  794. ordinal value = @120.
  795. If vendorInfo is NULL, the return value is SNMPAPI_FAILURE with
  796. SnmpGetLastError() set to return SNMPAPI_NOOP.
  797. Upon successful return from this function, the four "char"
  798. fields should contain NULL-terminated text strings suitable
  799. for output on a display device. The content of these fields
  800. is vendor-determined, but should provide information helpful
  801. to end-users in the event of a problem, if displayed by an
  802. application. For example, "vendorContact" could include a
  803. physical or postal address, telephone and/or fax numbers,
  804. an e-mail address or a URL. If a vendor has an IANA-issue
  805. enterprise number, then it should be returned as the value
  806. of vendorEnterprise; otherwise, its value must be zero.
  807. 8. SnmpOpen()
  808. [Note: Modified for clarity wrt SnmpCreateSession(), which
  809. is new for WinSNMP v2.]
  810. [Do_Box]
  811. Important: WinSNMP v2.0 added the SnmpCreateSession()
  812. function which provides a superset of the SnmpOpen()
  813. functionality. Developers are encouraged to use
  814. SnmpCreateSession() instead of SnmpOpen().
  815. SnmpOpen() is maintained for backwards compatibility with
  816. pre-v2.0 WinSNMP applications, but some (non-Windows)
  817. implementations may return SNMPAPI_OPERATION_INVALID in
  818. response to any SnmpOpen() call, as described below.
  819. [End_Box]
  820. The SnmpOpen() function enables the implementation to
  821. allocate and initialize memory, resources, and/or
  822. communications mechanisms and data structures for the
  823. application. The application will continue to use the
  824. "session identifier" returned by the implementation in
  825. subsequent WinSNMP function calls to facilitate resource
  826. accounting on a per session basis. This mechanism enables
  827. the implementation to perform an orderly release of
  828. resources in response to a subsequent SnmpClose() function
  829. call for a given session (or in response to a subsequent
  830. SnmpCleanup() call for the application).
  831. Syntax:
  832. HSNMP_SESSION SnmpOpen (
  833. IN HWND hWnd,
  834. IN UINT wMsg);
  835. Parameter Description
  836. hWnd Identifies the application's notification window.
  837. wMsg Identifies the application's notification message.
  838. Returns:
  839. If the function is successful, the return value is a non-
  840. zero HSNMP_SESSION value which identifies the WinSNMP
  841. session opened by the implementation on behalf of the
  842. calling application.
  843. If the function fails, the return value is SNMPAPI_FAILURE.
  844. Use the SnmpGetLastError() function to obtain extended error
  845. information.
  846. SnmpGetLastError() Description
  847. "Common Error Codes" See Section 2.10.1. Common Error
  848. Codes.
  849. SNMPAPI_HWND_INVALID The hWnd parameter is not a valid
  850. window handle.
  851. SNMPAPI_OPERATION_INVALID This implementation does not
  852. support the Windows/Message
  853. notification scheme (see
  854. SnmpCreateSession()).
  855. Comments:
  856. See Section 2.5. Sessions and Section <new> SnmpCreateSession().
  857. An application can open multiple sessions. Each such
  858. session for the same hWnd should provide a different wMsg,
  859. but this is not required.
  860. A successful SnmpOpen() call always returns a unique
  861. HSNMP_SESSION value (with respect to all other currently
  862. open sessions for the calling application).
  863. The hWnd parameter specifies the window to be notified when
  864. an asynchronous request completes or trap/notification
  865. occurs and the wMsg parameter specifies the message number
  866. that the implementation will send to the window. Upon
  867. receipt of this message,
  868. - If the wParam component of the notification message
  869. is zero (0), the application should call
  870. SnmpRecvMsg() to retrieve the subject PDU for
  871. immediate or subsequent processing.
  872. - If the wParam component of the notification message
  873. is non-zero, it will represent a WinSNMP API error
  874. code (e.g., SNMPAPI_TL_TIMEOUT) referring to the
  875. PDU identified by the Request_Id value in the lParam
  876. component. In this case, the application should
  877. react to the error condition and should not call
  878. SnmpRecvMsg().
  879. In other programming models (e.g., synchronous, CLI-driven,
  880. or "curtained" applications), the WinSNMP implementation may
  881. interpret hWnd and hMsg differently. Likewise, the session
  882. model may be used to facilitate multi-threaded programming
  883. in supporting environments. The SnmpCreateSession()
  884. function has been added to WinSNMP v2.0 to formalize such
  885. usage.
  886. Note: A well-behaved WinSNMP application will call
  887. SnmpClose() for each session opened with SnmpOpen(). When
  888. an emergency exit is required by the application, it must at
  889. least call SnmpCleanup().
  890. A well-behaved WinSNMP implementation must react to an
  891. SnmpCleanup() call as though it were a series of SnmpClose()
  892. calls for each open session allocated to the calling
  893. application.