Go to the documentation of this file.00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034 #include <string.h>
00035
00036 #include <pro/snmp_api.h>
00037
00042
00043
00044
00045
00046 static uint32_t statistics[SNMP_STAT_MAX];
00047
00048
00056 int SnmpOidLenCmp(CONST OID * name1, CONST OID * name2, size_t len)
00057 {
00058
00059 while (len--) {
00060 if (*name1 < *name2) {
00061
00062 return -1;
00063 }
00064 if (*name1++ > *name2++) {
00065
00066 return 1;
00067 }
00068 }
00069
00070 return 0;
00071 }
00072
00084 int SnmpOidCmp(CONST OID * name1, size_t len1, CONST OID * name2, size_t len2)
00085 {
00086
00087 int rc = SnmpOidLenCmp(name1, name2, (len1 < len2) ? len1 : len2);
00088
00089 if (rc == 0) {
00090 if (len1 < len2) {
00091 rc = -1;
00092 } else if (len1 > len2) {
00093 rc = 1;
00094 }
00095 }
00096 return rc;
00097 }
00098
00111 int SnmpOidTreeCmp(CONST OID * objid, size_t objlen, CONST OID * treeid, size_t treelen)
00112 {
00113
00114 int rc = SnmpOidLenCmp(objid, treeid, (objlen < treelen) ? objlen : treelen);
00115
00116 if (rc == 0 && objlen < treelen) {
00117 rc = -1;
00118 }
00119 return rc;
00120 }
00121
00134 int SnmpOidCmpIdx(CONST OID * name1, size_t len1, CONST OID * name2, size_t len2, OID index)
00135 {
00136 size_t len = (len1 < len2) ? len1 : len2;
00137
00138 int rc = SnmpOidLenCmp(name1, name2, len);
00139
00140 if (rc == 0) {
00141 if (len1 < len2) {
00142 rc = -1;
00143 } else if (len1 > len2) {
00144 if (*(name1 + len) < index) {
00145
00146 rc = -1;
00147 } else if (*(name1 + len) > index) {
00148
00149 rc = 1;
00150 } else if (len1 > len2 + 1) {
00151 rc = 1;
00152 }
00153 }
00154 }
00155 return rc;
00156 }
00157
00158
00159
00160
00161
00162
00163
00164
00165
00166
00167
00168
00169
00170
00171
00172 int SnmpOidEquals(CONST OID * name1, size_t len1, CONST OID * name2, size_t len2)
00173 {
00174 if (len1 != len2 || memcmp(name1, name2, len1)) {
00175 return -1;
00176 }
00177 return 0;
00178 }
00179
00180
00181 void SnmpStatsInc(int which)
00182 {
00183 if (which >= 0 && which < SNMP_STAT_MAX) {
00184 statistics[which]++;
00185 }
00186 }
00187
00188 uint32_t SnmpStatsGet(int which)
00189 {
00190 if (which >= 0 && which < SNMP_STAT_MAX) {
00191 return statistics[which];
00192 }
00193 return 0;
00194 }
00195
00196 void SnmpStatsSet(int which, uint32_t value)
00197 {
00198 if (which >= 0 && which < SNMP_STAT_MAX) {
00199 statistics[which] = value;
00200 }
00201 }
00202