示例#1
0
        public static Hashtable VblToHashTable(IntPtr vbl)
        {
            int       count = 0;
            ArrayList al    = new ArrayList();
            SMIOID    name  = new SMIOID();
            SMIVALUE  val   = new SMIVALUE();
            Hashtable ht    = new Hashtable();

            SNMPAPI_STATUS rc;

            //
            //  Get the variable count and set the capacity of the arraylist.  This
            //  speeds our processing as there's no need to expand the list as
            //  we add entries.
            //
            rc = SnmpAPI.SnmpCountVbl(vbl);
            if (rc != SNMPAPI_STATUS.SNMPAPI_FAILURE)
            {
                count = (int)rc;
            }
            al.Capacity = count;

            for (int i = 1; i <= count; i++)
            {
                rc = SnmpAPI.SnmpGetVb(vbl, i, ref name, ref val);
                if (rc != SNMPAPI_STATUS.SNMPAPI_SUCCESS)
                {
                    break;
                }

                //
                //  Build the variable name
                //
                string soid = OidToString(ref name);
                string v    = VbToString(ref val);
                if (soid != null)
                {
                    if (ht.ContainsKey(soid))
                    {
                        ht[soid] = ht[soid] + " " + v;
                    }
                    else
                    {
                        ht.Add(soid, v);
                    }
                }
            }
            return(ht);
        }
示例#2
0
        public static ArrayList VblToArrayList(IntPtr vbl)
        {
            int       count = 0;
            ArrayList al    = new ArrayList();
            SMIOID    name  = new SMIOID();
            SMIVALUE  val   = new SMIVALUE();

            SNMPAPI_STATUS rc;

            //
            //  Get the variable count and set the capacity of the arraylist.  This
            //  speeds our processing as there's no need to expand the list as
            //  we add entries.
            //
            rc = SnmpAPI.SnmpCountVbl(vbl);
            if (rc != SNMPAPI_STATUS.SNMPAPI_FAILURE)
            {
                count = (int)rc;
            }
            al.Capacity = count;

            for (int i = 1; i <= count; i++)
            {
                rc = SnmpAPI.SnmpGetVb(vbl, i, ref name, ref val);
                if (rc != SNMPAPI_STATUS.SNMPAPI_SUCCESS)
                {
                    break;
                }

                //
                //  Build the variable name
                //
                string soid = OidToString(ref name);
                string v    = VbToString(ref val);
                if (soid != null)
                {
                    al.Add(soid + oidDelimiter + v + oidDelimiter);
                }
            }
            return(al);
        }