5 * snmp_api.h - API for access to snmp.
7 * Caution: when using this library in a multi-threaded application,
8 * the values of global variables "snmp_errno" and "snmp_detail"
9 * cannot be reliably determined. Suggest using snmp_error()
10 * to obtain the library error codes.
13 #ifndef DONT_SHARE_ERROR_WITH_OTHER_THREADS
14 #define SET_SNMP_ERROR(x) snmp_errno=(x)
16 #define SET_SNMP_ERROR(x)
24 /***********************************************************
25 Copyright 1989 by Carnegie Mellon University
29 Permission to use, copy, modify, and distribute this software and its
30 documentation for any purpose and without fee is hereby granted,
31 provided that the above copyright notice appear in all copies and that
32 both that copyright notice and this permission notice appear in
33 supporting documentation, and that the name of CMU not be
34 used in advertising or publicity pertaining to distribution of the
35 software without specific, written prior permission.
37 CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
38 ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
39 CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
40 ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
41 WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
42 ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
44 ******************************************************************/
47 typedef struct variable_list netsnmp_variable_list;
49 struct netsnmp_transport_s;
51 #define USM_AUTH_KU_LEN 32
52 #define USM_PRIV_KU_LEN 32
54 typedef struct snmp_pdu {
57 * Protocol-version independent fields
60 int command; /* Type of this PDU */
61 long reqid; /* Request id - note: not incremented on retries */
62 long msgid; /* Message id for V3 messages
63 * note: incremented for each retry */
64 long transid; /* Unique ID for incoming transactions */
65 long sessid; /* Session id for AgentX messages */
66 long errstat; /* Error status (non_repeaters in GetBulk) */
67 long errindex; /* Error index (max_repetitions in GetBulk) */
68 u_long time; /* Uptime */
72 int securityLevel; /* noAuthNoPriv, authNoPriv, authPriv */
76 * Transport-specific opaque data. This replaces the IP-centric address
81 int transport_data_length;
84 * The actual transport domain. This SHOULD NOT BE FREE()D.
90 netsnmp_variable_list *variables;
94 * SNMPv1 & SNMPv2c fields
96 u_char *community; /* community for outgoing requests. */
97 size_t community_len; /* Length of community name. */
102 oid *enterprise; /* System OID */
103 size_t enterprise_length;
104 long trap_type; /* trap type */
105 long specific_type; /* specific type */
106 unsigned char agent_addr[4]; /* This is ONLY used for v1 TRAPs */
111 u_char *contextEngineID; /* context snmpEngineID */
112 size_t contextEngineIDLen; /* Length of contextEngineID */
113 char *contextName; /* authoritative contextName */
114 size_t contextNameLen; /* Length of contextName */
115 u_char *securityEngineID; /* authoritative snmpEngineID for security */
116 size_t securityEngineIDLen; /* Length of securityEngineID */
117 char *securityName; /* on behalf of this principal */
118 size_t securityNameLen; /* Length of securityName. */
122 * (also uses SNMPv1 community field)
127 void *securityStateRef;
131 typedef struct snmp_session netsnmp_session;
133 typedef int (*snmp_callback) (int, netsnmp_session *, int,
134 netsnmp_pdu *, void *);
135 typedef int (*netsnmp_callback) (int, netsnmp_session *, int,
136 netsnmp_pdu *, void *);
138 struct snmp_session {
140 * Protocol-version independent fields
143 int retries; /* Number of retries before timeout. */
144 long timeout; /* Number of uS until first timeout, then exponential backoff */
146 struct snmp_session *subsession;
147 struct snmp_session *next;
149 char *peername; /* Domain name or dotted IP address of default peer */
150 u_short remote_port; /* UDP port number of peer. */
151 u_short local_port; /* My UDP port number, 0 for default, picked randomly */
153 * Authentication function or NULL if null authentication is used
155 u_char *(*authenticator) (u_char *, size_t *, u_char *, size_t);
156 netsnmp_callback callback; /* Function to interpret incoming data */
158 * Pointer to data that the callback function may consider important
160 void *callback_magic;
162 int s_errno; /* copy of system errno */
163 int s_snmp_errno; /* copy of library errno */
164 long sessid; /* Session id - AgentX only */
167 * SNMPv1 & SNMPv2c fields
169 u_char *community; /* community for outgoing requests. */
170 size_t community_len; /* Length of community name. */
172 size_t rcvMsgMaxSize; /* Largest message to try to receive. */
173 size_t sndMsgMaxSize; /* Largest message to try to send. */
178 u_char isAuthoritative; /* are we the authoritative engine? */
179 u_char *contextEngineID; /* authoritative snmpEngineID */
180 size_t contextEngineIDLen; /* Length of contextEngineID */
181 u_int engineBoots; /* initial engineBoots for remote engine */
182 u_int engineTime; /* initial engineTime for remote engine */
183 char *contextName; /* authoritative contextName */
184 size_t contextNameLen; /* Length of contextName */
185 u_char *securityEngineID; /* authoritative snmpEngineID */
186 size_t securityEngineIDLen; /* Length of contextEngineID */
187 char *securityName; /* on behalf of this principal */
188 size_t securityNameLen; /* Length of securityName. */
189 oid *securityAuthProto; /* auth protocol oid */
190 size_t securityAuthProtoLen; /* Length of auth protocol oid */
191 u_char securityAuthKey[USM_AUTH_KU_LEN]; /* Ku for auth protocol XXX */
192 size_t securityAuthKeyLen; /* Length of Ku for auth protocol */
193 oid *securityPrivProto; /* priv protocol oid */
194 size_t securityPrivProtoLen; /* Length of priv protocol oid */
195 u_char securityPrivKey[USM_PRIV_KU_LEN]; /* Ku for privacy protocol XXX */
196 size_t securityPrivKeyLen; /* Length of Ku for priv protocol */
198 int securityLevel; /* noAuthNoPriv, authNoPriv, authPriv */
201 * security module specific
206 * use as you want data
212 * A list of all the outstanding requests for a particular session.
214 #ifdef SNMP_NEED_REQUEST_LIST
215 typedef struct request_list {
216 struct request_list *next_request;
217 long request_id; /* request id */
218 long message_id; /* message id */
219 netsnmp_callback callback; /* user callback per request (NULL if unused) */
220 void *cb_data; /* user callback data per request (NULL if unused) */
221 int retries; /* Number of retries */
222 u_long timeout; /* length to wait for timeout */
223 struct timeval time; /* Time this request was made */
224 struct timeval expire; /* time this request is due to expire */
225 struct snmp_session *session;
226 netsnmp_pdu *pdu; /* The pdu for this request
227 * (saved so it can be retransmitted */
228 } netsnmp_request_list;
229 #endif /* SNMP_NEED_REQUEST_LIST */
232 * Set fields in session and pdu to the following to get a default or unconfigured value.
234 #define SNMP_DEFAULT_COMMUNITY_LEN 0 /* to get a default community name */
235 #define SNMP_DEFAULT_RETRIES -1
236 #define SNMP_DEFAULT_TIMEOUT -1
237 #define SNMP_DEFAULT_REMPORT 0
238 #define SNMP_DEFAULT_REQID -1
239 #define SNMP_DEFAULT_MSGID -1
240 #define SNMP_DEFAULT_ERRSTAT -1
241 #define SNMP_DEFAULT_ERRINDEX -1
242 #define SNMP_DEFAULT_ADDRESS 0
243 #define SNMP_DEFAULT_PEERNAME NULL
244 #define SNMP_DEFAULT_ENTERPRISE_LENGTH 0
245 #define SNMP_DEFAULT_TIME 0
246 #define SNMP_DEFAULT_VERSION -1
247 #define SNMP_DEFAULT_SECMODEL -1
248 #define SNMP_DEFAULT_CONTEXT ""
249 #define SNMP_DEFAULT_AUTH_PROTO usmHMACMD5AuthProtocol
250 #define SNMP_DEFAULT_AUTH_PROTOLEN USM_LENGTH_OID_TRANSFORM
251 #define SNMP_DEFAULT_PRIV_PROTO usmDESPrivProtocol
252 #define SNMP_DEFAULT_PRIV_PROTOLEN USM_LENGTH_OID_TRANSFORM
254 extern const char *snmp_api_errstring(int);
255 extern void snmp_perror(const char *);
256 extern void snmp_set_detail(const char *);
258 #define SNMP_MAX_MSG_SIZE 1472 /* ethernet MTU minus IP/UDP header */
259 #define SNMP_MAX_MSG_V3_HDRS (4+3+4+7+7+3+7+16) /* fudge factor=16 */
260 #define SNMP_MAX_ENG_SIZE 32
261 #define SNMP_MAX_SEC_NAME_SIZE 256
262 #define SNMP_MAX_CONTEXT_SIZE 256
263 #define SNMP_SEC_PARAM_BUF_SIZE 256
266 * set to one to ignore unauthenticated Reports
268 #define SNMPV3_IGNORE_UNAUTH_REPORTS 0
271 * authoritative engine definitions
273 #define SNMP_SESS_NONAUTHORITATIVE 0 /* should be 0 to default to this */
274 #define SNMP_SESS_AUTHORITATIVE 1 /* don't learn engineIDs */
275 #define SNMP_SESS_UNKNOWNAUTH 2 /* sometimes (like NRs) */
278 * to determine type of Report from varbind_list
280 #define REPORT_STATS_LEN 9
281 #define REPORT_snmpUnknownSecurityModels_NUM 1
282 #define REPORT_snmpInvalidMsgs_NUM 2
283 #define REPORT_usmStatsUnsupportedSecLevels_NUM 1
284 #define REPORT_usmStatsNotInTimeWindows_NUM 2
285 #define REPORT_usmStatsUnknownUserNames_NUM 3
286 #define REPORT_usmStatsUnknownEngineIDs_NUM 4
287 #define REPORT_usmStatsWrongDigests_NUM 5
288 #define REPORT_usmStatsDecryptionErrors_NUM 6
290 #define SNMP_DETAIL_SIZE 512
292 #define SNMP_FLAGS_DONT_PROBE 0x100 /* don't probe for an engineID */
293 #define SNMP_FLAGS_STREAM_SOCKET 0x80
294 #define SNMP_FLAGS_LISTENING 0x40 /* Server stream sockets only */
295 #define SNMP_FLAGS_SUBSESSION 0x20
296 #define SNMP_FLAGS_STRIKE2 0x02
297 #define SNMP_FLAGS_STRIKE1 0x01
299 #define CLEAR_SNMP_STRIKE_FLAGS(x) \
300 x &= ~(SNMP_FLAGS_STRIKE2|SNMP_FLAGS_STRIKE1)
303 * returns '1' if the session is to be regarded as dead,
304 * otherwise set the strike flags appropriately, and return 0
306 #define SET_SNMP_STRIKE_FLAGS(x) \
307 (( x & SNMP_FLAGS_STRIKE2 ) ? 1 : \
308 ((( x & SNMP_FLAGS_STRIKE1 ) ? ( x |= SNMP_FLAGS_STRIKE2 ) : \
309 ( x |= SNMP_FLAGS_STRIKE1 )), \
313 * Error return values.
315 * SNMPERR_SUCCESS is the non-PDU "success" code.
317 * XXX These should be merged with SNMP_ERR_* defines and confined
320 #define SNMPERR_SUCCESS (0) /* XXX Non-PDU "success" code. */
321 #define SNMPERR_GENERR (-1)
322 #define SNMPERR_BAD_LOCPORT (-2)
323 #define SNMPERR_BAD_ADDRESS (-3)
324 #define SNMPERR_BAD_SESSION (-4)
325 #define SNMPERR_TOO_LONG (-5)
326 #define SNMPERR_NO_SOCKET (-6)
327 #define SNMPERR_V2_IN_V1 (-7)
328 #define SNMPERR_V1_IN_V2 (-8)
329 #define SNMPERR_BAD_REPEATERS (-9)
330 #define SNMPERR_BAD_REPETITIONS (-10)
331 #define SNMPERR_BAD_ASN1_BUILD (-11)
332 #define SNMPERR_BAD_SENDTO (-12)
333 #define SNMPERR_BAD_PARSE (-13)
334 #define SNMPERR_BAD_VERSION (-14)
335 #define SNMPERR_BAD_SRC_PARTY (-15)
336 #define SNMPERR_BAD_DST_PARTY (-16)
337 #define SNMPERR_BAD_CONTEXT (-17)
338 #define SNMPERR_BAD_COMMUNITY (-18)
339 #define SNMPERR_NOAUTH_DESPRIV (-19)
340 #define SNMPERR_BAD_ACL (-20)
341 #define SNMPERR_BAD_PARTY (-21)
342 #define SNMPERR_ABORT (-22)
343 #define SNMPERR_UNKNOWN_PDU (-23)
344 #define SNMPERR_TIMEOUT (-24)
345 #define SNMPERR_BAD_RECVFROM (-25)
346 #define SNMPERR_BAD_ENG_ID (-26)
347 #define SNMPERR_BAD_SEC_NAME (-27)
348 #define SNMPERR_BAD_SEC_LEVEL (-28)
349 #define SNMPERR_ASN_PARSE_ERR (-29)
350 #define SNMPERR_UNKNOWN_SEC_MODEL (-30)
351 #define SNMPERR_INVALID_MSG (-31)
352 #define SNMPERR_UNKNOWN_ENG_ID (-32)
353 #define SNMPERR_UNKNOWN_USER_NAME (-33)
354 #define SNMPERR_UNSUPPORTED_SEC_LEVEL (-34)
355 #define SNMPERR_AUTHENTICATION_FAILURE (-35)
356 #define SNMPERR_NOT_IN_TIME_WINDOW (-36)
357 #define SNMPERR_DECRYPTION_ERR (-37)
358 #define SNMPERR_SC_GENERAL_FAILURE (-38)
359 #define SNMPERR_SC_NOT_CONFIGURED (-39)
360 #define SNMPERR_KT_NOT_AVAILABLE (-40)
361 #define SNMPERR_UNKNOWN_REPORT (-41)
362 #define SNMPERR_USM_GENERICERROR (-42)
363 #define SNMPERR_USM_UNKNOWNSECURITYNAME (-43)
364 #define SNMPERR_USM_UNSUPPORTEDSECURITYLEVEL (-44)
365 #define SNMPERR_USM_ENCRYPTIONERROR (-45)
366 #define SNMPERR_USM_AUTHENTICATIONFAILURE (-46)
367 #define SNMPERR_USM_PARSEERROR (-47)
368 #define SNMPERR_USM_UNKNOWNENGINEID (-48)
369 #define SNMPERR_USM_NOTINTIMEWINDOW (-49)
370 #define SNMPERR_USM_DECRYPTIONERROR (-50)
371 #define SNMPERR_NOMIB (-51)
372 #define SNMPERR_RANGE (-52)
373 #define SNMPERR_MAX_SUBID (-53)
374 #define SNMPERR_BAD_SUBID (-54)
375 #define SNMPERR_LONG_OID (-55)
376 #define SNMPERR_BAD_NAME (-56)
377 #define SNMPERR_VALUE (-57)
378 #define SNMPERR_UNKNOWN_OBJID (-58)
379 #define SNMPERR_NULL_PDU (-59)
380 #define SNMPERR_NO_VARS (-60)
381 #define SNMPERR_VAR_TYPE (-61)
382 #define SNMPERR_MALLOC (-62)
383 #define SNMPERR_KRB5 (-63)
385 #define SNMPERR_MAX (-63)
387 #define non_repeaters errstat
388 #define max_repetitions errindex
390 struct variable_list {
391 struct variable_list *next_variable; /* NULL for last variable */
392 oid *name; /* Object identifier of variable */
393 size_t name_length; /* number of subid's in name */
394 u_char type; /* ASN type of variable */
395 union { /* value of variable */
400 struct counter64 *counter64;
401 #ifdef OPAQUE_SPECIAL_TYPES
407 #endif /* OPAQUE_SPECIAL_TYPES */
410 oid name_loc[MAX_OID_LEN]; /* 90 percentile < 24. */
411 u_char buf[40]; /* 90 percentile < 40. */
412 void *data; /* (Opaque) hook for additional data */
413 void (*dataFreeHook)(void *); /* callback to free above */
420 * netsnmp_session *snmp_open(session)
421 * netsnmp_session *session;
423 * Sets up the session with the snmp_session information provided
424 * by the user. Then opens and binds the necessary UDP port.
425 * A handle to the created session is returned (this is different than
426 * the pointer passed to snmp_open()). On any error, NULL is returned
427 * and snmp_errno is set to the appropriate error code.
429 netsnmp_session *snmp_open(netsnmp_session *);
432 * int snmp_close(session)
433 * netsnmp_session *session;
435 * Close the input session. Frees all data allocated for the session,
436 * dequeues any pending requests, and closes any sockets allocated for
437 * the session. Returns 0 on error, 1 otherwise.
439 * snmp_close_sessions() does the same thing for all open sessions
441 int snmp_close(netsnmp_session *);
442 int snmp_close_sessions(void);
446 * int snmp_send(session, pdu)
447 * netsnmp_session *session;
450 * Sends the input pdu on the session after calling snmp_build to create
451 * a serialized packet. If necessary, set some of the pdu data from the
452 * session defaults. Add a request corresponding to this pdu to the list
453 * of outstanding requests on this session, then send the pdu.
454 * Returns the request id of the generated packet if applicable, otherwise 1.
455 * On any error, 0 is returned.
456 * The pdu is freed by snmp_send() unless a failure occured.
458 int snmp_send(netsnmp_session *, netsnmp_pdu *);
461 * int snmp_async_send(session, pdu, callback, cb_data)
462 * netsnmp_session *session;
464 * netsnmp_callback callback;
467 * Sends the input pdu on the session after calling snmp_build to create
468 * a serialized packet. If necessary, set some of the pdu data from the
469 * session defaults. Add a request corresponding to this pdu to the list
470 * of outstanding requests on this session and store callback and data,
472 * Returns the request id of the generated packet if applicable, otherwise 1.
473 * On any error, 0 is returned.
474 * The pdu is freed by snmp_send() unless a failure occured.
476 int snmp_async_send(netsnmp_session *, netsnmp_pdu *,
477 netsnmp_callback, void *);
481 * void snmp_read(fdset)
484 * Checks to see if any of the fd's set in the fdset belong to
485 * snmp. Each socket with it's fd set has a packet read from it
486 * and snmp_parse is called on the packet received. The resulting pdu
487 * is passed to the callback routine for that session. If the callback
488 * routine returns successfully, the pdu and it's request are deleted.
490 void snmp_read(fd_set *);
499 * Frees the pdu and any malloc'd data associated with it.
501 void snmp_free_pdu(netsnmp_pdu *);
503 void snmp_free_var(netsnmp_variable_list *); /* frees just this one */
505 void snmp_free_varbind(netsnmp_variable_list * var); /* frees all in list */
508 * int snmp_select_info(numfds, fdset, timeout, block)
511 * struct timeval *timeout;
514 * Returns info about what snmp requires from a select statement.
515 * numfds is the number of fds in the list that are significant.
516 * All file descriptors opened for SNMP are OR'd into the fdset.
517 * If activity occurs on any of these file descriptors, snmp_read
518 * should be called with that file descriptor set.
520 * The timeout is the latest time that SNMP can wait for a timeout. The
521 * select should be done with the minimum time between timeout and any other
522 * timeouts necessary. This should be checked upon each invocation of select.
523 * If a timeout is received, snmp_timeout should be called to check if the
524 * timeout was for SNMP. (snmp_timeout is idempotent)
526 * Block is 1 if the select is requested to block indefinitely, rather than
527 * time out. If block is input as 1, the timeout value will be treated as
528 * undefined, but it must be available for setting in snmp_select_info. On
529 * return, if block is true, the value of timeout will be undefined.
531 * snmp_select_info returns the number of open sockets. (i.e. The number
534 int snmp_select_info(int *, fd_set *, struct timeval *,
540 * void snmp_timeout();
542 * snmp_timeout should be called whenever the timeout from snmp_select_info
543 * expires, but it is idempotent, so snmp_timeout can be polled (probably a
544 * cpu expensive proposition). snmp_timeout checks to see if any of the
545 * sessions have an outstanding request that has timed out. If it finds one
546 * (or more), and that pdu has more retries available, a new packet is formed
547 * from the pdu and is resent. If there are no more retries available, the
548 * callback for the session is used to alert the user of the timeout.
551 void snmp_timeout(void);
555 * This routine must be supplied by the application:
557 * u_char *authenticator(pdu, length, community, community_len)
558 * u_char *pdu; The rest of the PDU to be authenticated
559 * int *length; The length of the PDU (updated by the authenticator)
560 * u_char *community; The community name to authenticate under.
561 * int community_len The length of the community name.
563 * Returns the authenticated pdu, or NULL if authentication failed.
564 * If null authentication is used, the authenticator in snmp_session can be
571 * This routine must be supplied by the application:
573 * int callback(operation, session, reqid, pdu, magic)
575 * netsnmp_session *session; The session authenticated under.
576 * int reqid; The request id of this pdu (0 for TRAP)
577 * netsnmp_pdu *pdu; The pdu information.
578 * void *magic A link to the data for this routine.
580 * Returns 1 if request was successful, 0 if it should be kept pending.
581 * Any data in the pdu must be copied because it will be freed elsewhere.
582 * Operations are defined below:
585 #define NETSNMP_CALLBACK_OP_RECEIVED_MESSAGE 1
586 #define NETSNMP_CALLBACK_OP_TIMED_OUT 2
587 #define NETSNMP_CALLBACK_OP_SEND_FAILED 3
588 #define NETSNMP_CALLBACK_OP_CONNECT 4
589 #define NETSNMP_CALLBACK_OP_DISCONNECT 5
591 long snmp_get_next_msgid(void);
592 long snmp_get_next_reqid(void);
593 long snmp_get_next_sessid(void);
594 long snmp_get_next_transid(void);
596 int snmp_oid_compare(const oid *, size_t, const oid *,
598 int snmp_oid_ncompare(const oid *, size_t, const oid *,
600 int snmp_oidtree_compare(const oid *, size_t, const oid *,
602 int netsnmp_oid_equals(const oid *, size_t, const oid *,
604 int netsnmp_oid_tree_equals(const oid *, size_t, const oid *,
606 int netsnmp_oid_is_subtree(const oid *, size_t, const oid *,
608 int netsnmp_oid_find_prefix(const oid * in_name1, size_t len1,
609 const oid * in_name2, size_t len2);
610 void init_snmp(const char *);
611 u_char *snmp_pdu_build(netsnmp_pdu *, u_char *, size_t *);
612 #ifdef USE_REVERSE_ASNENCODING
613 u_char *snmp_pdu_rbuild(netsnmp_pdu *, u_char *, size_t *);
615 int snmpv3_parse(netsnmp_pdu *, u_char *, size_t *,
616 u_char **, netsnmp_session *);
617 int snmpv3_packet_build(netsnmp_session *,
618 netsnmp_pdu *pdu, u_char * packet,
621 size_t pdu_data_len);
622 int snmpv3_packet_rbuild(netsnmp_session *,
623 netsnmp_pdu *pdu, u_char * packet,
626 size_t pdu_data_len);
627 int snmpv3_make_report(netsnmp_pdu *pdu, int error);
628 int snmpv3_get_report_type(netsnmp_pdu *pdu);
629 int snmp_pdu_parse(netsnmp_pdu *pdu, u_char * data,
631 u_char *snmpv3_scopedPDU_parse(netsnmp_pdu *pdu, u_char * cp,
633 void snmp_store(const char *type);
634 void snmp_shutdown(const char *type);
635 netsnmp_variable_list *snmp_pdu_add_variable(netsnmp_pdu *, oid *,
636 size_t, u_char, const u_char *,
638 netsnmp_variable_list *snmp_varlist_add_variable(netsnmp_variable_list
643 const u_char * value,
645 int snmp_add_var(netsnmp_pdu *, oid *, size_t, char,
647 oid *snmp_duplicate_objid(const oid * objToCopy, size_t);
648 u_int snmp_increment_statistic(int which);
649 u_int snmp_increment_statistic_by(int which, int count);
650 u_int snmp_get_statistic(int which);
651 void snmp_init_statistics(void);
652 int create_user_from_session(netsnmp_session * session);
655 * New re-allocating reverse encoding functions.
657 #ifdef USE_REVERSE_ASNENCODING
659 int snmpv3_packet_realloc_rbuild(u_char ** pkt, size_t * pkt_len,
661 netsnmp_session * session,
662 netsnmp_pdu *pdu, u_char * pdu_data,
663 size_t pdu_data_len);
665 int snmp_pdu_realloc_rbuild(u_char ** pkt, size_t * pkt_len,
666 size_t * offset, netsnmp_pdu *pdu);
672 * Extended open; fpre_parse has changed.
675 netsnmp_session *snmp_open_ex(netsnmp_session *,
676 int (*fpre_parse) (netsnmp_session *,
678 netsnmp_transport_s *,
680 int (*fparse) (netsnmp_session *,
681 netsnmp_pdu *, u_char *,
683 int (*fpost_parse) (netsnmp_session *,
685 int (*fbuild) (netsnmp_session *,
686 netsnmp_pdu *, u_char *,
688 int (*frbuild) (netsnmp_session *,
689 netsnmp_pdu *, u_char **,
691 int (*fcheck) (u_char *, size_t));
694 * provided for backwards compatability. Don't use these functions.
695 * See snmp_debug.h and snmp_debug.c instead.
698 void snmp_set_do_debugging(int);
699 int snmp_get_do_debugging(void);
703 * snmp_error - return error data
704 * Inputs : address of errno, address of snmp_errno, address of string
705 * Caller must free the string returned after use.
707 void snmp_error(netsnmp_session *, int *, int *, char **);
709 * single session API.
711 * These functions perform similar actions as snmp_XX functions,
712 * but operate on a single session only.
717 netsnmp_session session, *ss;
718 netsnmp_pdu *pdu, *response;
720 snmp_sess_init(&session);
721 session.retries = ...
722 session.remote_port = ...
723 sessp = snmp_sess_open(&session);
724 ss = snmp_sess_session(sessp);
728 if (ss->community) free(ss->community);
729 ss->community = strdup(gateway);
730 ss->community_len = strlen(gateway);
732 snmp_sess_synch_response(sessp, pdu, &response);
734 snmp_sess_close(sessp);
737 * snmp_sess_synch_response, in snmp_client.h.
740 * 1. Invoke snmp_sess_session after snmp_sess_open.
741 * 2. snmp_sess_session return value is an opaque pointer.
742 * 3. Do NOT free memory returned by snmp_sess_session.
743 * 4. Replace snmp_send(ss,pdu) with snmp_sess_send(sessp,pdu)
746 void snmp_sess_init(netsnmp_session *);
747 void *snmp_sess_open(netsnmp_session *);
748 void *snmp_sess_pointer(netsnmp_session *);
749 netsnmp_session *snmp_sess_session(void *);
752 * Return the netsnmp_transport structure associated with the given opaque
756 struct netsnmp_transport_s *snmp_sess_transport(void *);
757 void snmp_sess_transport_set(void *,
758 struct netsnmp_transport_s *);
761 * EXPERIMENTAL API EXTENSIONS ------------------------------------------
763 * snmp_sess_add_ex, snmp_sess_add, snmp_add
765 * Analogous to snmp_open family of functions, but taking an
766 * netsnmp_transport pointer as an extra argument. Unlike snmp_open et
767 * al. it doesn't attempt to interpret the in_session->peername as a
768 * transport endpoint specifier, but instead uses the supplied transport.
773 void *snmp_sess_add_ex(netsnmp_session *,
774 struct netsnmp_transport_s *,
775 int (*fpre_parse) (netsnmp_session *,
779 int (*fparse) (netsnmp_session *,
782 int (*fpost_parse) (netsnmp_session *,
785 int (*fbuild) (netsnmp_session *,
788 int (*frbuild) (netsnmp_session *,
792 int (*fcheck) (u_char *, size_t),
793 netsnmp_pdu *(*fcreate_pdu) (struct
799 void *snmp_sess_add(netsnmp_session *,
800 struct netsnmp_transport_s *,
801 int (*fpre_parse) (netsnmp_session *,
803 netsnmp_transport_s *,
805 int (*fpost_parse) (netsnmp_session *,
806 netsnmp_pdu *, int));
808 netsnmp_session *snmp_add(netsnmp_session *,
809 struct netsnmp_transport_s *,
810 int (*fpre_parse) (netsnmp_session *,
811 struct netsnmp_transport_s
813 int (*fpost_parse) (netsnmp_session *,
814 netsnmp_pdu *, int));
815 netsnmp_session *snmp_add_full(netsnmp_session * in_session,
816 struct netsnmp_transport_s *transport,
817 int (*fpre_parse) (netsnmp_session *,
821 int (*fparse) (netsnmp_session *,
822 netsnmp_pdu *, u_char *,
824 int (*fpost_parse) (netsnmp_session *,
826 int (*fbuild) (netsnmp_session *,
827 netsnmp_pdu *, u_char *,
829 int (*frbuild) (netsnmp_session *,
833 int (*fcheck) (u_char *, size_t),
834 netsnmp_pdu *(*fcreate_pdu) (struct
841 * use return value from snmp_sess_open as void * parameter
844 int snmp_sess_send(void *, netsnmp_pdu *);
845 int snmp_sess_async_send(void *, netsnmp_pdu *,
846 netsnmp_callback, void *);
847 int snmp_sess_select_info(void *, int *, fd_set *,
848 struct timeval *, int *);
849 int snmp_sess_read(void *, fd_set *);
850 void snmp_sess_timeout(void *);
851 int snmp_sess_close(void *);
853 void snmp_sess_error(void *, int *, int *, char **);
854 void netsnmp_sess_log_error(int priority,
855 const char *prog_string,
856 netsnmp_session * ss);
857 void snmp_sess_perror(const char *prog_string,
858 netsnmp_session * ss);
861 * end single session API
865 * generic statistic counters
875 #define STAT_SNMPUNKNOWNSECURITYMODELS 0
876 #define STAT_SNMPINVALIDMSGS 1
877 #define STAT_SNMPUNKNOWNPDUHANDLERS 2
878 #define STAT_MPD_STATS_START STAT_SNMPUNKNOWNSECURITYMODELS
879 #define STAT_MPD_STATS_END STAT_SNMPUNKNOWNPDUHANDLERS
884 #define STAT_USMSTATSUNSUPPORTEDSECLEVELS 3
885 #define STAT_USMSTATSNOTINTIMEWINDOWS 4
886 #define STAT_USMSTATSUNKNOWNUSERNAMES 5
887 #define STAT_USMSTATSUNKNOWNENGINEIDS 6
888 #define STAT_USMSTATSWRONGDIGESTS 7
889 #define STAT_USMSTATSDECRYPTIONERRORS 8
890 #define STAT_USM_STATS_START STAT_USMSTATSUNSUPPORTEDSECLEVELS
891 #define STAT_USM_STATS_END STAT_USMSTATSDECRYPTIONERRORS
896 #define STAT_SNMPINPKTS 9
897 #define STAT_SNMPOUTPKTS 10
898 #define STAT_SNMPINBADVERSIONS 11
899 #define STAT_SNMPINBADCOMMUNITYNAMES 12
900 #define STAT_SNMPINBADCOMMUNITYUSES 13
901 #define STAT_SNMPINASNPARSEERRS 14
903 * #define STAT_SNMPINBADTYPES 15
905 #define STAT_SNMPINTOOBIGS 16
906 #define STAT_SNMPINNOSUCHNAMES 17
907 #define STAT_SNMPINBADVALUES 18
908 #define STAT_SNMPINREADONLYS 19
909 #define STAT_SNMPINGENERRS 20
910 #define STAT_SNMPINTOTALREQVARS 21
911 #define STAT_SNMPINTOTALSETVARS 22
912 #define STAT_SNMPINGETREQUESTS 23
913 #define STAT_SNMPINGETNEXTS 24
914 #define STAT_SNMPINSETREQUESTS 25
915 #define STAT_SNMPINGETRESPONSES 26
916 #define STAT_SNMPINTRAPS 27
917 #define STAT_SNMPOUTTOOBIGS 28
918 #define STAT_SNMPOUTNOSUCHNAMES 29
919 #define STAT_SNMPOUTBADVALUES 30
921 * #define STAT_SNMPOUTREADONLYS 31
923 #define STAT_SNMPOUTGENERRS 32
924 #define STAT_SNMPOUTGETREQUESTS 33
925 #define STAT_SNMPOUTGETNEXTS 34
926 #define STAT_SNMPOUTSETREQUESTS 35
927 #define STAT_SNMPOUTGETRESPONSES 36
928 #define STAT_SNMPOUTTRAPS 37
932 #define STAT_SNMPSILENTDROPS 39
933 #define STAT_SNMPPROXYDROPS 40
934 #define STAT_SNMP_STATS_START STAT_SNMPINPKTS
935 #define STAT_SNMP_STATS_END STAT_SNMPPROXYDROPS
938 * target mib counters
940 #define STAT_SNMPUNAVAILABLECONTEXTS 41
941 #define STAT_SNMPUNKNOWNCONTEXTS 42
942 #define STAT_TARGET_STATS_START STAT_SNMPUNAVAILABLECONTEXTS
943 #define STAT_TARGET_STATS_END STAT_SNMPUNKNOWNCONTEXTS
950 #endif /* SNMP_API_H */