1 --- net-snmp-5.4.2.1-dev/apps/snmpnetstat/inet.c 2009-01-22 18:26:23.264301468 +0200
2 +++ net-snmp-5.4.2.1-dev/apps/snmpnetstat/inet.c 2009-01-22 18:48:30.400620330 +0200
8 -tcpprotopr(const char *name)
10 +tcpprotoprint_line(const char *name, netsnmp_variable_list *vp, int *first)
12 - netsnmp_variable_list *var, *vp;
13 - oid tcpConnState_oid[] = { 1,3,6,1,2,1,6,13,1,1 };
14 - size_t tcpConnState_len = OID_LENGTH( tcpConnState_oid );
21 oid localPort, remotePort;
22 struct in_addr localAddr, remoteAddr;
25 + state = *vp->val.integer;
26 + if (!aflag && state == MIB_TCPCONNSTATE_LISTEN) {
31 + printf("Active Internet (%s) Connections", name);
33 + printf(" (including servers)");
35 + width = Aflag ? 18 : 22;
36 + printf("%-5.5s %*.*s %*.*s %s\n",
37 + "Proto", -width, width, "Local Address",
38 + -width, width, "Remote Address", "(state)");
42 + /* Extract the local/remote information from the index values */
44 + cp[0] = vp->name[ 10 ] & 0xff;
45 + cp[1] = vp->name[ 11 ] & 0xff;
46 + cp[2] = vp->name[ 12 ] & 0xff;
47 + cp[3] = vp->name[ 13 ] & 0xff;
48 + localAddr.s_addr = tmpAddr.addr.s_addr;
49 + localPort = ntohs(vp->name[ 14 ]);
51 + cp[0] = vp->name[ 15 ] & 0xff;
52 + cp[1] = vp->name[ 16 ] & 0xff;
53 + cp[2] = vp->name[ 17 ] & 0xff;
54 + cp[3] = vp->name[ 18 ] & 0xff;
55 + remoteAddr.s_addr = tmpAddr.addr.s_addr;
56 + remotePort = ntohs(vp->name[ 19 ]);
58 + printf("%-5.5s", name);
59 + inetprint(&localAddr, localPort, name, 1);
60 + inetprint(&remoteAddr, remotePort, name, 0);
61 + if (state < 1 || state > TCP_NSTATES) {
62 + printf("%d\n", state );
64 + printf("%s\n", tcpstates[state]);
69 +tcpprotopr_get(const char *name, oid *root, size_t root_len)
71 + netsnmp_variable_list *var, *vp;
76 * the necessary information.
79 - snmp_varlist_add_variable( &var, tcpConnState_oid, tcpConnState_len,
80 + snmp_varlist_add_variable( &var, root, root_len,
84 @@ -137,45 +182,111 @@
85 for (vp = var; vp ; vp=vp->next_variable) {
86 - state = *vp->val.integer;
87 - if (!aflag && state == MIB_TCPCONNSTATE_LISTEN)
91 - printf("Active Internet (%s) Connections", name);
93 - printf(" (including servers)");
95 - width = Aflag ? 18 : 22;
96 - printf("%-5.5s %*.*s %*.*s %s\n",
97 - "Proto", -width, width, "Local Address",
98 - -width, width, "Remote Address", "(state)");
102 - /* Extract the local/remote information from the index values */
104 - cp[0] = vp->name[ 10 ] & 0xff;
105 - cp[1] = vp->name[ 11 ] & 0xff;
106 - cp[2] = vp->name[ 12 ] & 0xff;
107 - cp[3] = vp->name[ 13 ] & 0xff;
108 - localAddr.s_addr = tmpAddr.addr.s_addr;
109 - localPort = ntohs(vp->name[ 14 ]);
111 - cp[0] = vp->name[ 15 ] & 0xff;
112 - cp[1] = vp->name[ 16 ] & 0xff;
113 - cp[2] = vp->name[ 17 ] & 0xff;
114 - cp[3] = vp->name[ 18 ] & 0xff;
115 - remoteAddr.s_addr = tmpAddr.addr.s_addr;
116 - remotePort = ntohs(vp->name[ 19 ]);
118 - printf("%-5.5s", name);
119 - inetprint(&localAddr, localPort, name, 1);
120 - inetprint(&remoteAddr, remotePort, name, 0);
121 - if ( state < 1 || state > TCP_NSTATES )
122 - printf("%d\n", state );
124 - printf("%s\n", tcpstates[ state ]);
125 + tcpprotoprint_line(name, vp, &first);
127 snmp_free_varbind( var );
131 +tcpprotopr_bulkget(const char *name, oid *root, size_t root_len)
133 + netsnmp_variable_list *vp;
134 + netsnmp_pdu *pdu, *response;
135 + oid tcpConnState_oid[MAX_OID_LEN];
136 + size_t tcpConnState_len;
142 + * setup initial object name
144 + memmove(tcpConnState_oid, root, sizeof(root) * root_len);
145 + tcpConnState_len = root_len;
148 + * Walking the tcpConnState column will provide all
149 + * the necessary information.
153 + * create PDU for GETBULK request and add object name to request
155 + pdu = snmp_pdu_create(SNMP_MSG_GETBULK);
156 + pdu->non_repeaters = 0;
157 + pdu->max_repetitions = max_getbulk; /* fill the packet */
158 + snmp_add_null_var(pdu, tcpConnState_oid, tcpConnState_len);
163 + status = snmp_synch_response(ss, pdu, &response);
164 + if (status == STAT_SUCCESS) {
165 + if (response->errstat == SNMP_ERR_NOERROR) {
166 + for (vp = response->variables; vp ; vp=vp->next_variable) {
167 + if ((vp->name_length < root_len) ||
168 + (memcmp(root, vp->name, sizeof(oid) * root_len) != 0)) {
170 + * not part of this subtree
176 + tcpprotoprint_line(name, vp, &first);
178 + if ((vp->type != SNMP_ENDOFMIBVIEW) &&
179 + (vp->type != SNMP_NOSUCHOBJECT) &&
180 + (vp->type != SNMP_NOSUCHINSTANCE)) {
182 + * Check if last variable, and if so, save for next request.
184 + if (vp->next_variable == NULL) {
185 + memmove(tcpConnState_oid, vp->name,
186 + vp->name_length * sizeof(oid));
187 + tcpConnState_len = vp->name_length;
191 + * an exception value, so stop
198 + * error in response, print it
202 + } else if (status == STAT_TIMEOUT) {
204 + } else { /* status == STAT_ERROR */
209 + snmp_free_pdu(response);
215 +tcpprotopr(const char *name)
217 + oid tcpConnState_oid[] = { 1,3,6,1,2,1,6,13,1,1 };
218 + size_t tcpConnState_len = OID_LENGTH( tcpConnState_oid );
219 + int use_getbulk = 1;
221 +#ifndef NETSNMP_DISABLE_SNMPV1
222 + if (ss->version == SNMP_VERSION_1) {
228 + tcpprotopr_bulkget(name, tcpConnState_oid, tcpConnState_len);
230 + tcpprotopr_get(name, tcpConnState_oid, tcpConnState_len);
235 --- net-snmp-5.4.2.1/man/snmpnetstat.1.def 2009-01-22 18:43:30.073986008 +0200
236 +++ net-snmp-5.4.2.1-dev/man/snmpnetstat.1.def 2009-01-22 18:57:34.170565184 +0200
238 traffic on the configured network interfaces.
239 The fourth form displays statistics about the named protocol.
242 +will issue GETBULK requests to query for information
243 +if at least protocol version
247 AGENT identifies a target SNMP agent, which is
248 instrumented to monitor the given objects.
249 At its simplest, the AGENT specification will
251 is also present, show per-protocol routing statistics instead of
254 +.BI \-CR " repeaters"
255 +For GETBULK requests,
257 +specifies the max-repeaters value to use.
259 When snmpnetstat is invoked with an interval argument, it
260 displays a running count of statistics related to network
262 --- net-snmp-5.4.2.1/apps/snmpnetstat/main.c 2006-09-15 03:48:50.000000000 +0300
263 +++ net-snmp-5.4.2.1-dev/apps/snmpnetstat/main.c 2009-01-22 18:48:17.313950236 +0200
265 int tflag; /* show i/f watchdog timers */
266 int vflag; /* be verbose */
269 int interval; /* repeat interval for i/f stats */
270 char *intrface; /* desired i/f for stats, or NULL for all i/fs */
271 int af; /* address family */
272 +int max_getbulk = 32; /* specifies the max-repeaters value to use with GETBULK requests */
274 char *progname = NULL;
281 + if (optind < argc) {
282 + if (argv[optind]) {
283 + max_getbulk = atoi(argv[optind]);
284 + if (max_getbulk == 0) {
286 + fprintf(stderr, "Bad -CR option: %s\n",
293 + fprintf(stderr, "Bad -CR option: no argument given\n");
298 case 'S': /* FreeBSD:
299 NetBSD: Semi-numeric display
300 OpenBSD: Show route source selector */
301 --- net-snmp-5.4.2.1/apps/snmpnetstat/netstat.h~ 2009-01-22 19:09:36.000000000 +0200
302 +++ net-snmp-5.4.2.1/apps/snmpnetstat/netstat.h 2009-01-22 19:09:38.270836446 +0200
304 extern char *intrface; /* desired i/f for stats, or NULL for all i/fs */
306 extern int af; /* address family */
307 +extern int max_getbulk; /* specifies the max-repeaters value to use with GETBULK requests */
309 extern char *__progname; /* program name, from crt0.o */