net-snmp 0.1.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/.document ADDED
@@ -0,0 +1,5 @@
1
+ README.rdoc
2
+ lib/**/*.rb
3
+ bin/*
4
+ features/**/*.feature
5
+ LICENSE
data/.gitignore ADDED
@@ -0,0 +1,4 @@
1
+ *.gem
2
+ .bundle
3
+ Gemfile.lock
4
+ pkg/*
data/.rspec ADDED
@@ -0,0 +1 @@
1
+ --color
data/Gemfile ADDED
@@ -0,0 +1,8 @@
1
+ source "http://rubygems.org"
2
+
3
+ # Specify your gem's dependencies in net-snmp.gemspec
4
+ gemspec
5
+
6
+ #group :development, :test do
7
+ # gem 'eventmachine', '1.0.0.beta.3'
8
+ #end
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2009 mixtli
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,146 @@
1
+ = net-snmp
2
+
3
+ == DESCRIPTION
4
+
5
+ net-snmp is a Ruby object oriented wrapper around the C netsnmp[http://www.net-snmp.org] libraries.
6
+ It provides classes for sessions, pdus, varbinds, and more.
7
+
8
+ == FEATURES
9
+
10
+ * Supports SNMP versions 1, 2c, and 3
11
+ * Supports both synchronous and asynchronous calls
12
+ * Integrates well with eventmachine, or can be used standalone.
13
+ * In Ruby 1.9, uses fibers behind the scenes to emulate synchronous calls asynchronously
14
+
15
+
16
+ == USAGE
17
+
18
+ You must have the net-snmp libraries installed and available on the system. Check to make sure
19
+ they are available in your library path. If necessary, add them to your shell like so:
20
+
21
+ export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:/opt/local/lib/net-snmp
22
+
23
+
24
+ You can use the library in two styles: synchronously or asynchronously. If you use the synchronous style,
25
+ calls will block until a result is returned or the request times out. If you use the asynchronous style, you
26
+ must provide a block to the client methods, which will be called when the data is ready.
27
+
28
+ In order for your callbacks to fire, you must call Net::SNMP.dispatcher. You may pass a timeout argument to
29
+ the dispatcher. If you pass false, the call will block forever until data is ready. If you pass an integer, it will block for
30
+ <timeout> seconds. If you pass nil (the default), it will do a poll and return immediately. In that case, you
31
+ will have to arrange for the dispatcher to run periodically. This can be done in your main event loop or in a
32
+ seperate thread.
33
+
34
+ If you like eventmachine, it's very easy to set up the dispatcher to run periodically in the adaptor. If you're
35
+ using eventmachine with ruby 1.9, the library uses fibers behind the scenes to turn your synchronous calls into asynchronous
36
+ calls, while allowing you to use a synchronous calling style. Examples of all these scenarios are below.
37
+
38
+ == FFI
39
+ This library uses ruby-ffi to access the net-snmp libraries. If you want to use the C library directly, the wrapper
40
+ functions are defined in Net::SNMP::Wrapper. You can call them like so:
41
+ Net::SNMP::Wrapper.snmp_perror("some_error")
42
+
43
+
44
+
45
+ == EXAMPLES
46
+
47
+
48
+ A simple synchronous SNMP-GET
49
+
50
+ session = Net::SNMP::Session.open(:peername => "test.net-snmp.org", :community => "demopublic" )
51
+ result = session.get("sysDescr.0")
52
+ puts result.varbinds.first.value
53
+
54
+ An asynchronous SNMP-GET
55
+
56
+ Net::SNMP::Session.open(:peername => 'test.net-snmp.org', :community => 'demopublic') do |session|
57
+ session.get(["sysDescr.0", "sysContact.0"]) do |result|
58
+ puts result.varbinds[0].value
59
+ end
60
+ end
61
+ Net::SNMP.dispatcher(false) #Setting timeout to false causes dispatcher to block until data is ready
62
+
63
+
64
+ Running the dispatcher in a seperate thread
65
+
66
+ dispatcher_thread = Thread.new do
67
+ while Net::SNMP.dispatcher == 0
68
+ sleep 1
69
+ end
70
+ end
71
+
72
+ Net::SNMP::Session.open(:peername => 'test.net-snmp.org', :community => 'demopublic') do |s|
73
+ s.get(["sysDescr.0", "sysContact.0"]) do |result|
74
+ puts result.varbinds[0].value
75
+ end
76
+ end
77
+ dispatcher_thread.join
78
+
79
+ Running the dispatcher from eventmachine
80
+ EM.run do
81
+ tickloop = EM.tick_loop do
82
+ Net::SNMP.dispatcher
83
+ end
84
+
85
+ Net::SNMP::Session.open(:peername => 'test.net-snmp.org', :community => 'demopublic') do |session|
86
+ session.get("sysDescr.0") do |result|
87
+ puts result.varbinds[0].value
88
+ end
89
+ end
90
+ end
91
+
92
+ Using synchronous style with eventmachine in ruby 1.9
93
+ EM.run do
94
+ Fiber.new {
95
+ EM.tick_loop do
96
+ Net::SNMP.dispatcher
97
+ end
98
+ session = Net::SNMP::Session.open(:peername => 'test.net-snmp.org', :community => 'demopublic')
99
+ result = session.get("sysDescr.0")
100
+ puts result.varbinds[0].value
101
+
102
+ }.resume
103
+ EM.stop
104
+ end
105
+
106
+
107
+ In the last example, note that you must wrap your code in Fiber.new {}.resume. You could instead use the
108
+ em-synchrony[https://github.com/igrigorik/em-synchrony] gem, and wrap your loop with EM.synchrony{}.
109
+ Note that even though it appears you are making a blocking call, waiting for a return value, actually in the
110
+ background, control is passed back to the reactor fiber to process other requests. get() will return once the
111
+ data is available. This is all seemless to you, the developer. Behold the power of fibers!
112
+
113
+
114
+ == CAVEATS/DISCLAIMER
115
+
116
+ THIS GEM COULD CRASH YOUR SYSTEM AND EAT YOUR CHILDREN!
117
+
118
+ You have been warned.
119
+
120
+ This is very much alpha software. For more information on usage, take a look at the specs. Currently it's
121
+ only tested against net-snmp 5.5. The net-snmp api seems pretty stable, but if anything changes, it could
122
+ break this gem. Please let me know if you find bugs or missing features. Or better yet, send a pull request.
123
+
124
+
125
+ == TODO
126
+
127
+ * Better error handling.
128
+ * SNMPv3 support needs testing for various security models
129
+ * Better documentation
130
+ * More tests
131
+ * Cleanup cruft and unused code
132
+
133
+
134
+ == Note on Patches/Pull Requests
135
+
136
+ * Fork the project.
137
+ * Make your feature addition or bug fix.
138
+ * Add tests for it. This is important so I don't break it in a
139
+ future version unintentionally.
140
+ * Commit, do not mess with rakefile, version, or history.
141
+ (if you want to have your own version, that is fine but bump version in a commit by itself I can ignore when I pull)
142
+ * Send me a pull request. Bonus points for topic branches.
143
+
144
+ == Copyright
145
+
146
+ Copyright (c) 2010 mixtli. See LICENSE for details.
data/Rakefile ADDED
@@ -0,0 +1,2 @@
1
+ require 'bundler'
2
+ Bundler::GemHelper.install_tasks
data/VERSION ADDED
@@ -0,0 +1 @@
1
+ 0.0.0
data/bin/snmpget.rb ADDED
@@ -0,0 +1,30 @@
1
+ #!/usr/bin/env ruby
2
+ require 'optparse'
3
+ #require 'ruby-debug19'
4
+ $LOAD_PATH.unshift(File.dirname(__FILE__) + "/../lib")
5
+
6
+ require 'net-snmp'
7
+ options = {}
8
+
9
+ optparse = OptionParser.new do|opts|
10
+ opts.banner = "Usage: snmpget.rb -v [1,2,3] -c <community> <host> <oid>"
11
+ opts.on( '-v', '--version VERSION', 'SNMP version' ) do |version|
12
+ options[:version] = version
13
+ end
14
+
15
+ opts.on('-c', '--community COMMUNITY', 'Community') do |community|
16
+ options[:community] = community
17
+ end
18
+ end
19
+ optparse.parse!
20
+ host = ARGV[0]
21
+ oid = ARGV[1]
22
+
23
+ sess = Net::SNMP::Session.new(:peername => host, :community => options[:community], :version => options[:version])
24
+
25
+ pdu = sess.get(oid)
26
+
27
+ pdu.varbinds.each do |v|
28
+ puts v.name
29
+ puts v.value
30
+ end
data/c/Makefile ADDED
@@ -0,0 +1,3 @@
1
+ all:
2
+ gcc -o test -L/opt/local/lib -I/opt/local/include -lnetsnmp test.c
3
+
data/c/test ADDED
Binary file
data/c/test.c ADDED
@@ -0,0 +1,137 @@
1
+ #include <stdio.h>
2
+ #include "string.h"
3
+ #include <net-snmp/net-snmp-config.h>
4
+ #include <net-snmp/types.h>
5
+ #include <net-snmp/library/parse.h>
6
+
7
+ struct oid {
8
+ char *Name;
9
+ oid Oid[MAX_OID_LEN];
10
+ size_t OidLen;
11
+ } oids[] = {
12
+ { "system.sysDescr.0" },
13
+ { "ifDescr.1" },
14
+ { "ifIndex.1" },
15
+ { NULL }
16
+ };
17
+
18
+ int main() {
19
+ struct oid *op = oids;
20
+ init_snmp("snmpdemoapp");
21
+ init_mib();
22
+ test_mib();
23
+ while (op->Name) {
24
+ op->OidLen = sizeof(op->Oid)/sizeof(op->Oid[0]);
25
+
26
+ get_node(op->Name, op->Oid, &op->OidLen);
27
+
28
+ op++;
29
+ }
30
+
31
+ test_synch();
32
+
33
+
34
+ }
35
+
36
+ int test_mib() {
37
+ struct tree *mytree;
38
+ size_t oidlen;
39
+ int i = 0;
40
+ oid myoid[MAX_OID_LEN];
41
+ snmp_set_save_descriptions(1);
42
+
43
+ printf("sizeof(netsnmp_vardata) = %lu\n", sizeof(netsnmp_vardata));
44
+ printf("sizeof(netsnmp_variable_list) = %lu\n", sizeof(netsnmp_variable_list));
45
+ printf("sizeof(netsnmp_session) = %lu\n", sizeof(netsnmp_session));
46
+ printf("sizeof(netsnmp_pdu) = %lu\n", sizeof(netsnmp_pdu));
47
+ oidlen = 100;
48
+ get_node("interfaces.ifNumber.2", myoid, &oidlen);
49
+ printf("oidlen = %lu\n", oidlen);
50
+ for(i=0;i < oidlen; i++) {
51
+ printf("%lu\n", myoid[i]);
52
+ }
53
+ mytree = get_tree(myoid, oidlen, get_tree_head());
54
+ printf("label = %s\n", mytree->label);
55
+ printf("description = %s\n", mytree->description);
56
+ print_description(myoid, oidlen, 200);
57
+
58
+ print_mib_tree(stdout, mytree, 1000);
59
+ }
60
+
61
+
62
+ int test_synch() {
63
+ struct snmp_session ss, *sp;
64
+ struct oid *op;
65
+
66
+ snmp_sess_init(&ss); /* initialize session */
67
+ ss.version = SNMP_VERSION_2c;
68
+ ss.peername = "127.0.0.1";
69
+ ss.community = "public";
70
+ ss.community_len = strlen(ss.community);
71
+ printf("here\n");
72
+ snmp_synch_setup(&ss);
73
+ if (!(sp = snmp_open(&ss))) {
74
+ snmp_perror("snmp_open");
75
+ return;
76
+ }
77
+ printf("and here\n");
78
+ for (op = oids; op->Name; op++) {
79
+ struct snmp_pdu *req, *resp;
80
+ int status;
81
+ req = snmp_pdu_create(SNMP_MSG_GET);
82
+ snmp_add_null_var(req, op->Oid, op->OidLen);
83
+ status = snmp_synch_response(sp, req, &resp);
84
+ printf("got status %d\n", status);
85
+ printf("oid %s\n", op->Name);
86
+ if (!print_result(status, sp, resp)) break;
87
+ snmp_free_pdu(resp);
88
+ }
89
+ snmp_close(sp);
90
+ }
91
+
92
+
93
+
94
+ /*
95
+ * simple printing of returned data
96
+ */
97
+ int print_result (int status, struct snmp_session *sp, struct snmp_pdu *pdu)
98
+ {
99
+ char buf[1024];
100
+ struct variable_list *vp;
101
+ int ix;
102
+ struct timeval now;
103
+ struct timezone tz;
104
+ struct tm *tm;
105
+
106
+ gettimeofday(&now, &tz);
107
+ tm = localtime(&now.tv_sec);
108
+ fprintf(stdout, "%.2d:%.2d:%.2d.%.6d ", tm->tm_hour, tm->tm_min, tm->tm_sec,
109
+ now.tv_usec);
110
+ switch (status) {
111
+ case STAT_SUCCESS:
112
+ vp = pdu->variables;
113
+ if (pdu->errstat == SNMP_ERR_NOERROR) {
114
+ while (vp) {
115
+ snprint_variable(buf, sizeof(buf), vp->name, vp->name_length, vp);
116
+ fprintf(stdout, "%s: %s\n", sp->peername, buf);
117
+ vp = vp->next_variable;
118
+ }
119
+ }
120
+ else {
121
+ for (ix = 1; vp && ix != pdu->errindex; vp = vp->next_variable, ix++)
122
+ ;
123
+ if (vp) snprint_objid(buf, sizeof(buf), vp->name, vp->name_length);
124
+ else strcpy(buf, "(none)");
125
+ fprintf(stdout, "%s: %s: %s\n",
126
+ sp->peername, buf, snmp_errstring(pdu->errstat));
127
+ }
128
+ return 1;
129
+ case STAT_TIMEOUT:
130
+ fprintf(stdout, "%s: Timeout\n", sp->peername);
131
+ return 0;
132
+ case STAT_ERROR:
133
+ snmp_perror(sp->peername);
134
+ return 0;
135
+ }
136
+ return 0;
137
+ }
@@ -0,0 +1,1086 @@
1
+ /* Portions of this file are subject to the following copyright(s). See
2
+ * the Net-SNMP's COPYING file for more details and other copyrights
3
+ * that may apply:
4
+ */
5
+ /*
6
+ * Portions of this file are copyrighted by:
7
+ * Copyright � 2003 Sun Microsystems, Inc. All rights reserved.
8
+ * Use is subject to license terms specified in the COPYING file
9
+ * distributed with the Net-SNMP package.
10
+ */
11
+ #ifndef SNMP_API_H
12
+ #define SNMP_API_H
13
+
14
+ /*
15
+ * @file snmp_api.h - API for access to snmp.
16
+ *
17
+ * @addtogroup library
18
+ *
19
+ * Caution: when using this library in a multi-threaded application,
20
+ * the values of global variables "snmp_errno" and "snmp_detail"
21
+ * cannot be reliably determined. Suggest using snmp_error()
22
+ * to obtain the library error codes.
23
+ *
24
+ * @{
25
+ */
26
+
27
+ #ifndef DONT_SHARE_ERROR_WITH_OTHER_THREADS
28
+ #define SET_SNMP_ERROR(x) snmp_errno=(x)
29
+ #else
30
+ #define SET_SNMP_ERROR(x)
31
+ #endif
32
+
33
+
34
+ #ifdef __cplusplus
35
+ extern "C" {
36
+ #endif
37
+
38
+ /***********************************************************
39
+ Copyright 1989 by Carnegie Mellon University
40
+
41
+ All Rights Reserved
42
+
43
+ Permission to use, copy, modify, and distribute this software and its
44
+ documentation for any purpose and without fee is hereby granted,
45
+ provided that the above copyright notice appear in all copies and that
46
+ both that copyright notice and this permission notice appear in
47
+ supporting documentation, and that the name of CMU not be
48
+ used in advertising or publicity pertaining to distribution of the
49
+ software without specific, written prior permission.
50
+
51
+ CMU DISCLAIMS ALL WARRANTIES WITH REGARD TO THIS SOFTWARE, INCLUDING
52
+ ALL IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS, IN NO EVENT SHALL
53
+ CMU BE LIABLE FOR ANY SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES OR
54
+ ANY DAMAGES WHATSOEVER RESULTING FROM LOSS OF USE, DATA OR PROFITS,
55
+ WHETHER IN AN ACTION OF CONTRACT, NEGLIGENCE OR OTHER TORTIOUS ACTION,
56
+ ARISING OUT OF OR IN CONNECTION WITH THE USE OR PERFORMANCE OF THIS
57
+ SOFTWARE.
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
+ typedef struct variable_list netsnmp_variable_list;
64
+ struct timeval;
65
+ struct netsnmp_transport_s;
66
+
67
+ #define USM_AUTH_KU_LEN 32
68
+ #define USM_PRIV_KU_LEN 32
69
+
70
+ /** @typedef struct snmp_pdu to netsnmp_pdu
71
+ * Typedefs the snmp_pdu struct into netsnmp_pdu */
72
+ /** @struct snmp_pdu
73
+ * The snmp protocol data unit.
74
+ */
75
+ typedef struct snmp_pdu {
76
+
77
+ /*
78
+ * Protocol-version independent fields
79
+ */
80
+ /** snmp version */
81
+ long version;
82
+ /** Type of this PDU */
83
+ int command;
84
+ /** Request id - note: not incremented on retries */
85
+ long reqid;
86
+ /** Message id for V3 messages note: incremented for each retry */
87
+ long msgid;
88
+ /** Unique ID for incoming transactions */
89
+ long transid;
90
+ /** Session id for AgentX messages */
91
+ long sessid;
92
+ /** Error status (non_repeaters in GetBulk) */
93
+ long errstat;
94
+ /** Error index (max_repetitions in GetBulk) */
95
+ long errindex;
96
+ /** Uptime */
97
+ u_long time;
98
+ u_long flags;
99
+
100
+ int securityModel;
101
+ /** noAuthNoPriv, authNoPriv, authPriv */
102
+ int securityLevel;
103
+ int msgParseModel;
104
+
105
+ /**
106
+ * Transport-specific opaque data. This replaces the IP-centric address
107
+ * field.
108
+ */
109
+
110
+ void *transport_data;
111
+ int transport_data_length;
112
+
113
+ /**
114
+ * The actual transport domain. This SHOULD NOT BE FREE()D.
115
+ */
116
+
117
+ const oid *tDomain;
118
+ size_t tDomainLen;
119
+
120
+ netsnmp_variable_list *variables;
121
+
122
+
123
+ /*
124
+ * SNMPv1 & SNMPv2c fields
125
+ */
126
+ /** community for outgoing requests. */
127
+ u_char *community;
128
+ /** length of community name. */
129
+ size_t community_len;
130
+
131
+ /*
132
+ * Trap information
133
+ */
134
+ /** System OID */
135
+ oid *enterprise;
136
+ size_t enterprise_length;
137
+ /** trap type */
138
+ long trap_type;
139
+ /** specific type */
140
+ long specific_type;
141
+ /** This is ONLY used for v1 TRAPs */
142
+ unsigned char agent_addr[4];
143
+
144
+ /*
145
+ * SNMPv3 fields
146
+ */
147
+ /** context snmpEngineID */
148
+ u_char *contextEngineID;
149
+ /** Length of contextEngineID */
150
+ size_t contextEngineIDLen;
151
+ /** authoritative contextName */
152
+ char *contextName;
153
+ /** Length of contextName */
154
+ size_t contextNameLen;
155
+ /** authoritative snmpEngineID for security */
156
+ u_char *securityEngineID;
157
+ /** Length of securityEngineID */
158
+ size_t securityEngineIDLen;
159
+ /** on behalf of this principal */
160
+ char *securityName;
161
+ /** Length of securityName. */
162
+ size_t securityNameLen;
163
+
164
+ /*
165
+ * AgentX fields
166
+ * (also uses SNMPv1 community field)
167
+ */
168
+ int priority;
169
+ int range_subid;
170
+
171
+ void *securityStateRef;
172
+ } netsnmp_pdu;
173
+
174
+ struct snmp_session;
175
+
176
+ /** @typedef struct snmp_session netsnmp_session
177
+ * Typedefs the snmp_session struct intonetsnmp_session */
178
+ typedef struct snmp_session netsnmp_session;
179
+
180
+ typedef int (*snmp_callback) (int, netsnmp_session *, int,
181
+ netsnmp_pdu *, void *);
182
+ typedef int (*netsnmp_callback) (int, netsnmp_session *, int,
183
+ netsnmp_pdu *, void *);
184
+ /** @struct snmp_session
185
+ * The snmp session structure.
186
+ */
187
+ struct snmp_session {
188
+ /*
189
+ * Protocol-version independent fields
190
+ */
191
+ /** snmp version */
192
+ long version;
193
+ /** Number of retries before timeout. */
194
+ int retries;
195
+ /** Number of uS until first timeout, then exponential backoff */
196
+ long timeout;
197
+ u_long flags;
198
+ struct snmp_session *subsession;
199
+ struct snmp_session *next;
200
+
201
+ /** name or address of default peer (may include transport specifier and/or port number) */
202
+ char *peername;
203
+ /** UDP port number of peer. (NO LONGER USED - USE peername INSTEAD) */
204
+ u_short remote_port;
205
+ /** My Domain name or dotted IP address, 0 for default */
206
+ char *localname;
207
+ /** My UDP port number, 0 for default, picked randomly */
208
+ u_short local_port;
209
+ /**
210
+ * Authentication function or NULL if null authentication is used
211
+ */
212
+ u_char *(*authenticator) (u_char *, size_t *, u_char *, size_t);
213
+ /** Function to interpret incoming data */
214
+ netsnmp_callback callback;
215
+ /**
216
+ * Pointer to data that the callback function may consider important
217
+ */
218
+ void *callback_magic;
219
+ /** copy of system errno */
220
+ int s_errno;
221
+ /** copy of library errno */
222
+ int s_snmp_errno;
223
+ /** Session id - AgentX only */
224
+ long sessid;
225
+
226
+ /*
227
+ * SNMPv1 & SNMPv2c fields
228
+ */
229
+ /** community for outgoing requests. */
230
+ u_char *community;
231
+ /** Length of community name. */
232
+ size_t community_len;
233
+ /** Largest message to try to receive. */
234
+ size_t rcvMsgMaxSize;
235
+ /** Largest message to try to send. */
236
+ size_t sndMsgMaxSize;
237
+
238
+ /*
239
+ * SNMPv3 fields
240
+ */
241
+ /** are we the authoritative engine? */
242
+ u_char isAuthoritative;
243
+ /** authoritative snmpEngineID */
244
+ u_char *contextEngineID;
245
+ /** Length of contextEngineID */
246
+ size_t contextEngineIDLen;
247
+ /** initial engineBoots for remote engine */
248
+ u_int engineBoots;
249
+ /** initial engineTime for remote engine */
250
+ u_int engineTime;
251
+ /** authoritative contextName */
252
+ char *contextName;
253
+ /** Length of contextName */
254
+ size_t contextNameLen;
255
+ /** authoritative snmpEngineID */
256
+ u_char *securityEngineID;
257
+ /** Length of contextEngineID */
258
+ size_t securityEngineIDLen;
259
+ /** on behalf of this principal */
260
+ char *securityName;
261
+ /** Length of securityName. */
262
+ size_t securityNameLen;
263
+
264
+ /** auth protocol oid */
265
+ oid *securityAuthProto;
266
+ /** Length of auth protocol oid */
267
+ size_t securityAuthProtoLen;
268
+ /** Ku for auth protocol XXX */
269
+ u_char securityAuthKey[USM_AUTH_KU_LEN];
270
+ /** Length of Ku for auth protocol */
271
+ size_t securityAuthKeyLen;
272
+ /** Kul for auth protocol */
273
+ u_char *securityAuthLocalKey;
274
+ /** Length of Kul for auth protocol XXX */
275
+ size_t securityAuthLocalKeyLen;
276
+
277
+ /** priv protocol oid */
278
+ oid *securityPrivProto;
279
+ /** Length of priv protocol oid */
280
+ size_t securityPrivProtoLen;
281
+ /** Ku for privacy protocol XXX */
282
+ u_char securityPrivKey[USM_PRIV_KU_LEN];
283
+ /** Length of Ku for priv protocol */
284
+ size_t securityPrivKeyLen;
285
+ /** Kul for priv protocol */
286
+ u_char *securityPrivLocalKey;
287
+ /** Length of Kul for priv protocol XXX */
288
+ size_t securityPrivLocalKeyLen;
289
+
290
+ /** snmp security model, v1, v2c, usm */
291
+ int securityModel;
292
+ /** noAuthNoPriv, authNoPriv, authPriv */
293
+ int securityLevel;
294
+ /** target param name */
295
+ char *paramName;
296
+
297
+ /**
298
+ * security module specific
299
+ */
300
+ void *securityInfo;
301
+
302
+ /**
303
+ * use as you want data
304
+ *
305
+ * used by 'SNMP_FLAGS_RESP_CALLBACK' handling in the agent
306
+ * XXX: or should we add a new field into this structure?
307
+ */
308
+ void *myvoid;
309
+ };
310
+
311
+ /*
312
+ * A list of all the outstanding requests for a particular session.
313
+ */
314
+ #ifdef SNMP_NEED_REQUEST_LIST
315
+ typedef struct request_list {
316
+ struct request_list *next_request;
317
+ long request_id; /* request id */
318
+ long message_id; /* message id */
319
+ netsnmp_callback callback; /* user callback per request (NULL if unused) */
320
+ void *cb_data; /* user callback data per request (NULL if unused) */
321
+ int retries; /* Number of retries */
322
+ u_long timeout; /* length to wait for timeout */
323
+ struct timeval time; /* Time this request was made */
324
+ struct timeval expire; /* time this request is due to expire */
325
+ struct snmp_session *session;
326
+ netsnmp_pdu *pdu; /* The pdu for this request
327
+ * (saved so it can be retransmitted */
328
+ } netsnmp_request_list;
329
+ #endif /* SNMP_NEED_REQUEST_LIST */
330
+
331
+ /*
332
+ * Set fields in session and pdu to the following to get a default or unconfigured value.
333
+ */
334
+ #define SNMP_DEFAULT_COMMUNITY_LEN 0 /* to get a default community name */
335
+ #define SNMP_DEFAULT_RETRIES -1
336
+ #define SNMP_DEFAULT_TIMEOUT -1
337
+ #define SNMP_DEFAULT_REMPORT 0
338
+ #define SNMP_DEFAULT_REQID -1
339
+ #define SNMP_DEFAULT_MSGID -1
340
+ #define SNMP_DEFAULT_ERRSTAT -1
341
+ #define SNMP_DEFAULT_ERRINDEX -1
342
+ #define SNMP_DEFAULT_ADDRESS 0
343
+ #define SNMP_DEFAULT_PEERNAME NULL
344
+ #define SNMP_DEFAULT_ENTERPRISE_LENGTH 0
345
+ #define SNMP_DEFAULT_TIME 0
346
+ #define SNMP_DEFAULT_VERSION -1
347
+ #define SNMP_DEFAULT_SECMODEL -1
348
+ #define SNMP_DEFAULT_CONTEXT ""
349
+ #ifndef NETSNMP_DISABLE_MD5
350
+ #define SNMP_DEFAULT_AUTH_PROTO usmHMACMD5AuthProtocol
351
+ #else
352
+ #define SNMP_DEFAULT_AUTH_PROTO usmHMACSHA1AuthProtocol
353
+ #endif
354
+ #define SNMP_DEFAULT_AUTH_PROTOLEN USM_LENGTH_OID_TRANSFORM
355
+ #ifndef NETSNMP_DISABLE_DES
356
+ #define SNMP_DEFAULT_PRIV_PROTO usmDESPrivProtocol
357
+ #else
358
+ #define SNMP_DEFAULT_PRIV_PROTO usmAESPrivProtocol
359
+ #endif
360
+ #define SNMP_DEFAULT_PRIV_PROTOLEN USM_LENGTH_OID_TRANSFORM
361
+
362
+ NETSNMP_IMPORT const char *snmp_api_errstring(int);
363
+ NETSNMP_IMPORT void snmp_perror(const char *);
364
+ NETSNMP_IMPORT void snmp_set_detail(const char *);
365
+
366
+ #define SNMP_MAX_MSG_SIZE 1472 /* ethernet MTU minus IP/UDP header */
367
+ #define SNMP_MAX_MSG_V3_HDRS (4+3+4+7+7+3+7+16) /* fudge factor=16 */
368
+ #define SNMP_MAX_ENG_SIZE 32
369
+ #define SNMP_MAX_SEC_NAME_SIZE 256
370
+ #define SNMP_MAX_CONTEXT_SIZE 256
371
+ #define SNMP_SEC_PARAM_BUF_SIZE 256
372
+
373
+ /*
374
+ * set to one to ignore unauthenticated Reports
375
+ */
376
+ #define SNMPV3_IGNORE_UNAUTH_REPORTS 0
377
+
378
+ /*
379
+ * authoritative engine definitions
380
+ */
381
+ #define SNMP_SESS_NONAUTHORITATIVE 0 /* should be 0 to default to this */
382
+ #define SNMP_SESS_AUTHORITATIVE 1 /* don't learn engineIDs */
383
+ #define SNMP_SESS_UNKNOWNAUTH 2 /* sometimes (like NRs) */
384
+
385
+ /*
386
+ * to determine type of Report from varbind_list
387
+ */
388
+ #define REPORT_STATS_LEN 9
389
+ #define REPORT_snmpUnknownSecurityModels_NUM 1
390
+ #define REPORT_snmpInvalidMsgs_NUM 2
391
+ #define REPORT_usmStatsUnsupportedSecLevels_NUM 1
392
+ #define REPORT_usmStatsNotInTimeWindows_NUM 2
393
+ #define REPORT_usmStatsUnknownUserNames_NUM 3
394
+ #define REPORT_usmStatsUnknownEngineIDs_NUM 4
395
+ #define REPORT_usmStatsWrongDigests_NUM 5
396
+ #define REPORT_usmStatsDecryptionErrors_NUM 6
397
+
398
+ #define SNMP_DETAIL_SIZE 512
399
+
400
+ #define SNMP_FLAGS_RESP_CALLBACK 0x400 /* Additional callback on response */
401
+ #define SNMP_FLAGS_USER_CREATED 0x200 /* USM user has been created */
402
+ #define SNMP_FLAGS_DONT_PROBE 0x100 /* don't probe for an engineID */
403
+ #define SNMP_FLAGS_STREAM_SOCKET 0x80
404
+ #define SNMP_FLAGS_LISTENING 0x40 /* Server stream sockets only */
405
+ #define SNMP_FLAGS_SUBSESSION 0x20
406
+ #define SNMP_FLAGS_STRIKE2 0x02
407
+ #define SNMP_FLAGS_STRIKE1 0x01
408
+
409
+ #define CLEAR_SNMP_STRIKE_FLAGS(x) \
410
+ x &= ~(SNMP_FLAGS_STRIKE2|SNMP_FLAGS_STRIKE1)
411
+
412
+ /*
413
+ * returns '1' if the session is to be regarded as dead,
414
+ * otherwise set the strike flags appropriately, and return 0
415
+ */
416
+ #define SET_SNMP_STRIKE_FLAGS(x) \
417
+ (( x & SNMP_FLAGS_STRIKE2 ) ? 1 : \
418
+ ((( x & SNMP_FLAGS_STRIKE1 ) ? ( x |= SNMP_FLAGS_STRIKE2 ) : \
419
+ ( x |= SNMP_FLAGS_STRIKE1 )), \
420
+ 0))
421
+
422
+ /*
423
+ * Error return values.
424
+ *
425
+ * SNMPERR_SUCCESS is the non-PDU "success" code.
426
+ *
427
+ * XXX These should be merged with SNMP_ERR_* defines and confined
428
+ * to values < 0. ???
429
+ */
430
+ #define SNMPERR_SUCCESS (0) /* XXX Non-PDU "success" code. */
431
+ #define SNMPERR_GENERR (-1)
432
+ #define SNMPERR_BAD_LOCPORT (-2)
433
+ #define SNMPERR_BAD_ADDRESS (-3)
434
+ #define SNMPERR_BAD_SESSION (-4)
435
+ #define SNMPERR_TOO_LONG (-5)
436
+ #define SNMPERR_NO_SOCKET (-6)
437
+ #define SNMPERR_V2_IN_V1 (-7)
438
+ #define SNMPERR_V1_IN_V2 (-8)
439
+ #define SNMPERR_BAD_REPEATERS (-9)
440
+ #define SNMPERR_BAD_REPETITIONS (-10)
441
+ #define SNMPERR_BAD_ASN1_BUILD (-11)
442
+ #define SNMPERR_BAD_SENDTO (-12)
443
+ #define SNMPERR_BAD_PARSE (-13)
444
+ #define SNMPERR_BAD_VERSION (-14)
445
+ #define SNMPERR_BAD_SRC_PARTY (-15)
446
+ #define SNMPERR_BAD_DST_PARTY (-16)
447
+ #define SNMPERR_BAD_CONTEXT (-17)
448
+ #define SNMPERR_BAD_COMMUNITY (-18)
449
+ #define SNMPERR_NOAUTH_DESPRIV (-19)
450
+ #define SNMPERR_BAD_ACL (-20)
451
+ #define SNMPERR_BAD_PARTY (-21)
452
+ #define SNMPERR_ABORT (-22)
453
+ #define SNMPERR_UNKNOWN_PDU (-23)
454
+ #define SNMPERR_TIMEOUT (-24)
455
+ #define SNMPERR_BAD_RECVFROM (-25)
456
+ #define SNMPERR_BAD_ENG_ID (-26)
457
+ #define SNMPERR_BAD_SEC_NAME (-27)
458
+ #define SNMPERR_BAD_SEC_LEVEL (-28)
459
+ #define SNMPERR_ASN_PARSE_ERR (-29)
460
+ #define SNMPERR_UNKNOWN_SEC_MODEL (-30)
461
+ #define SNMPERR_INVALID_MSG (-31)
462
+ #define SNMPERR_UNKNOWN_ENG_ID (-32)
463
+ #define SNMPERR_UNKNOWN_USER_NAME (-33)
464
+ #define SNMPERR_UNSUPPORTED_SEC_LEVEL (-34)
465
+ #define SNMPERR_AUTHENTICATION_FAILURE (-35)
466
+ #define SNMPERR_NOT_IN_TIME_WINDOW (-36)
467
+ #define SNMPERR_DECRYPTION_ERR (-37)
468
+ #define SNMPERR_SC_GENERAL_FAILURE (-38)
469
+ #define SNMPERR_SC_NOT_CONFIGURED (-39)
470
+ #define SNMPERR_KT_NOT_AVAILABLE (-40)
471
+ #define SNMPERR_UNKNOWN_REPORT (-41)
472
+ #define SNMPERR_USM_GENERICERROR (-42)
473
+ #define SNMPERR_USM_UNKNOWNSECURITYNAME (-43)
474
+ #define SNMPERR_USM_UNSUPPORTEDSECURITYLEVEL (-44)
475
+ #define SNMPERR_USM_ENCRYPTIONERROR (-45)
476
+ #define SNMPERR_USM_AUTHENTICATIONFAILURE (-46)
477
+ #define SNMPERR_USM_PARSEERROR (-47)
478
+ #define SNMPERR_USM_UNKNOWNENGINEID (-48)
479
+ #define SNMPERR_USM_NOTINTIMEWINDOW (-49)
480
+ #define SNMPERR_USM_DECRYPTIONERROR (-50)
481
+ #define SNMPERR_NOMIB (-51)
482
+ #define SNMPERR_RANGE (-52)
483
+ #define SNMPERR_MAX_SUBID (-53)
484
+ #define SNMPERR_BAD_SUBID (-54)
485
+ #define SNMPERR_LONG_OID (-55)
486
+ #define SNMPERR_BAD_NAME (-56)
487
+ #define SNMPERR_VALUE (-57)
488
+ #define SNMPERR_UNKNOWN_OBJID (-58)
489
+ #define SNMPERR_NULL_PDU (-59)
490
+ #define SNMPERR_NO_VARS (-60)
491
+ #define SNMPERR_VAR_TYPE (-61)
492
+ #define SNMPERR_MALLOC (-62)
493
+ #define SNMPERR_KRB5 (-63)
494
+ #define SNMPERR_PROTOCOL (-64)
495
+ #define SNMPERR_OID_NONINCREASING (-65)
496
+
497
+ #define SNMPERR_MAX (-65)
498
+
499
+ #define non_repeaters errstat
500
+ #define max_repetitions errindex
501
+
502
+ typedef union {
503
+ long *integer;
504
+ u_char *string;
505
+ oid *objid;
506
+ u_char *bitstring;
507
+ struct counter64 *counter64;
508
+ #ifdef NETSNMP_WITH_OPAQUE_SPECIAL_TYPES
509
+ float *floatVal;
510
+ double *doubleVal;
511
+ /*
512
+ * t_union *unionVal;
513
+ */
514
+ #endif /* NETSNMP_WITH_OPAQUE_SPECIAL_TYPES */
515
+ } netsnmp_vardata;
516
+
517
+
518
+ /** @struct variable_list
519
+ * The netsnmp variable list binding structure, it's typedef'd to
520
+ * netsnmp_variable_list.
521
+ */
522
+ struct variable_list {
523
+ /** NULL for last variable */
524
+ struct variable_list *next_variable;
525
+ /** Object identifier of variable */
526
+ oid *name;
527
+ /** number of subid's in name */
528
+ size_t name_length;
529
+ /** ASN type of variable */
530
+ u_char type;
531
+ /** value of variable */
532
+ netsnmp_vardata val;
533
+ /** the length of the value to be copied into buf */
534
+ size_t val_len;
535
+ /** 90 percentile < 24. */
536
+ oid name_loc[MAX_OID_LEN];
537
+ /** 90 percentile < 40. */
538
+ u_char buf[40];
539
+ /** (Opaque) hook for additional data */
540
+ void *data;
541
+ /** callback to free above */
542
+ void (*dataFreeHook)(void *);
543
+ int index;
544
+ };
545
+
546
+
547
+
548
+ /*
549
+ * netsnmp_session *snmp_open(session)
550
+ * netsnmp_session *session;
551
+ *
552
+ * Sets up the session with the snmp_session information provided
553
+ * by the user. Then opens and binds the necessary UDP port.
554
+ * A handle to the created session is returned (this is different than
555
+ * the pointer passed to snmp_open()). On any error, NULL is returned
556
+ * and snmp_errno is set to the appropriate error code.
557
+ */
558
+ netsnmp_session *snmp_open(netsnmp_session *);
559
+
560
+ /*
561
+ * int snmp_close(session)
562
+ * netsnmp_session *session;
563
+ *
564
+ * Close the input session. Frees all data allocated for the session,
565
+ * dequeues any pending requests, and closes any sockets allocated for
566
+ * the session. Returns 0 on error, 1 otherwise.
567
+ *
568
+ * snmp_close_sessions() does the same thing for all open sessions
569
+ */
570
+ int snmp_close(netsnmp_session *);
571
+ int snmp_close_sessions(void);
572
+
573
+
574
+ /*
575
+ * int snmp_send(session, pdu)
576
+ * netsnmp_session *session;
577
+ * netsnmp_pdu *pdu;
578
+ *
579
+ * Sends the input pdu on the session after calling snmp_build to create
580
+ * a serialized packet. If necessary, set some of the pdu data from the
581
+ * session defaults. Add a request corresponding to this pdu to the list
582
+ * of outstanding requests on this session, then send the pdu.
583
+ * Returns the request id of the generated packet if applicable, otherwise 1.
584
+ * On any error, 0 is returned.
585
+ * The pdu is freed by snmp_send() unless a failure occured.
586
+ */
587
+ int snmp_send(netsnmp_session *, netsnmp_pdu *);
588
+
589
+ /*
590
+ * int snmp_async_send(session, pdu, callback, cb_data)
591
+ * netsnmp_session *session;
592
+ * netsnmp_pdu *pdu;
593
+ * netsnmp_callback callback;
594
+ * void *cb_data;
595
+ *
596
+ * Sends the input pdu on the session after calling snmp_build to create
597
+ * a serialized packet. If necessary, set some of the pdu data from the
598
+ * session defaults. Add a request corresponding to this pdu to the list
599
+ * of outstanding requests on this session and store callback and data,
600
+ * then send the pdu.
601
+ * Returns the request id of the generated packet if applicable, otherwise 1.
602
+ * On any error, 0 is returned.
603
+ * The pdu is freed by snmp_send() unless a failure occured.
604
+ */
605
+ int snmp_async_send(netsnmp_session *, netsnmp_pdu *,
606
+ netsnmp_callback, void *);
607
+
608
+
609
+ /*
610
+ * void snmp_read(fdset)
611
+ * fd_set *fdset;
612
+ *
613
+ * Checks to see if any of the fd's set in the fdset belong to
614
+ * snmp. Each socket with it's fd set has a packet read from it
615
+ * and snmp_parse is called on the packet received. The resulting pdu
616
+ * is passed to the callback routine for that session. If the callback
617
+ * routine returns successfully, the pdu and it's request are deleted.
618
+ */
619
+ void snmp_read(fd_set *);
620
+
621
+
622
+
623
+ /*
624
+ * void
625
+ * snmp_free_pdu(pdu)
626
+ * netsnmp_pdu *pdu;
627
+ *
628
+ * Frees the pdu and any malloc'd data associated with it.
629
+ */
630
+ void snmp_free_pdu(netsnmp_pdu *);
631
+
632
+ void snmp_free_var(netsnmp_variable_list *); /* frees just this one */
633
+
634
+ void snmp_free_varbind(netsnmp_variable_list * var); /* frees all in list */
635
+
636
+ /*
637
+ * int snmp_select_info(numfds, fdset, timeout, block)
638
+ * int *numfds;
639
+ * fd_set *fdset;
640
+ * struct timeval *timeout;
641
+ * int *block;
642
+ *
643
+ * Returns info about what snmp requires from a select statement.
644
+ * numfds is the number of fds in the list that are significant.
645
+ * All file descriptors opened for SNMP are OR'd into the fdset.
646
+ * If activity occurs on any of these file descriptors, snmp_read
647
+ * should be called with that file descriptor set.
648
+ *
649
+ * The timeout is the latest time that SNMP can wait for a timeout. The
650
+ * select should be done with the minimum time between timeout and any other
651
+ * timeouts necessary. This should be checked upon each invocation of select.
652
+ * If a timeout is received, snmp_timeout should be called to check if the
653
+ * timeout was for SNMP. (snmp_timeout is idempotent)
654
+ *
655
+ * Block is 1 if the select is requested to block indefinitely, rather than
656
+ * time out. If block is input as 1, the timeout value will be treated as
657
+ * undefined, but it must be available for setting in snmp_select_info. On
658
+ * return, if block is true, the value of timeout will be undefined.
659
+ *
660
+ * snmp_select_info returns the number of open sockets. (i.e. The number
661
+ * of sessions open)
662
+ */
663
+ int snmp_select_info(int *, fd_set *, struct timeval *,
664
+ int *);
665
+
666
+
667
+
668
+ /*
669
+ * void snmp_timeout();
670
+ *
671
+ * snmp_timeout should be called whenever the timeout from snmp_select_info
672
+ * expires, but it is idempotent, so snmp_timeout can be polled (probably a
673
+ * cpu expensive proposition). snmp_timeout checks to see if any of the
674
+ * sessions have an outstanding request that has timed out. If it finds one
675
+ * (or more), and that pdu has more retries available, a new packet is formed
676
+ * from the pdu and is resent. If there are no more retries available, the
677
+ * callback for the session is used to alert the user of the timeout.
678
+ */
679
+
680
+ void snmp_timeout(void);
681
+
682
+
683
+ /*
684
+ * This routine must be supplied by the application:
685
+ *
686
+ * u_char *authenticator(pdu, length, community, community_len)
687
+ * u_char *pdu; The rest of the PDU to be authenticated
688
+ * int *length; The length of the PDU (updated by the authenticator)
689
+ * u_char *community; The community name to authenticate under.
690
+ * int community_len The length of the community name.
691
+ *
692
+ * Returns the authenticated pdu, or NULL if authentication failed.
693
+ * If null authentication is used, the authenticator in snmp_session can be
694
+ * set to NULL(0).
695
+ */
696
+
697
+
698
+
699
+ /*
700
+ * This routine must be supplied by the application:
701
+ *
702
+ * int callback(operation, session, reqid, pdu, magic)
703
+ * int operation;
704
+ * netsnmp_session *session; The session authenticated under.
705
+ * int reqid; The request id of this pdu (0 for TRAP)
706
+ * netsnmp_pdu *pdu; The pdu information.
707
+ * void *magic A link to the data for this routine.
708
+ *
709
+ * Returns 1 if request was successful, 0 if it should be kept pending.
710
+ * Any data in the pdu must be copied because it will be freed elsewhere.
711
+ * Operations are defined below:
712
+ */
713
+
714
+ #define NETSNMP_CALLBACK_OP_RECEIVED_MESSAGE 1
715
+ #define NETSNMP_CALLBACK_OP_TIMED_OUT 2
716
+ #define NETSNMP_CALLBACK_OP_SEND_FAILED 3
717
+ #define NETSNMP_CALLBACK_OP_CONNECT 4
718
+ #define NETSNMP_CALLBACK_OP_DISCONNECT 5
719
+
720
+ long snmp_get_next_msgid(void);
721
+ long snmp_get_next_reqid(void);
722
+ long snmp_get_next_sessid(void);
723
+ long snmp_get_next_transid(void);
724
+
725
+ int snmp_oid_compare(const oid *, size_t, const oid *,
726
+ size_t);
727
+ int snmp_oid_ncompare(const oid *, size_t, const oid *,
728
+ size_t, size_t);
729
+ int snmp_oidtree_compare(const oid *, size_t, const oid *,
730
+ size_t);
731
+ int snmp_oidsubtree_compare(const oid *, size_t, const oid *,
732
+ size_t);
733
+ int netsnmp_oid_compare_ll(const oid * in_name1,
734
+ size_t len1, const oid * in_name2,
735
+ size_t len2, size_t *offpt);
736
+ int netsnmp_oid_equals(const oid *, size_t, const oid *,
737
+ size_t);
738
+ int netsnmp_oid_tree_equals(const oid *, size_t, const oid *,
739
+ size_t);
740
+ int netsnmp_oid_is_subtree(const oid *, size_t, const oid *,
741
+ size_t);
742
+ int netsnmp_oid_find_prefix(const oid * in_name1, size_t len1,
743
+ const oid * in_name2, size_t len2);
744
+ void init_snmp(const char *);
745
+ u_char *snmp_pdu_build(netsnmp_pdu *, u_char *, size_t *);
746
+ #ifdef NETSNMP_USE_REVERSE_ASNENCODING
747
+ u_char *snmp_pdu_rbuild(netsnmp_pdu *, u_char *, size_t *);
748
+ #endif
749
+ int snmpv3_parse(netsnmp_pdu *, u_char *, size_t *,
750
+ u_char **, netsnmp_session *);
751
+ int snmpv3_packet_build(netsnmp_session *,
752
+ netsnmp_pdu *pdu, u_char * packet,
753
+ size_t * out_length,
754
+ u_char * pdu_data,
755
+ size_t pdu_data_len);
756
+ int snmpv3_packet_rbuild(netsnmp_session *,
757
+ netsnmp_pdu *pdu, u_char * packet,
758
+ size_t * out_length,
759
+ u_char * pdu_data,
760
+ size_t pdu_data_len);
761
+ int snmpv3_make_report(netsnmp_pdu *pdu, int error);
762
+ int snmpv3_get_report_type(netsnmp_pdu *pdu);
763
+ int snmp_pdu_parse(netsnmp_pdu *pdu, u_char * data,
764
+ size_t * length);
765
+ u_char *snmpv3_scopedPDU_parse(netsnmp_pdu *pdu, u_char * cp,
766
+ size_t * length);
767
+ void snmp_store(const char *type);
768
+ void snmp_shutdown(const char *type);
769
+ netsnmp_variable_list *snmp_pdu_add_variable(netsnmp_pdu *, const oid *,
770
+ size_t, u_char, const u_char *,
771
+ size_t);
772
+ netsnmp_variable_list *snmp_varlist_add_variable(netsnmp_variable_list
773
+ ** varlist,
774
+ const oid * name,
775
+ size_t name_length,
776
+ u_char type,
777
+ const u_char * value,
778
+ size_t len);
779
+ int snmp_add_var(netsnmp_pdu *, const oid *, size_t, char,
780
+ const char *);
781
+ oid *snmp_duplicate_objid(const oid * objToCopy, size_t);
782
+ u_int snmp_increment_statistic(int which);
783
+ u_int snmp_increment_statistic_by(int which, int count);
784
+ u_int snmp_get_statistic(int which);
785
+ void snmp_init_statistics(void);
786
+ int create_user_from_session(netsnmp_session * session);
787
+ int snmp_get_fd_for_session(struct snmp_session *sessp);
788
+
789
+ /*
790
+ * New re-allocating reverse encoding functions.
791
+ */
792
+ #ifdef NETSNMP_USE_REVERSE_ASNENCODING
793
+
794
+ int snmpv3_packet_realloc_rbuild(u_char ** pkt, size_t * pkt_len,
795
+ size_t * offset,
796
+ netsnmp_session * session,
797
+ netsnmp_pdu *pdu, u_char * pdu_data,
798
+ size_t pdu_data_len);
799
+
800
+ int snmp_pdu_realloc_rbuild(u_char ** pkt, size_t * pkt_len,
801
+ size_t * offset, netsnmp_pdu *pdu);
802
+ #endif
803
+
804
+
805
+
806
+ /*
807
+ * Extended open; fpre_parse has changed.
808
+ */
809
+
810
+ netsnmp_session *snmp_open_ex(netsnmp_session *,
811
+ int (*fpre_parse) (netsnmp_session *,
812
+ struct
813
+ netsnmp_transport_s *,
814
+ void *, int),
815
+ int (*fparse) (netsnmp_session *,
816
+ netsnmp_pdu *, u_char *,
817
+ size_t),
818
+ int (*fpost_parse) (netsnmp_session *,
819
+ netsnmp_pdu *, int),
820
+ int (*fbuild) (netsnmp_session *,
821
+ netsnmp_pdu *, u_char *,
822
+ size_t *),
823
+ int (*frbuild) (netsnmp_session *,
824
+ netsnmp_pdu *, u_char **,
825
+ size_t *, size_t *),
826
+ int (*fcheck) (u_char *, size_t));
827
+
828
+ /*
829
+ * provided for backwards compatability. Don't use these functions.
830
+ * See snmp_debug.h and snmp_debug.c instead.
831
+ */
832
+
833
+ void snmp_set_do_debugging(int);
834
+ int snmp_get_do_debugging(void);
835
+
836
+
837
+ /*
838
+ * snmp_error - return error data
839
+ * Inputs : address of errno, address of snmp_errno, address of string
840
+ * Caller must free the string returned after use.
841
+ */
842
+ void snmp_error(netsnmp_session *, int *, int *, char **);
843
+ /*
844
+ * single session API.
845
+ *
846
+ * These functions perform similar actions as snmp_XX functions,
847
+ * but operate on a single session only.
848
+ *
849
+ * Synopsis:
850
+
851
+ void * sessp;
852
+ netsnmp_session session, *ss;
853
+ netsnmp_pdu *pdu, *response;
854
+
855
+ snmp_sess_init(&session);
856
+ session.retries = ...
857
+ session.remote_port = ...
858
+ sessp = snmp_sess_open(&session);
859
+ ss = snmp_sess_session(sessp);
860
+ if (ss == NULL)
861
+ exit(1);
862
+ ...
863
+ if (ss->community) free(ss->community);
864
+ ss->community = strdup(gateway);
865
+ ss->community_len = strlen(gateway);
866
+ ...
867
+ snmp_sess_synch_response(sessp, pdu, &response);
868
+ ...
869
+ snmp_sess_close(sessp);
870
+
871
+ * See also:
872
+ * snmp_sess_synch_response, in snmp_client.h.
873
+
874
+ * Notes:
875
+ * 1. Invoke snmp_sess_session after snmp_sess_open.
876
+ * 2. snmp_sess_session return value is an opaque pointer.
877
+ * 3. Do NOT free memory returned by snmp_sess_session.
878
+ * 4. Replace snmp_send(ss,pdu) with snmp_sess_send(sessp,pdu)
879
+ */
880
+
881
+ void snmp_sess_init(netsnmp_session *);
882
+ void *snmp_sess_open(netsnmp_session *);
883
+ void *snmp_sess_pointer(netsnmp_session *);
884
+ netsnmp_session *snmp_sess_session(void *);
885
+
886
+ /*
887
+ * Return the netsnmp_transport structure associated with the given opaque
888
+ * pointer.
889
+ */
890
+
891
+ struct netsnmp_transport_s *snmp_sess_transport(void *);
892
+ void snmp_sess_transport_set(void *,
893
+ struct netsnmp_transport_s *);
894
+
895
+ /*
896
+ * EXPERIMENTAL API EXTENSIONS ------------------------------------------
897
+ *
898
+ * snmp_sess_add_ex, snmp_sess_add, snmp_add
899
+ *
900
+ * Analogous to snmp_open family of functions, but taking an
901
+ * netsnmp_transport pointer as an extra argument. Unlike snmp_open et
902
+ * al. it doesn't attempt to interpret the in_session->peername as a
903
+ * transport endpoint specifier, but instead uses the supplied transport.
904
+ * JBPN
905
+ *
906
+ */
907
+
908
+ void *snmp_sess_add_ex(netsnmp_session *,
909
+ struct netsnmp_transport_s *,
910
+ int (*fpre_parse) (netsnmp_session *,
911
+ struct
912
+ netsnmp_transport_s
913
+ *, void *, int),
914
+ int (*fparse) (netsnmp_session *,
915
+ struct snmp_pdu *,
916
+ u_char *, size_t),
917
+ int (*fpost_parse) (netsnmp_session *,
918
+ struct snmp_pdu *,
919
+ int),
920
+ int (*fbuild) (netsnmp_session *,
921
+ struct snmp_pdu *,
922
+ u_char *, size_t *),
923
+ int (*frbuild) (netsnmp_session *,
924
+ struct snmp_pdu *,
925
+ u_char **, size_t *,
926
+ size_t *),
927
+ int (*fcheck) (u_char *, size_t),
928
+ netsnmp_pdu *(*fcreate_pdu) (struct
929
+ netsnmp_transport_s
930
+ *,
931
+ void *,
932
+ size_t));
933
+
934
+ void *snmp_sess_add(netsnmp_session *,
935
+ struct netsnmp_transport_s *,
936
+ int (*fpre_parse) (netsnmp_session *,
937
+ struct
938
+ netsnmp_transport_s *,
939
+ void *, int),
940
+ int (*fpost_parse) (netsnmp_session *,
941
+ netsnmp_pdu *, int));
942
+
943
+ netsnmp_session *snmp_add(netsnmp_session *,
944
+ struct netsnmp_transport_s *,
945
+ int (*fpre_parse) (netsnmp_session *,
946
+ struct netsnmp_transport_s
947
+ *, void *, int),
948
+ int (*fpost_parse) (netsnmp_session *,
949
+ netsnmp_pdu *, int));
950
+ netsnmp_session *snmp_add_full(netsnmp_session * in_session,
951
+ struct netsnmp_transport_s *transport,
952
+ int (*fpre_parse) (netsnmp_session *,
953
+ struct
954
+ netsnmp_transport_s
955
+ *, void *, int),
956
+ int (*fparse) (netsnmp_session *,
957
+ netsnmp_pdu *, u_char *,
958
+ size_t),
959
+ int (*fpost_parse) (netsnmp_session *,
960
+ netsnmp_pdu *, int),
961
+ int (*fbuild) (netsnmp_session *,
962
+ netsnmp_pdu *, u_char *,
963
+ size_t *),
964
+ int (*frbuild) (netsnmp_session *,
965
+ netsnmp_pdu *,
966
+ u_char **, size_t *,
967
+ size_t *),
968
+ int (*fcheck) (u_char *, size_t),
969
+ netsnmp_pdu *(*fcreate_pdu) (struct
970
+ netsnmp_transport_s
971
+ *, void *,
972
+ size_t)
973
+ );
974
+
975
+ /*
976
+ * use return value from snmp_sess_open as void * parameter
977
+ */
978
+
979
+ int snmp_sess_send(void *, netsnmp_pdu *);
980
+ int snmp_sess_async_send(void *, netsnmp_pdu *,
981
+ netsnmp_callback, void *);
982
+ int snmp_sess_select_info(void *, int *, fd_set *,
983
+ struct timeval *, int *);
984
+ int snmp_sess_read(void *, fd_set *);
985
+ void snmp_sess_timeout(void *);
986
+ int snmp_sess_close(void *);
987
+
988
+ void snmp_sess_error(void *, int *, int *, char **);
989
+ void netsnmp_sess_log_error(int priority,
990
+ const char *prog_string,
991
+ netsnmp_session * ss);
992
+ void snmp_sess_perror(const char *prog_string,
993
+ netsnmp_session * ss);
994
+ const char * snmp_pdu_type(int type);
995
+
996
+ /*
997
+ * end single session API
998
+ */
999
+
1000
+ /*
1001
+ * generic statistic counters
1002
+ */
1003
+
1004
+ /*
1005
+ * snmpv3 statistics
1006
+ */
1007
+
1008
+ /*
1009
+ * mpd stats
1010
+ */
1011
+ #define STAT_SNMPUNKNOWNSECURITYMODELS 0
1012
+ #define STAT_SNMPINVALIDMSGS 1
1013
+ #define STAT_SNMPUNKNOWNPDUHANDLERS 2
1014
+ #define STAT_MPD_STATS_START STAT_SNMPUNKNOWNSECURITYMODELS
1015
+ #define STAT_MPD_STATS_END STAT_SNMPUNKNOWNPDUHANDLERS
1016
+
1017
+ /*
1018
+ * usm stats
1019
+ */
1020
+ #define STAT_USMSTATSUNSUPPORTEDSECLEVELS 3
1021
+ #define STAT_USMSTATSNOTINTIMEWINDOWS 4
1022
+ #define STAT_USMSTATSUNKNOWNUSERNAMES 5
1023
+ #define STAT_USMSTATSUNKNOWNENGINEIDS 6
1024
+ #define STAT_USMSTATSWRONGDIGESTS 7
1025
+ #define STAT_USMSTATSDECRYPTIONERRORS 8
1026
+ #define STAT_USM_STATS_START STAT_USMSTATSUNSUPPORTEDSECLEVELS
1027
+ #define STAT_USM_STATS_END STAT_USMSTATSDECRYPTIONERRORS
1028
+
1029
+ /*
1030
+ * snmp counters
1031
+ */
1032
+ #define STAT_SNMPINPKTS 9
1033
+ #define STAT_SNMPOUTPKTS 10
1034
+ #define STAT_SNMPINBADVERSIONS 11
1035
+ #define STAT_SNMPINBADCOMMUNITYNAMES 12
1036
+ #define STAT_SNMPINBADCOMMUNITYUSES 13
1037
+ #define STAT_SNMPINASNPARSEERRS 14
1038
+ /*
1039
+ * #define STAT_SNMPINBADTYPES 15
1040
+ */
1041
+ #define STAT_SNMPINTOOBIGS 16
1042
+ #define STAT_SNMPINNOSUCHNAMES 17
1043
+ #define STAT_SNMPINBADVALUES 18
1044
+ #define STAT_SNMPINREADONLYS 19
1045
+ #define STAT_SNMPINGENERRS 20
1046
+ #define STAT_SNMPINTOTALREQVARS 21
1047
+ #define STAT_SNMPINTOTALSETVARS 22
1048
+ #define STAT_SNMPINGETREQUESTS 23
1049
+ #define STAT_SNMPINGETNEXTS 24
1050
+ #define STAT_SNMPINSETREQUESTS 25
1051
+ #define STAT_SNMPINGETRESPONSES 26
1052
+ #define STAT_SNMPINTRAPS 27
1053
+ #define STAT_SNMPOUTTOOBIGS 28
1054
+ #define STAT_SNMPOUTNOSUCHNAMES 29
1055
+ #define STAT_SNMPOUTBADVALUES 30
1056
+ /*
1057
+ * #define STAT_SNMPOUTREADONLYS 31
1058
+ */
1059
+ #define STAT_SNMPOUTGENERRS 32
1060
+ #define STAT_SNMPOUTGETREQUESTS 33
1061
+ #define STAT_SNMPOUTGETNEXTS 34
1062
+ #define STAT_SNMPOUTSETREQUESTS 35
1063
+ #define STAT_SNMPOUTGETRESPONSES 36
1064
+ #define STAT_SNMPOUTTRAPS 37
1065
+ /*
1066
+ * AUTHTRAPENABLE 38
1067
+ */
1068
+ #define STAT_SNMPSILENTDROPS 39
1069
+ #define STAT_SNMPPROXYDROPS 40
1070
+ #define STAT_SNMP_STATS_START STAT_SNMPINPKTS
1071
+ #define STAT_SNMP_STATS_END STAT_SNMPPROXYDROPS
1072
+
1073
+ /*
1074
+ * target mib counters
1075
+ */
1076
+ #define STAT_SNMPUNAVAILABLECONTEXTS 41
1077
+ #define STAT_SNMPUNKNOWNCONTEXTS 42
1078
+ #define STAT_TARGET_STATS_START STAT_SNMPUNAVAILABLECONTEXTS
1079
+ #define STAT_TARGET_STATS_END STAT_SNMPUNKNOWNCONTEXTS
1080
+
1081
+ #define MAX_STATS 43
1082
+
1083
+ #ifdef __cplusplus
1084
+ }
1085
+ #endif
1086
+ #endif /* SNMP_API_H */