00001 #ifndef NET_SNMP_SESSION_API_H 00002 #define NET_SNMP_SESSION_API_H 00003 00009 #include <net-snmp/types.h> 00010 00011 #ifdef __cplusplus 00012 extern "C" { 00013 #endif 00014 00015 void snmp_sess_init(netsnmp_session *); 00016 00017 /* 00018 * netsnmp_session *snmp_open(session) 00019 * netsnmp_session *session; 00020 * 00021 * Sets up the session with the snmp_session information provided 00022 * by the user. Then opens and binds the necessary UDP port. 00023 * A handle to the created session is returned (this is different than 00024 * the pointer passed to snmp_open()). On any error, NULL is returned 00025 * and snmp_errno is set to the appropriate error code. 00026 */ 00027 netsnmp_session *snmp_open(netsnmp_session *); 00028 00029 /* 00030 * int snmp_close(session) 00031 * netsnmp_session *session; 00032 * 00033 * Close the input session. Frees all data allocated for the session, 00034 * dequeues any pending requests, and closes any sockets allocated for 00035 * the session. Returns 0 on error, 1 otherwise. 00036 * 00037 * snmp_close_sessions() does the same thing for all open sessions 00038 */ 00039 int snmp_close(netsnmp_session *); 00040 int snmp_close_sessions(void); 00041 00042 00043 /* 00044 * int snmp_send(session, pdu) 00045 * netsnmp_session *session; 00046 * netsnmp_pdu *pdu; 00047 * 00048 * Sends the input pdu on the session after calling snmp_build to create 00049 * a serialized packet. If necessary, set some of the pdu data from the 00050 * session defaults. Add a request corresponding to this pdu to the list 00051 * of outstanding requests on this session, then send the pdu. 00052 * Returns the request id of the generated packet if applicable, otherwise 1. 00053 * On any error, 0 is returned. 00054 * The pdu is freed by snmp_send() unless a failure occured. 00055 */ 00056 int snmp_send(netsnmp_session *, netsnmp_pdu *); 00057 00058 /* 00059 * int snmp_async_send(session, pdu, callback, cb_data) 00060 * netsnmp_session *session; 00061 * netsnmp_pdu *pdu; 00062 * netsnmp_callback callback; 00063 * void *cb_data; 00064 * 00065 * Sends the input pdu on the session after calling snmp_build to create 00066 * a serialized packet. If necessary, set some of the pdu data from the 00067 * session defaults. Add a request corresponding to this pdu to the list 00068 * of outstanding requests on this session and store callback and data, 00069 * then send the pdu. 00070 * Returns the request id of the generated packet if applicable, otherwise 1. 00071 * On any error, 0 is returned. 00072 * The pdu is freed by snmp_send() unless a failure occured. 00073 */ 00074 int snmp_async_send(netsnmp_session *, netsnmp_pdu *, 00075 netsnmp_callback, void *); 00076 00077 00078 /* 00079 * void snmp_read(fdset) 00080 * fd_set *fdset; 00081 * 00082 * Checks to see if any of the fd's set in the fdset belong to 00083 * snmp. Each socket with it's fd set has a packet read from it 00084 * and snmp_parse is called on the packet received. The resulting pdu 00085 * is passed to the callback routine for that session. If the callback 00086 * routine returns successfully, the pdu and it's request are deleted. 00087 */ 00088 void snmp_read(fd_set *); 00089 00090 /* 00091 * snmp_read2() is similar to snmp_read(), but accepts a pointer to a 00092 * large file descriptor set instead of a pointer to a regular file 00093 * descriptor set. 00094 */ 00095 void snmp_read2(netsnmp_large_fd_set *); 00096 00097 00098 int snmp_synch_response(netsnmp_session *, netsnmp_pdu *, 00099 netsnmp_pdu **); 00100 00101 /* 00102 * int snmp_select_info(numfds, fdset, timeout, block) 00103 * int *numfds; 00104 * fd_set *fdset; 00105 * struct timeval *timeout; 00106 * int *block; 00107 * 00108 * Returns info about what snmp requires from a select statement. 00109 * numfds is the number of fds in the list that are significant. 00110 * All file descriptors opened for SNMP are OR'd into the fdset. 00111 * If activity occurs on any of these file descriptors, snmp_read 00112 * should be called with that file descriptor set. 00113 * 00114 * The timeout is the latest time that SNMP can wait for a timeout. The 00115 * select should be done with the minimum time between timeout and any other 00116 * timeouts necessary. This should be checked upon each invocation of select. 00117 * If a timeout is received, snmp_timeout should be called to check if the 00118 * timeout was for SNMP. (snmp_timeout is idempotent) 00119 * 00120 * Block is 1 if the select is requested to block indefinitely, rather than 00121 * time out. If block is input as 1, the timeout value will be treated as 00122 * undefined, but it must be available for setting in snmp_select_info. On 00123 * return, if block is true, the value of timeout will be undefined. 00124 * 00125 * snmp_select_info returns the number of open sockets. (i.e. The number 00126 * of sessions open) 00127 */ 00128 int snmp_select_info(int *, fd_set *, struct timeval *, 00129 int *); 00130 00131 /* 00132 * snmp_select_info2() is similar to snmp_select_info(), but accepts a 00133 * pointer to a large file descriptor set instead of a pointer to a 00134 * regular file descriptor set. 00135 */ 00136 int snmp_select_info2(int *, netsnmp_large_fd_set *, 00137 struct timeval *, int *); 00138 00139 00140 /* 00141 * void snmp_timeout(); 00142 * 00143 * snmp_timeout should be called whenever the timeout from snmp_select_info 00144 * expires, but it is idempotent, so snmp_timeout can be polled (probably a 00145 * cpu expensive proposition). snmp_timeout checks to see if any of the 00146 * sessions have an outstanding request that has timed out. If it finds one 00147 * (or more), and that pdu has more retries available, a new packet is formed 00148 * from the pdu and is resent. If there are no more retries available, the 00149 * callback for the session is used to alert the user of the timeout. 00150 */ 00151 00152 void snmp_timeout(void); 00153 00154 /* 00155 * snmp_error - return error data 00156 * Inputs : address of errno, address of snmp_errno, address of string 00157 * Caller must free the string returned after use. 00158 */ 00159 void snmp_error(netsnmp_session *, int *, int *, char **); 00160 00161 /* 00162 * single session API. 00163 * 00164 * These functions perform similar actions as snmp_XX functions, 00165 * but operate on a single session only. 00166 * 00167 * Synopsis: 00168 00169 void * sessp; 00170 netsnmp_session session, *ss; 00171 netsnmp_pdu *pdu, *response; 00172 00173 snmp_sess_init(&session); 00174 session.retries = ... 00175 session.remote_port = ... 00176 sessp = snmp_sess_open(&session); 00177 ss = snmp_sess_session(sessp); 00178 if (ss == NULL) 00179 exit(1); 00180 ... 00181 if (ss->community) free(ss->community); 00182 ss->community = strdup(gateway); 00183 ss->community_len = strlen(gateway); 00184 ... 00185 snmp_sess_synch_response(sessp, pdu, &response); 00186 ... 00187 snmp_sess_close(sessp); 00188 00189 * See also: 00190 * snmp_sess_synch_response, in snmp_client.h. 00191 00192 * Notes: 00193 * 1. Invoke snmp_sess_session after snmp_sess_open. 00194 * 2. snmp_sess_session return value is an opaque pointer. 00195 * 3. Do NOT free memory returned by snmp_sess_session. 00196 * 4. Replace snmp_send(ss,pdu) with snmp_sess_send(sessp,pdu) 00197 */ 00198 00199 void *snmp_sess_open(netsnmp_session *); 00200 void *snmp_sess_pointer(netsnmp_session *); 00201 netsnmp_session *snmp_sess_session(void *); 00202 00203 00204 /* 00205 * use return value from snmp_sess_open as void * parameter 00206 */ 00207 00208 int snmp_sess_send(void *, netsnmp_pdu *); 00209 int snmp_sess_async_send(void *, netsnmp_pdu *, 00210 netsnmp_callback, void *); 00211 int snmp_sess_select_info(void *, int *, fd_set *, 00212 struct timeval *, int *); 00213 int snmp_sess_select_info2(void *, int *, 00214 netsnmp_large_fd_set *, 00215 struct timeval *, int *); 00216 /* 00217 * Returns 0 if success, -1 if fail. 00218 */ 00219 int snmp_sess_read(void *, fd_set *); 00220 /* 00221 * Similar to snmp_sess_read(), but accepts a pointer to a large file 00222 * descriptor set instead of a pointer to a file descriptor set. 00223 */ 00224 int snmp_sess_read2(void *, 00225 netsnmp_large_fd_set *); 00226 void snmp_sess_timeout(void *); 00227 int snmp_sess_close(void *); 00228 00229 int snmp_sess_synch_response(void *, netsnmp_pdu *, 00230 netsnmp_pdu **); 00231 00232 #ifdef __cplusplus 00233 } 00234 #endif 00235 00236 00237 /* 00238 * For the initial release, this will just refer to the 00239 * relevant UCD header files. 00240 * In due course, the routines relevant to this area of the 00241 * API will be identified, and listed here directly. 00242 * 00243 * But for the time being, this header file is a placeholder, 00244 * to allow application writers to adopt the new header file names. 00245 */ 00246 00247 #include <net-snmp/library/snmp_api.h> 00248 #include <net-snmp/library/snmp_client.h> 00249 #include <net-snmp/library/asn1.h> 00250 #include <net-snmp/library/callback.h> 00251 00252 #include <net-snmp/library/snmp_transport.h> 00253 #include <net-snmp/library/snmp_service.h> 00254 #include <net-snmp/library/snmpCallbackDomain.h> 00255 #ifdef NETSNMP_TRANSPORT_UNIX_DOMAIN 00256 #include <net-snmp/library/snmpUnixDomain.h> 00257 #endif 00258 #ifdef NETSNMP_TRANSPORT_UDP_DOMAIN 00259 #include <net-snmp/library/snmpUDPDomain.h> 00260 #endif 00261 #ifdef NETSNMP_TRANSPORT_TCP_DOMAIN 00262 #include <net-snmp/library/snmpTCPDomain.h> 00263 #endif 00264 #ifdef NETSNMP_TRANSPORT_UDPIPV6_DOMAIN 00265 #include <net-snmp/library/snmpUDPIPv6Domain.h> 00266 #endif 00267 #ifdef NETSNMP_TRANSPORT_TCPIPV6_DOMAIN 00268 #include <net-snmp/library/snmpTCPIPv6Domain.h> 00269 #endif 00270 #ifdef NETSNMP_TRANSPORT_IPX_DOMAIN 00271 #include <net-snmp/library/snmpIPXDomain.h> 00272 #endif 00273 #ifdef NETSNMP_TRANSPORT_AAL5PVC_DOMAIN 00274 #include <net-snmp/library/snmpAAL5PVCDomain.h> 00275 #endif 00276 00277 #include <net-snmp/library/ucd_compat.h> 00278 00279 #endif /* NET_SNMP_SESSION_API_H */
Last modified: Wednesday, 01-Aug-2018 04:41:28 UTC
For questions regarding web content and site functionality, please write to the net-snmp-users mail list.