]> git.pld-linux.org Git - packages/net-snmp.git/commitdiff
- for v1 use GetNext, for anything bigger use GetBulk
authorElan Ruusamäe <glen@pld-linux.org>
Thu, 22 Jan 2009 16:29:55 +0000 (16:29 +0000)
committercvs2git <feedback@pld-linux.org>
Sun, 24 Jun 2012 12:13:13 +0000 (12:13 +0000)
Changed files:
    net-snmp-snmpnetstat-getbulk.patch -> 1.2

net-snmp-snmpnetstat-getbulk.patch

index 7a4c99b994e5c4d5d07b3583bc3e8d7ae114ca1f..00a7a3302d50dac955873232a7d2fcb57c157d0a 100644 (file)
@@ -1,56 +1,97 @@
 --- net-snmp-5.4.2.1/apps/snmpnetstat/inet.c   2006-04-21 15:30:47.000000000 +0300
-+++ /home/glen/inet.c  2009-01-22 17:39:57.754383000 +0200
-@@ -110,8 +110,10 @@
- tcpprotopr(const char *name)
++++ net-snmp-5.4.2.1-dev/apps/snmpnetstat/inet.c       2009-01-22 18:26:23.264301468 +0200
+@@ -106,20 +106,65 @@
+ };
+ #define TCP_NSTATES 11
+-void
+-tcpprotopr(const char *name)
++static void
++tcpprotoprint_line(const char *name, netsnmp_variable_list *vp, int *first)
  {
-     netsnmp_variable_list *var, *vp;
+-    netsnmp_variable_list *var, *vp;
 -    oid    tcpConnState_oid[] = { 1,3,6,1,2,1,6,13,1,1 };
 -    size_t tcpConnState_len   = OID_LENGTH( tcpConnState_oid );
-+      netsnmp_pdu    *pdu, *response;
-+    oid             tcpConnState_mib[] = { 1,3,6,1,2,1,6,13,1,1 };
-+    oid             tcpConnState_oid[MAX_OID_LEN];
-+    size_t          tcpConnState_len;
      int    state, width;
++    char  *cp;
      union {
          struct in_addr addr;
-@@ -121,61 +123,126 @@
+         char      data[4];
+     } tmpAddr;
+     oid    localPort, remotePort;
      struct in_addr localAddr, remoteAddr;
-     char  *cp;
-     int    first = 1;
-+    int    running = 1;
-+    int    status;
+-    char  *cp;
++
++      state = *vp->val.integer;
++      if (!aflag && state == MIB_TCPCONNSTATE_LISTEN) {
++              return;
++      }
 +
++      if (*first) {
++              printf("Active Internet (%s) Connections", name);
++              if (aflag)
++                      printf(" (including servers)");
++              putchar('\n');
++              width = Aflag ? 18 : 22;
++              printf("%-5.5s %*.*s %*.*s %s\n",
++                         "Proto", -width, width, "Local Address",
++                                              -width, width, "Remote Address", "(state)");
++              *first = 0;
++      }
++      
++      /* Extract the local/remote information from the index values */
++      cp = tmpAddr.data;
++      cp[0] = vp->name[ 10 ] & 0xff;
++      cp[1] = vp->name[ 11 ] & 0xff;
++      cp[2] = vp->name[ 12 ] & 0xff;
++      cp[3] = vp->name[ 13 ] & 0xff;
++      localAddr.s_addr = tmpAddr.addr.s_addr;
++      localPort        = ntohs(vp->name[ 14 ]);
++      cp = tmpAddr.data;
++      cp[0] = vp->name[ 15 ] & 0xff;
++      cp[1] = vp->name[ 16 ] & 0xff;
++      cp[2] = vp->name[ 17 ] & 0xff;
++      cp[3] = vp->name[ 18 ] & 0xff;
++      remoteAddr.s_addr = tmpAddr.addr.s_addr;
++      remotePort        = ntohs(vp->name[ 19 ]);
 +
-+    /*
-+     * setup initial object name
-+     */
-+      memmove(tcpConnState_oid, tcpConnState_mib, sizeof(tcpConnState_mib));
-+      tcpConnState_len = sizeof(tcpConnState_mib) / sizeof(oid);
++      printf("%-5.5s", name);
++      inetprint(&localAddr,  localPort,  name, 1);
++      inetprint(&remoteAddr, remotePort, name, 0);
++      if (state < 1 || state > TCP_NSTATES) {
++              printf("%d\n", state );
++      } else {
++              printf("%s\n", tcpstates[state]);
++      }
++}
++
++static void
++tcpprotopr_get(const char *name, oid *root, size_t root_len)
++{
++    netsnmp_variable_list *var, *vp;
+     int    first = 1;
  
      /*
-      * Walking the tcpConnState column will provide all
+@@ -127,7 +172,7 @@
       *   the necessary information.
       */
--    var = NULL;
+     var = NULL;
 -    snmp_varlist_add_variable( &var, tcpConnState_oid, tcpConnState_len,
--                                   ASN_NULL, NULL,  0);
--    if (!var)
--        return;
--    if (netsnmp_query_walk( var, ss ) != SNMP_ERR_NOERROR)
--        return;
--
--    for (vp = var; vp ; vp=vp->next_variable) {
++    snmp_varlist_add_variable( &var, root, root_len,
+                                    ASN_NULL, NULL,  0);
+     if (!var)
+         return;
+@@ -135,47 +180,113 @@
+         return;
+     for (vp = var; vp ; vp=vp->next_variable) {
 -        state = *vp->val.integer;
 -        if (!aflag && state == MIB_TCPCONNSTATE_LISTEN)
 -            continue;
-+      while (running) {
-+        /*
-+         * create PDU for GETBULK request and add object name to request
-+         */
-+        pdu = snmp_pdu_create(SNMP_MSG_GETBULK);
-+        pdu->non_repeaters = 0;
-+        pdu->max_repetitions = 1024;    /* fill the packet */
-+        snmp_add_null_var(pdu, tcpConnState_oid, tcpConnState_len);
++              tcpprotoprint_line(name, vp, &first);
++    }
++    snmp_free_varbind( var );
++}
  
 -        if (first) {
 -            printf("Active Internet (%s) Connections", name);
 -                   "Proto", -width, width, "Local Address",
 -                            -width, width, "Remote Address", "(state)");
 -            first=0;
++void
++tcpprotopr_bulkget(const char *name, oid *root, size_t root_len)
++{
++    netsnmp_variable_list *vp;
++      netsnmp_pdu    *pdu, *response;
++    oid             tcpConnState_oid[MAX_OID_LEN];
++      size_t          tcpConnState_len;
++    int    first = 1;
++    int    running = 1;
++    int    status;
++
++      /*
++     * setup initial object name
++     */
++      memmove(tcpConnState_oid, root, sizeof(root) * root_len);
++      tcpConnState_len = root_len;
++
++    /*
++     * Walking the tcpConnState column will provide all
++     *   the necessary information.
++     */
++      while (running) {
++        /*
++         * create PDU for GETBULK request and add object name to request
++         */
++        pdu = snmp_pdu_create(SNMP_MSG_GETBULK);
++        pdu->non_repeaters = 0;
++        pdu->max_repetitions = 1024;    /* fill the packet */
++        snmp_add_null_var(pdu, tcpConnState_oid, tcpConnState_len);
++
 +        /*
 +         * do the request
 +         */
 +        if (status == STAT_SUCCESS) {
 +            if (response->errstat == SNMP_ERR_NOERROR) {
 +                              for (vp = response->variables; vp ; vp=vp->next_variable) {
-+
-+                    if ((vp->name_length < sizeof(tcpConnState_mib) / sizeof(oid)) ||
-+                                                      (memcmp(tcpConnState_mib, vp->name, sizeof(tcpConnState_mib)) != 0)) {
++                    if ((vp->name_length < root_len) ||
++                                                      (memcmp(root, vp->name, sizeof(oid) * root_len) != 0)) {
 +                        /*
 +                         * not part of this subtree
 +                         */
 +                        continue;
 +                    }
 +
-+                                      state = *vp->val.integer;
-+                                      if (!aflag && state == MIB_TCPCONNSTATE_LISTEN) {
-+                                              continue;
-+                                      }
-+
-+                                      if (first) {
-+                                              printf("Active Internet (%s) Connections", name);
-+                                              if (aflag)
-+                                                      printf(" (including servers)");
-+                                              putchar('\n');
-+                                              width = Aflag ? 18 : 22;
-+                                              printf("%-5.5s %*.*s %*.*s %s\n",
-+                                                         "Proto", -width, width, "Local Address",
-+                                                                              -width, width, "Remote Address", "(state)");
-+                                              first = 0;
-+                                      }
-+                                      
-+                                      /* Extract the local/remote information from the index values */
-+                                      cp = tmpAddr.data;
-+                                      cp[0] = vp->name[ 10 ] & 0xff;
-+                                      cp[1] = vp->name[ 11 ] & 0xff;
-+                                      cp[2] = vp->name[ 12 ] & 0xff;
-+                                      cp[3] = vp->name[ 13 ] & 0xff;
-+                                      localAddr.s_addr = tmpAddr.addr.s_addr;
-+                                      localPort        = ntohs(vp->name[ 14 ]);
-+                                      cp = tmpAddr.data;
-+                                      cp[0] = vp->name[ 15 ] & 0xff;
-+                                      cp[1] = vp->name[ 16 ] & 0xff;
-+                                      cp[2] = vp->name[ 17 ] & 0xff;
-+                                      cp[3] = vp->name[ 18 ] & 0xff;
-+                                      remoteAddr.s_addr = tmpAddr.addr.s_addr;
-+                                      remotePort        = ntohs(vp->name[ 19 ]);
-+
-+                                      printf("%-5.5s", name);
-+                                      inetprint(&localAddr,  localPort,  name, 1);
-+                                      inetprint(&remoteAddr, remotePort, name, 0);
-+                                      if (state < 1 || state > TCP_NSTATES) {
-+                                              printf("%d\n", state );
-+                                      } else {
-+                                              printf("%s\n", tcpstates[state]);
-+                                      }
++                                      tcpprotoprint_line(name, vp, &first);
 +
 +                    if ((vp->type != SNMP_ENDOFMIBVIEW) &&
 +                        (vp->type != SNMP_NOSUCHOBJECT) &&
 +                         * Check if last variable, and if so, save for next request.
 +                         */
 +                        if (vp->next_variable == NULL) {
-+//                                                    printf("old: "); fprint_objid(stdout, tcpConnState_oid, tcpConnState_len);
-+
 +                            memmove(tcpConnState_oid, vp->name,
 +                                    vp->name_length * sizeof(oid));
 +                            tcpConnState_len = vp->name_length;
-+
-+//                                                    printf("new: "); fprint_objid(stdout, tcpConnState_oid, tcpConnState_len);
 +                        }
 +                    } else {
 +                        /*
 +        if (response) {
 +            snmp_free_pdu(response);
 +              }
++      }
++}
++
++void
++tcpprotopr(const char *name)
++{
++    oid    tcpConnState_oid[] = { 1,3,6,1,2,1,6,13,1,1 };
++    size_t tcpConnState_len   = OID_LENGTH( tcpConnState_oid );
++      int    use_getbulk = 1;
++
++#ifndef NETSNMP_DISABLE_SNMPV1
++    if (ss->version == SNMP_VERSION_1) {
++        use_getbulk = 0;
++      }
++#endif
++
++      if (use_getbulk) {
++              tcpprotopr_bulkget(name, tcpConnState_oid, tcpConnState_len);
++      } else {
++              tcpprotopr_get(name, tcpConnState_oid, tcpConnState_len);
 +      }
  }
  
This page took 0.101331 seconds and 4 git commands to generate.