]>
Commit | Line | Data |
---|---|---|
0e2cd867 | 1 | /* |
2 | * $Id: snmp_api.h,v 1.11 1998/09/23 17:20:01 wessels Exp $ | |
3 | */ | |
4 | ||
54f642bf | 5 | #ifndef _SNMP_API_H_ |
6 | #define _SNMP_API_H_ | |
7 | ||
8 | #include "config.h" | |
9 | #ifdef HAVE_SYS_TIME_H | |
10 | #include <sys/time.h> | |
11 | #endif | |
0e473d70 | 12 | |
8bde32ea | 13 | /*********************************************************** |
14 | Copyright 1989 by Carnegie Mellon University | |
15 | ||
16 | All Rights Reserved | |
17 | ||
18 | Permission to use, copy, modify, and distribute this software and its | |
19 | documentation for any purpose and without fee is hereby granted, | |
20 | provided that the above copyright notice appear in all copies and that | |
21 | both that copyright notice and this permission notice appear in | |
22 | supporting documentation, and that the name of CMU not be | |
23 | used in advertising or publicity pertaining to distribution of the | |
24 | software without specific, written prior permission. | |
25 | ||
26 | CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING | |
27 | ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL | |
28 | CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR | |
29 | ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS, | |
30 | WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION, | |
31 | ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS | |
32 | SOFTWARE. | |
33 | ******************************************************************/ | |
34 | ||
35 | /* | |
36 | * snmp_api.h - API for access to snmp. | |
37 | */ | |
38 | ||
8bde32ea | 39 | |
8bde32ea | 40 | |
41 | /* | |
42 | * Set fields in session and pdu to the following to get a default or unconfigured value. | |
43 | */ | |
44 | #define SNMP_DEFAULT_COMMUNITY_LEN 0 /* to get a default community name */ | |
54f642bf | 45 | #define SNMP_DEFAULT_RETRIES 3 |
46 | #define SNMP_DEFAULT_TIMEOUT 1 | |
8bde32ea | 47 | #define SNMP_DEFAULT_REMPORT 0 |
8bde32ea | 48 | #define SNMP_DEFAULT_PEERNAME NULL |
49 | #define SNMP_DEFAULT_ENTERPRISE_LENGTH 0 | |
50 | #define SNMP_DEFAULT_TIME 0 | |
54f642bf | 51 | #define SNMP_DEFAULT_MAXREPETITIONS 5 |
52 | #define SNMP_DEFAULT_MACREPEATERS 0 | |
8bde32ea | 53 | |
54f642bf | 54 | #ifdef __cplusplus |
55 | extern "C" { | |
56 | #endif | |
8bde32ea | 57 | |
43d4303e | 58 | /* Parse the buffer pointed to by arg3, of length arg4, into pdu arg2. |
59 | * | |
60 | * Returns the community of the incoming PDU, or NULL | |
61 | */ | |
62 | u_char *snmp_parse(struct snmp_session *, struct snmp_pdu *, | |
63 | u_char *, int); | |
8bde32ea | 64 | |
54f642bf | 65 | /* Encode pdu arg2 into buffer arg3. arg4 contains the size of |
66 | * the buffer. | |
67 | */ | |
43d4303e | 68 | int snmp_build(struct snmp_session *, struct snmp_pdu *, |
69 | u_char *, int *); | |
8bde32ea | 70 | |
8bde32ea | 71 | /* |
72 | * struct snmp_session *snmp_open(session) | |
43d4303e | 73 | * struct snmp_session *session; |
8bde32ea | 74 | * |
75 | * Sets up the session with the snmp_session information provided | |
76 | * by the user. Then opens and binds the necessary UDP port. | |
77 | * A handle to the created session is returned (this is different than | |
78 | * the pointer passed to snmp_open()). On any error, NULL is returned | |
79 | * and snmp_errno is set to the appropriate error code. | |
80 | */ | |
7274dc31 | 81 | #if 0 |
43d4303e | 82 | struct snmp_session *snmp_open(struct snmp_session *); |
8bde32ea | 83 | |
84 | /* | |
85 | * int snmp_close(session) | |
86 | * struct snmp_session *session; | |
87 | * | |
88 | * Close the input session. Frees all data allocated for the session, | |
89 | * dequeues any pending requests, and closes any sockets allocated for | |
90 | * the session. Returns 0 on error, 1 otherwise. | |
91 | */ | |
43d4303e | 92 | int snmp_close(struct snmp_session *); |
8bde32ea | 93 | |
94 | ||
95 | /* | |
96 | * int snmp_send(session, pdu) | |
97 | * struct snmp_session *session; | |
43d4303e | 98 | * struct snmp_pdu *pdu; |
8bde32ea | 99 | * |
100 | * Sends the input pdu on the session after calling snmp_build to create | |
101 | * a serialized packet. If necessary, set some of the pdu data from the | |
102 | * session defaults. Add a request corresponding to this pdu to the list | |
103 | * of outstanding requests on this session, then send the pdu. | |
104 | * Returns the request id of the generated packet if applicable, otherwise 1. | |
105 | * On any error, 0 is returned. | |
106 | * The pdu is freed by snmp_send() unless a failure occured. | |
107 | */ | |
43d4303e | 108 | int snmp_send(struct snmp_session *, struct snmp_pdu *); |
8bde32ea | 109 | |
8bde32ea | 110 | /* |
111 | * void snmp_read(fdset) | |
112 | * fd_set *fdset; | |
113 | * | |
114 | * Checks to see if any of the fd's set in the fdset belong to | |
115 | * snmp. Each socket with it's fd set has a packet read from it | |
116 | * and snmp_parse is called on the packet received. The resulting pdu | |
117 | * is passed to the callback routine for that session. If the callback | |
118 | * routine returns successfully, the pdu and it's request are deleted. | |
119 | */ | |
43d4303e | 120 | void snmp_read(fd_set *); |
8bde32ea | 121 | |
122 | ||
8bde32ea | 123 | /* |
124 | * int snmp_select_info(numfds, fdset, timeout, block) | |
125 | * int *numfds; | |
126 | * fd_set *fdset; | |
127 | * struct timeval *timeout; | |
128 | * int *block; | |
129 | * | |
130 | * Returns info about what snmp requires from a select statement. | |
131 | * numfds is the number of fds in the list that are significant. | |
132 | * All file descriptors opened for SNMP are OR'd into the fdset. | |
133 | * If activity occurs on any of these file descriptors, snmp_read | |
134 | * should be called with that file descriptor set. | |
135 | * | |
136 | * The timeout is the latest time that SNMP can wait for a timeout. The | |
137 | * select should be done with the minimum time between timeout and any other | |
138 | * timeouts necessary. This should be checked upon each invocation of select. | |
139 | * If a timeout is received, snmp_timeout should be called to check if the | |
140 | * timeout was for SNMP. (snmp_timeout is idempotent) | |
141 | * | |
142 | * Block is 1 if the select is requested to block indefinitely, rather than time out. | |
143 | * If block is input as 1, the timeout value will be treated as undefined, but it must | |
144 | * be available for setting in snmp_select_info. On return, if block is true, the value | |
145 | * of timeout will be undefined. | |
146 | * | |
147 | * snmp_select_info returns the number of open sockets. (i.e. The number of sessions open) | |
148 | */ | |
43d4303e | 149 | int snmp_select_info(int *, fd_set *, struct timeval *, int *); |
8bde32ea | 150 | |
151 | /* | |
152 | * void snmp_timeout(); | |
153 | * | |
154 | * snmp_timeout should be called whenever the timeout from snmp_select_info expires, | |
155 | * but it is idempotent, so snmp_timeout can be polled (probably a cpu expensive | |
156 | * proposition). snmp_timeout checks to see if any of the sessions have an | |
157 | * outstanding request that has timed out. If it finds one (or more), and that | |
158 | * pdu has more retries available, a new packet is formed from the pdu and is | |
159 | * resent. If there are no more retries available, the callback for the session | |
160 | * is used to alert the user of the timeout. | |
161 | */ | |
43d4303e | 162 | void snmp_timeout(void); |
8bde32ea | 163 | |
164 | ||
8bde32ea | 165 | /* |
166 | * This routine must be supplied by the application: | |
167 | * | |
168 | * int callback(operation, session, reqid, pdu, magic) | |
169 | * int operation; | |
170 | * struct snmp_session *session; The session authenticated under. | |
43d4303e | 171 | * int reqid; The request id of this pdu (0 for TRAP) |
172 | * struct snmp_pdu *pdu; The pdu information. | |
173 | * void *magic A link to the data for this routine. | |
8bde32ea | 174 | * |
175 | * Returns 1 if request was successful, 0 if it should be kept pending. | |
176 | * Any data in the pdu must be copied because it will be freed elsewhere. | |
177 | * Operations are defined below: | |
178 | */ | |
8bde32ea | 179 | |
931ae822 | 180 | |
8bde32ea | 181 | |
8bde32ea | 182 | |
54f642bf | 183 | |
43d4303e | 184 | void snmp_api_stats(void *); |
7274dc31 | 185 | #endif |
54f642bf | 186 | #ifdef __cplusplus |
187 | } | |
54f642bf | 188 | |
43d4303e | 189 | #endif |
190 | #endif /* _SNMP_API_H_ */ |