Details | Last modification | View Log | RSS feed
Rev | Author | Line No. | Line |
---|---|---|---|
147 | f9daq | 1 | #ifndef _NETSNMPLIB_H |
2 | #define _NETSNMPLIB_H |
||
3 | |||
4 | |||
5 | #define false 0; |
||
6 | #define true 1; |
||
7 | |||
8 | |||
9 | #include <winsock2.h> |
||
10 | #include <ws2tcpip.h> |
||
11 | #include <stdio.h> |
||
12 | |||
13 | |||
14 | #include <net-snmp/net-snmp-config.h> |
||
15 | |||
16 | |||
17 | /* |
||
18 | * Basic system type definitions, taken from the BSD file sys/types.h. |
||
19 | */ |
||
20 | typedef unsigned char u_char; |
||
21 | typedef unsigned short u_short; |
||
22 | typedef unsigned int u_int; |
||
23 | typedef unsigned long u_long; |
||
24 | |||
25 | #include <net-snmp/library/asn1.h> |
||
26 | #include <net-snmp/library/snmp.h> |
||
27 | |||
28 | |||
29 | #define SNMP_VERSION_2c 1 |
||
30 | typedef void *HSNMP; // SNMP handle (like FILE) |
||
31 | |||
32 | |||
33 | |||
34 | /* |
||
35 | * For the initial release, this will just refer to the |
||
36 | * relevant UCD header files. |
||
37 | * In due course, the types and structures relevant to the |
||
38 | * Net-SNMP API will be identified, and defined here directly. |
||
39 | * |
||
40 | * But for the time being, this header file is primarily a placeholder, |
||
41 | * to allow application writers to adopt the new header file names. |
||
42 | */ |
||
43 | |||
44 | typedef union { |
||
45 | long *integer; |
||
46 | u_char *string; |
||
47 | oid *objid; |
||
48 | u_char *bitstring; |
||
49 | struct counter64 *counter64; |
||
50 | #ifdef NETSNMP_WITH_OPAQUE_SPECIAL_TYPES |
||
51 | float *floatVal; |
||
52 | double *doubleVal; |
||
53 | /* |
||
54 | * t_union *unionVal; |
||
55 | */ |
||
56 | #endif /* NETSNMP_WITH_OPAQUE_SPECIAL_TYPES */ |
||
57 | } netsnmp_vardata; |
||
58 | |||
59 | |||
60 | /** @typedef struct variable_list netsnmp_variable_list |
||
61 | * Typedefs the variable_list struct into netsnmp_variable_list */ |
||
62 | /** @struct variable_list |
||
63 | * The netsnmp variable list binding structure, it's typedef'd to |
||
64 | * netsnmp_variable_list. |
||
65 | */ |
||
66 | typedef struct variable_list { |
||
67 | /** NULL for last variable */ |
||
68 | struct variable_list *next_variable; |
||
69 | /** Object identifier of variable */ |
||
70 | oid *name; |
||
71 | /** number of subid's in name */ |
||
72 | size_t name_length; |
||
73 | /** ASN type of variable */ |
||
74 | u_char type; |
||
75 | /** value of variable */ |
||
76 | netsnmp_vardata val; |
||
77 | /** the length of the value to be copied into buf */ |
||
78 | size_t val_len; |
||
79 | /** 90 percentile < 24. */ |
||
80 | oid name_loc[MAX_OID_LEN]; |
||
81 | /** 90 percentile < 40. */ |
||
82 | u_char buf[40]; |
||
83 | /** (Opaque) hook for additional data */ |
||
84 | void *data; |
||
85 | /** callback to free above */ |
||
86 | void (*dataFreeHook)(void *); |
||
87 | int index; |
||
88 | } netsnmp_variable_list; |
||
89 | |||
90 | /** @typedef struct snmp_pdu to netsnmp_pdu |
||
91 | * Typedefs the snmp_pdu struct into netsnmp_pdu */ |
||
92 | /** @struct snmp_pdu |
||
93 | * The snmp protocol data unit. |
||
94 | */ |
||
95 | typedef struct snmp_pdu { |
||
96 | |||
97 | #define non_repeaters errstat |
||
98 | #define max_repetitions errindex |
||
99 | |||
100 | /* |
||
101 | * Protocol-version independent fields |
||
102 | */ |
||
103 | /** snmp version */ |
||
104 | long version; |
||
105 | /** Type of this PDU */ |
||
106 | int command; |
||
107 | /** Request id - note: not incremented on retries */ |
||
108 | long reqid; |
||
109 | /** Message id for V3 messages note: incremented for each retry */ |
||
110 | long msgid; |
||
111 | /** Unique ID for incoming transactions */ |
||
112 | long transid; |
||
113 | /** Session id for AgentX messages */ |
||
114 | long sessid; |
||
115 | /** Error status (non_repeaters in GetBulk) */ |
||
116 | long errstat; |
||
117 | /** Error index (max_repetitions in GetBulk) */ |
||
118 | long errindex; |
||
119 | /** Uptime */ |
||
120 | u_long time; |
||
121 | u_long flags; |
||
122 | |||
123 | int securityModel; |
||
124 | /** noAuthNoPriv, authNoPriv, authPriv */ |
||
125 | int securityLevel; |
||
126 | int msgParseModel; |
||
127 | |||
128 | /** |
||
129 | * Transport-specific opaque data. This replaces the IP-centric address |
||
130 | * field. |
||
131 | */ |
||
132 | |||
133 | void *transport_data; |
||
134 | int transport_data_length; |
||
135 | |||
136 | /** |
||
137 | * The actual transport domain. This SHOULD NOT BE FREE()D. |
||
138 | */ |
||
139 | |||
140 | const oid *tDomain; |
||
141 | size_t tDomainLen; |
||
142 | |||
143 | netsnmp_variable_list *variables; |
||
144 | |||
145 | |||
146 | /* |
||
147 | * SNMPv1 & SNMPv2c fields |
||
148 | */ |
||
149 | /** community for outgoing requests. */ |
||
150 | u_char *community; |
||
151 | /** length of community name. */ |
||
152 | size_t community_len; |
||
153 | |||
154 | /* |
||
155 | * Trap information |
||
156 | */ |
||
157 | /** System OID */ |
||
158 | oid *enterprise; |
||
159 | size_t enterprise_length; |
||
160 | /** trap type */ |
||
161 | long trap_type; |
||
162 | /** specific type */ |
||
163 | long specific_type; |
||
164 | /** This is ONLY used for v1 TRAPs */ |
||
165 | unsigned char agent_addr[4]; |
||
166 | |||
167 | /* |
||
168 | * SNMPv3 fields |
||
169 | */ |
||
170 | /** context snmpEngineID */ |
||
171 | u_char *contextEngineID; |
||
172 | /** Length of contextEngineID */ |
||
173 | size_t contextEngineIDLen; |
||
174 | /** authoritative contextName */ |
||
175 | char *contextName; |
||
176 | /** Length of contextName */ |
||
177 | size_t contextNameLen; |
||
178 | /** authoritative snmpEngineID for security */ |
||
179 | u_char *securityEngineID; |
||
180 | /** Length of securityEngineID */ |
||
181 | size_t securityEngineIDLen; |
||
182 | /** on behalf of this principal */ |
||
183 | char *securityName; |
||
184 | /** Length of securityName. */ |
||
185 | size_t securityNameLen; |
||
186 | |||
187 | /* |
||
188 | * AgentX fields |
||
189 | * (also uses SNMPv1 community field) |
||
190 | */ |
||
191 | int priority; |
||
192 | int range_subid; |
||
193 | |||
194 | void *securityStateRef; |
||
195 | } netsnmp_pdu; |
||
196 | |||
197 | |||
198 | struct snmp_session; |
||
199 | typedef struct snmp_session netsnmp_session; |
||
200 | |||
201 | |||
202 | #define USM_AUTH_KU_LEN 32 |
||
203 | #define USM_PRIV_KU_LEN 32 |
||
204 | |||
205 | |||
206 | typedef int (*netsnmp_callback) (int, netsnmp_session *, int, |
||
207 | netsnmp_pdu *, void *); |
||
208 | |||
209 | /** @struct snmp_session |
||
210 | * The snmp session structure. |
||
211 | */ |
||
212 | struct snmp_session { |
||
213 | /* |
||
214 | * Protocol-version independent fields |
||
215 | */ |
||
216 | /** snmp version */ |
||
217 | long version; |
||
218 | /** Number of retries before timeout. */ |
||
219 | int retries; |
||
220 | /** Number of uS until first timeout, then exponential backoff */ |
||
221 | long timeout; |
||
222 | u_long flags; |
||
223 | struct snmp_session *subsession; |
||
224 | struct snmp_session *next; |
||
225 | |||
226 | /** name or address of default peer (may include transport specifier and/or port number) */ |
||
227 | char *peername; |
||
228 | /** UDP port number of peer. (NO LONGER USED - USE peername INSTEAD) */ |
||
229 | u_short remote_port; |
||
230 | /** My Domain name or dotted IP address, 0 for default */ |
||
231 | char *localname; |
||
232 | /** My UDP port number, 0 for default, picked randomly */ |
||
233 | u_short local_port; |
||
234 | /** |
||
235 | * Authentication function or NULL if null authentication is used |
||
236 | */ |
||
237 | u_char *(*authenticator) (u_char *, size_t *, u_char *, size_t); |
||
238 | /** Function to interpret incoming data */ |
||
239 | netsnmp_callback callback; |
||
240 | /** |
||
241 | * Pointer to data that the callback function may consider important |
||
242 | */ |
||
243 | void *callback_magic; |
||
244 | /** copy of system errno */ |
||
245 | int s_errno; |
||
246 | /** copy of library errno */ |
||
247 | int s_snmp_errno; |
||
248 | /** Session id - AgentX only */ |
||
249 | long sessid; |
||
250 | |||
251 | /* |
||
252 | * SNMPv1 & SNMPv2c fields |
||
253 | */ |
||
254 | /** community for outgoing requests. */ |
||
255 | u_char *community; |
||
256 | /** Length of community name. */ |
||
257 | size_t community_len; |
||
258 | /** Largest message to try to receive. */ |
||
259 | size_t rcvMsgMaxSize; |
||
260 | /** Largest message to try to send. */ |
||
261 | size_t sndMsgMaxSize; |
||
262 | |||
263 | /* |
||
264 | * SNMPv3 fields |
||
265 | */ |
||
266 | /** are we the authoritative engine? */ |
||
267 | u_char isAuthoritative; |
||
268 | /** authoritative snmpEngineID */ |
||
269 | u_char *contextEngineID; |
||
270 | /** Length of contextEngineID */ |
||
271 | size_t contextEngineIDLen; |
||
272 | /** initial engineBoots for remote engine */ |
||
273 | u_int engineBoots; |
||
274 | /** initial engineTime for remote engine */ |
||
275 | u_int engineTime; |
||
276 | /** authoritative contextName */ |
||
277 | char *contextName; |
||
278 | /** Length of contextName */ |
||
279 | size_t contextNameLen; |
||
280 | /** authoritative snmpEngineID */ |
||
281 | u_char *securityEngineID; |
||
282 | /** Length of contextEngineID */ |
||
283 | size_t securityEngineIDLen; |
||
284 | /** on behalf of this principal */ |
||
285 | char *securityName; |
||
286 | /** Length of securityName. */ |
||
287 | size_t securityNameLen; |
||
288 | |||
289 | /** auth protocol oid */ |
||
290 | oid *securityAuthProto; |
||
291 | /** Length of auth protocol oid */ |
||
292 | size_t securityAuthProtoLen; |
||
293 | /** Ku for auth protocol XXX */ |
||
294 | u_char securityAuthKey[USM_AUTH_KU_LEN]; |
||
295 | /** Length of Ku for auth protocol */ |
||
296 | size_t securityAuthKeyLen; |
||
297 | /** Kul for auth protocol */ |
||
298 | u_char *securityAuthLocalKey; |
||
299 | /** Length of Kul for auth protocol XXX */ |
||
300 | size_t securityAuthLocalKeyLen; |
||
301 | |||
302 | /** priv protocol oid */ |
||
303 | oid *securityPrivProto; |
||
304 | /** Length of priv protocol oid */ |
||
305 | size_t securityPrivProtoLen; |
||
306 | /** Ku for privacy protocol XXX */ |
||
307 | u_char securityPrivKey[USM_PRIV_KU_LEN]; |
||
308 | /** Length of Ku for priv protocol */ |
||
309 | size_t securityPrivKeyLen; |
||
310 | /** Kul for priv protocol */ |
||
311 | u_char *securityPrivLocalKey; |
||
312 | /** Length of Kul for priv protocol XXX */ |
||
313 | size_t securityPrivLocalKeyLen; |
||
314 | |||
315 | /** snmp security model, v1, v2c, usm */ |
||
316 | int securityModel; |
||
317 | /** noAuthNoPriv, authNoPriv, authPriv */ |
||
318 | int securityLevel; |
||
319 | /** target param name */ |
||
320 | char *paramName; |
||
321 | |||
322 | /** |
||
323 | * security module specific |
||
324 | */ |
||
325 | void *securityInfo; |
||
326 | |||
327 | /** |
||
328 | * use as you want data |
||
329 | * |
||
330 | * used by 'SNMP_FLAGS_RESP_CALLBACK' handling in the agent |
||
331 | * XXX: or should we add a new field into this structure? |
||
332 | */ |
||
333 | void *myvoid; |
||
334 | }; |
||
335 | |||
336 | |||
337 | /** |
||
338 | * Structure for holding a set of file descriptors, similar to fd_set. |
||
339 | * |
||
340 | * This structure however can hold so-called large file descriptors |
||
341 | * (>= FD_SETSIZE or 1024) on Unix systems or more than FD_SETSIZE (64) |
||
342 | * sockets on Windows systems. |
||
343 | * |
||
344 | * It is safe to allocate this structure on the stack. |
||
345 | * |
||
346 | * This structure must be initialized by calling netsnmp_large_fd_set_init() |
||
347 | * and must be cleaned up via netsnmp_large_fd_set_cleanup(). If this last |
||
348 | * function is not called this may result in a memory leak. |
||
349 | */ |
||
350 | typedef struct netsnmp_large_fd_set_s { |
||
351 | /** Maximum set size. */ |
||
352 | unsigned lfs_setsize; |
||
353 | /** |
||
354 | * Points to lfs_set if lfs_setsize <= FD_SETSIZE, and otherwise |
||
355 | * to dynamically allocated memory. |
||
356 | */ |
||
357 | fd_set *lfs_setptr; |
||
358 | /** File descriptor / socket set data if lfs_setsize <= FD_SETSIZE. */ |
||
359 | fd_set lfs_set; |
||
360 | } netsnmp_large_fd_set; |
||
361 | |||
362 | |||
363 | /* |
||
364 | * A tree in the format of the tree structure of the MIB. |
||
365 | */ |
||
366 | struct tree { |
||
367 | struct tree *child_list; /* list of children of this node */ |
||
368 | struct tree *next_peer; /* Next node in list of peers */ |
||
369 | struct tree *next; /* Next node in hashed list of names */ |
||
370 | struct tree *parent; |
||
371 | char *label; /* This node's textual name */ |
||
372 | u_long subid; /* This node's integer subidentifier */ |
||
373 | int modid; /* The module containing this node */ |
||
374 | int number_modules; |
||
375 | int *module_list; /* To handle multiple modules */ |
||
376 | int tc_index; /* index into tclist (-1 if NA) */ |
||
377 | int type; /* This node's object type */ |
||
378 | int access; /* This nodes access */ |
||
379 | int status; /* This nodes status */ |
||
380 | struct enum_list *enums; /* (optional) list of enumerated integers */ |
||
381 | struct range_list *ranges; |
||
382 | struct index_list *indexes; |
||
383 | char *augments; |
||
384 | struct varbind_list *varbinds; |
||
385 | char *hint; |
||
386 | char *units; |
||
387 | int (*printomat) (u_char **, size_t *, size_t *, int, |
||
388 | const netsnmp_variable_list *, |
||
389 | const struct enum_list *, const char *, |
||
390 | const char *); |
||
391 | void (*printer) (char *, const netsnmp_variable_list *, const struct enum_list *, const char *, const char *); /* Value printing function */ |
||
392 | char *description; /* description (a quoted string) */ |
||
393 | char *reference; /* references (a quoted string) */ |
||
394 | int reported; /* 1=report started in print_subtree... */ |
||
395 | char *defaultValue; |
||
396 | }; |
||
397 | |||
398 | |||
399 | |||
400 | |||
401 | netsnmp_pdu *snmp_pdu_create(int type); |
||
402 | netsnmp_pdu *snmp_clone_pdu(netsnmp_pdu *pdu); |
||
403 | netsnmp_pdu *snmp_fix_pdu( netsnmp_pdu *pdu, int idx); |
||
404 | void snmp_free_pdu( netsnmp_pdu *pdu); |
||
405 | |||
406 | |||
407 | void init_snmp(const char *); |
||
408 | void init_mib(void); |
||
409 | int get_node(const char *, oid *, size_t *); |
||
410 | void snmp_sess_init(netsnmp_session *); |
||
411 | struct tree *read_module(const char *); |
||
412 | |||
413 | |||
414 | |||
415 | /* Creation */ |
||
416 | netsnmp_variable_list * |
||
417 | snmp_pdu_add_variable(netsnmp_pdu *pdu, |
||
418 | const oid *name, size_t name_length, |
||
419 | u_char type, |
||
420 | const void *value, size_t len); |
||
421 | netsnmp_variable_list * |
||
422 | snmp_varlist_add_variable(netsnmp_variable_list **varlist, |
||
423 | const oid *name, size_t name_length, |
||
424 | u_char type, |
||
425 | const void *value, size_t len); |
||
426 | netsnmp_variable_list * |
||
427 | snmp_add_null_var(netsnmp_pdu *pdu, |
||
428 | const oid *name, size_t name_length); |
||
429 | netsnmp_variable_list * |
||
430 | snmp_clone_varbind(netsnmp_variable_list *varlist); |
||
431 | |||
432 | /* Setting Values */ |
||
433 | int snmp_set_var_value(netsnmp_variable_list *var, |
||
434 | const void *value, size_t len); |
||
435 | int snmp_set_var_objid(netsnmp_variable_list *var, |
||
436 | const oid *name, size_t name_length); |
||
437 | int snmp_set_var_typed_value(netsnmp_variable_list *var, |
||
438 | u_char type, |
||
439 | const void *value, size_t len); |
||
440 | int snmp_set_var_typed_integer(netsnmp_variable_list *var, |
||
441 | u_char type, long val); |
||
442 | |||
443 | /* Output */ |
||
444 | void print_variable(const oid *objid, size_t objidlen, |
||
445 | const netsnmp_variable_list *variable); |
||
446 | void fprint_variable(FILE *fp, |
||
447 | const oid *objid, size_t objidlen, |
||
448 | const netsnmp_variable_list *variable); |
||
449 | int snprint_variable(char *buf, size_t buf_len, |
||
450 | const oid *objid, size_t objidlen, |
||
451 | const netsnmp_variable_list *variable); |
||
452 | |||
453 | void print_value(const oid *objid, size_t objidlen, |
||
454 | const netsnmp_variable_list *variable); |
||
455 | void fprint_value(FILE *fp, |
||
456 | const oid *objid, size_t objidlen, |
||
457 | const netsnmp_variable_list *variable); |
||
458 | int snprint_value(char *buf, size_t buf_len, |
||
459 | const oid *objid, size_t objidlen, |
||
460 | const netsnmp_variable_list *variable); |
||
461 | |||
462 | /* Deletion */ |
||
463 | void snmp_free_var( netsnmp_variable_list *var); /* frees just this one */ |
||
464 | void snmp_free_varbind(netsnmp_variable_list *varlist); /* frees all in list */ |
||
465 | |||
466 | |||
467 | |||
468 | void snmp_sess_init(netsnmp_session *); |
||
469 | |||
470 | /* |
||
471 | * netsnmp_session *snmp_open(session) |
||
472 | * netsnmp_session *session; |
||
473 | * |
||
474 | * Sets up the session with the snmp_session information provided |
||
475 | * by the user. Then opens and binds the necessary UDP port. |
||
476 | * A handle to the created session is returned (this is different than |
||
477 | * the pointer passed to snmp_open()). On any error, NULL is returned |
||
478 | * and snmp_errno is set to the appropriate error code. |
||
479 | */ |
||
480 | netsnmp_session *snmp_open(netsnmp_session *); |
||
481 | |||
482 | /* |
||
483 | * int snmp_close(session) |
||
484 | * netsnmp_session *session; |
||
485 | * |
||
486 | * Close the input session. Frees all data allocated for the session, |
||
487 | * dequeues any pending requests, and closes any sockets allocated for |
||
488 | * the session. Returns 0 on error, 1 otherwise. |
||
489 | * |
||
490 | * snmp_close_sessions() does the same thing for all open sessions |
||
491 | */ |
||
492 | int snmp_close(netsnmp_session *); |
||
493 | int snmp_close_sessions(void); |
||
494 | |||
495 | |||
496 | /* |
||
497 | * int snmp_send(session, pdu) |
||
498 | * netsnmp_session *session; |
||
499 | * netsnmp_pdu *pdu; |
||
500 | * |
||
501 | * Sends the input pdu on the session after calling snmp_build to create |
||
502 | * a serialized packet. If necessary, set some of the pdu data from the |
||
503 | * session defaults. Add a request corresponding to this pdu to the list |
||
504 | * of outstanding requests on this session, then send the pdu. |
||
505 | * Returns the request id of the generated packet if applicable, otherwise 1. |
||
506 | * On any error, 0 is returned. |
||
507 | * The pdu is freed by snmp_send() unless a failure occured. |
||
508 | */ |
||
509 | int snmp_send(netsnmp_session *, netsnmp_pdu *); |
||
510 | |||
511 | /* |
||
512 | * int snmp_async_send(session, pdu, callback, cb_data) |
||
513 | * netsnmp_session *session; |
||
514 | * netsnmp_pdu *pdu; |
||
515 | * netsnmp_callback callback; |
||
516 | * void *cb_data; |
||
517 | * |
||
518 | * Sends the input pdu on the session after calling snmp_build to create |
||
519 | * a serialized packet. If necessary, set some of the pdu data from the |
||
520 | * session defaults. Add a request corresponding to this pdu to the list |
||
521 | * of outstanding requests on this session and store callback and data, |
||
522 | * then send the pdu. |
||
523 | * Returns the request id of the generated packet if applicable, otherwise 1. |
||
524 | * On any error, 0 is returned. |
||
525 | * The pdu is freed by snmp_send() unless a failure occured. |
||
526 | */ |
||
527 | int snmp_async_send(netsnmp_session *, netsnmp_pdu *, |
||
528 | netsnmp_callback, void *); |
||
529 | |||
530 | |||
531 | /* |
||
532 | * void snmp_read(fdset) |
||
533 | * fd_set *fdset; |
||
534 | * |
||
535 | * Checks to see if any of the fd's set in the fdset belong to |
||
536 | * snmp. Each socket with it's fd set has a packet read from it |
||
537 | * and snmp_parse is called on the packet received. The resulting pdu |
||
538 | * is passed to the callback routine for that session. If the callback |
||
539 | * routine returns successfully, the pdu and it's request are deleted. |
||
540 | */ |
||
541 | void snmp_read(fd_set *); |
||
542 | |||
543 | /* |
||
544 | * snmp_read2() is similar to snmp_read(), but accepts a pointer to a |
||
545 | * large file descriptor set instead of a pointer to a regular file |
||
546 | * descriptor set. |
||
547 | */ |
||
548 | void snmp_read2(netsnmp_large_fd_set *); |
||
549 | |||
550 | |||
551 | int snmp_synch_response(netsnmp_session *, netsnmp_pdu *, |
||
552 | netsnmp_pdu **); |
||
553 | |||
554 | /* |
||
555 | * int snmp_select_info(numfds, fdset, timeout, block) |
||
556 | * int *numfds; |
||
557 | * fd_set *fdset; |
||
558 | * struct timeval *timeout; |
||
559 | * int *block; |
||
560 | * |
||
561 | * Returns info about what snmp requires from a select statement. |
||
562 | * numfds is the number of fds in the list that are significant. |
||
563 | * All file descriptors opened for SNMP are OR'd into the fdset. |
||
564 | * If activity occurs on any of these file descriptors, snmp_read |
||
565 | * should be called with that file descriptor set. |
||
566 | * |
||
567 | * The timeout is the latest time that SNMP can wait for a timeout. The |
||
568 | * select should be done with the minimum time between timeout and any other |
||
569 | * timeouts necessary. This should be checked upon each invocation of select. |
||
570 | * If a timeout is received, snmp_timeout should be called to check if the |
||
571 | * timeout was for SNMP. (snmp_timeout is idempotent) |
||
572 | * |
||
573 | * Block is 1 if the select is requested to block indefinitely, rather than |
||
574 | * time out. If block is input as 1, the timeout value will be treated as |
||
575 | * undefined, but it must be available for setting in snmp_select_info. On |
||
576 | * return, if block is true, the value of timeout will be undefined. |
||
577 | * |
||
578 | * snmp_select_info returns the number of open sockets. (i.e. The number |
||
579 | * of sessions open) |
||
580 | */ |
||
581 | int snmp_select_info(int *, fd_set *, struct timeval *, |
||
582 | int *); |
||
583 | |||
584 | /* |
||
585 | * snmp_select_info2() is similar to snmp_select_info(), but accepts a |
||
586 | * pointer to a large file descriptor set instead of a pointer to a |
||
587 | * regular file descriptor set. |
||
588 | */ |
||
589 | int snmp_select_info2(int *, netsnmp_large_fd_set *, |
||
590 | struct timeval *, int *); |
||
591 | |||
592 | |||
593 | /* |
||
594 | * void snmp_timeout(); |
||
595 | * |
||
596 | * snmp_timeout should be called whenever the timeout from snmp_select_info |
||
597 | * expires, but it is idempotent, so snmp_timeout can be polled (probably a |
||
598 | * cpu expensive proposition). snmp_timeout checks to see if any of the |
||
599 | * sessions have an outstanding request that has timed out. If it finds one |
||
600 | * (or more), and that pdu has more retries available, a new packet is formed |
||
601 | * from the pdu and is resent. If there are no more retries available, the |
||
602 | * callback for the session is used to alert the user of the timeout. |
||
603 | */ |
||
604 | |||
605 | void snmp_timeout(void); |
||
606 | |||
607 | /* |
||
608 | * snmp_error - return error data |
||
609 | * Inputs : address of errno, address of snmp_errno, address of string |
||
610 | * Caller must free the string returned after use. |
||
611 | */ |
||
612 | void snmp_error(netsnmp_session *, int *, int *, char **); |
||
613 | |||
614 | /* |
||
615 | * single session API. |
||
616 | * |
||
617 | * These functions perform similar actions as snmp_XX functions, |
||
618 | * but operate on a single session only. |
||
619 | * |
||
620 | * Synopsis: |
||
621 | |||
622 | void * sessp; |
||
623 | netsnmp_session session, *ss; |
||
624 | netsnmp_pdu *pdu, *response; |
||
625 | |||
626 | snmp_sess_init(&session); |
||
627 | session.retries = ... |
||
628 | session.remote_port = ... |
||
629 | sessp = snmp_sess_open(&session); |
||
630 | ss = snmp_sess_session(sessp); |
||
631 | if (ss == NULL) |
||
632 | exit(1); |
||
633 | ... |
||
634 | if (ss->community) free(ss->community); |
||
635 | ss->community = strdup(gateway); |
||
636 | ss->community_len = strlen(gateway); |
||
637 | ... |
||
638 | snmp_sess_synch_response(sessp, pdu, &response); |
||
639 | ... |
||
640 | snmp_sess_close(sessp); |
||
641 | |||
642 | * See also: |
||
643 | * snmp_sess_synch_response, in snmp_client.h. |
||
644 | |||
645 | * Notes: |
||
646 | * 1. Invoke snmp_sess_session after snmp_sess_open. |
||
647 | * 2. snmp_sess_session return value is an opaque pointer. |
||
648 | * 3. Do NOT free memory returned by snmp_sess_session. |
||
649 | * 4. Replace snmp_send(ss,pdu) with snmp_sess_send(sessp,pdu) |
||
650 | */ |
||
651 | |||
652 | void *snmp_sess_open(netsnmp_session *); |
||
653 | void *snmp_sess_pointer(netsnmp_session *); |
||
654 | netsnmp_session *snmp_sess_session(void *); |
||
655 | |||
656 | |||
657 | /* |
||
658 | * use return value from snmp_sess_open as void * parameter |
||
659 | */ |
||
660 | |||
661 | int snmp_sess_send(void *, netsnmp_pdu *); |
||
662 | int snmp_sess_async_send(void *, netsnmp_pdu *, |
||
663 | netsnmp_callback, void *); |
||
664 | int snmp_sess_select_info(void *, int *, fd_set *, |
||
665 | struct timeval *, int *); |
||
666 | int snmp_sess_select_info2(void *, int *, |
||
667 | netsnmp_large_fd_set *, |
||
668 | struct timeval *, int *); |
||
669 | /* |
||
670 | * Returns 0 if success, -1 if fail. |
||
671 | */ |
||
672 | int snmp_sess_read(void *, fd_set *); |
||
673 | /* |
||
674 | * Similar to snmp_sess_read(), but accepts a pointer to a large file |
||
675 | * descriptor set instead of a pointer to a file descriptor set. |
||
676 | */ |
||
677 | int snmp_sess_read2(void *, |
||
678 | netsnmp_large_fd_set *); |
||
679 | void snmp_sess_timeout(void *); |
||
680 | int snmp_sess_close(void *); |
||
681 | |||
682 | int snmp_sess_synch_response(void *, netsnmp_pdu *, netsnmp_pdu **); |
||
683 | |||
684 | |||
685 | struct snmp_pdu; |
||
686 | struct snmp_session; |
||
687 | struct variable_list; |
||
688 | |||
689 | struct synch_state { |
||
690 | int waiting; |
||
691 | int status; |
||
692 | /* |
||
693 | * status codes |
||
694 | */ |
||
695 | #define STAT_SUCCESS 0 |
||
696 | #define STAT_ERROR 1 |
||
697 | #define STAT_TIMEOUT 2 |
||
698 | int reqid; |
||
699 | netsnmp_pdu *pdu; |
||
700 | }; |
||
701 | |||
702 | void snmp_replace_var_types(netsnmp_variable_list *vbl, |
||
703 | u_char old_type, |
||
704 | u_char new_type); |
||
705 | void snmp_reset_var_buffers(netsnmp_variable_list *var); |
||
706 | void snmp_reset_var_types(netsnmp_variable_list *vbl, |
||
707 | u_char new_type); |
||
708 | int count_varbinds(netsnmp_variable_list *var_ptr); |
||
709 | int count_varbinds_of_type(netsnmp_variable_list *var_ptr, |
||
710 | u_char type); |
||
711 | netsnmp_variable_list *find_varbind_of_type(netsnmp_variable_list * |
||
712 | var_ptr, u_char type); |
||
713 | netsnmp_variable_list *find_varbind_in_list(netsnmp_variable_list *vblist, |
||
714 | oid *name, size_t len); |
||
715 | |||
716 | netsnmp_pdu *snmp_split_pdu(netsnmp_pdu *, int skipCount, |
||
717 | int copyCount); |
||
718 | |||
719 | unsigned long snmp_varbind_len(netsnmp_pdu *pdu); |
||
720 | int snmp_clone_var(netsnmp_variable_list *, |
||
721 | netsnmp_variable_list *); |
||
722 | const char *snmp_errstring(int); |
||
723 | int snmp_synch_response_cb(netsnmp_session *, |
||
724 | netsnmp_pdu *, netsnmp_pdu **, |
||
725 | snmp_callback); |
||
726 | int snmp_clone_mem(void **, const void *, unsigned); |
||
727 | |||
728 | |||
729 | void netsnmp_query_set_default_session(netsnmp_session *); |
||
730 | netsnmp_session *netsnmp_query_get_default_session( void ); |
||
731 | int netsnmp_query_get( netsnmp_variable_list *, netsnmp_session *); |
||
732 | int netsnmp_query_getnext( netsnmp_variable_list *, netsnmp_session *); |
||
733 | int netsnmp_query_walk( netsnmp_variable_list *, netsnmp_session *); |
||
734 | int netsnmp_query_set( netsnmp_variable_list *, netsnmp_session *); |
||
735 | |||
736 | void snmp_sess_perror(const char *prog_string, |
||
737 | netsnmp_session *ss); |
||
738 | const char *snmp_pdu_type(int type); |
||
739 | |||
740 | #endif |