1,SNMP中MIB节点的查找采用桶散列数据结构,即先对节点进行散列值,然后将该节点放入桶中形成链表;详见《TCP/IP网际互联卷2》P365。 2,SNMP中用到的散列算法如下: /*------------------------------------------------------------------------ * hashoid - hash the object id *------------------------------------------------------------------------ */ int hashoid(struct oid *oip) { register unsigned tot; register int i; for (tot = 0, i = oip->len - 1; i >= 0; i--) tot = tot * S_HTRADIX + oip->id[i]; return tot % S_HTABSIZ; } 3,在散列表中查找特定MIB节点算法: struct mib_info * getmib(struct oid *oip) { struct snhnode *hp; int loc, i; loc = hashoid(oip); /* try the regular hash table and get the hash value of the name*/ for (hp = snhtab[loc]; hp; hp = hp->sh_next) if (oidequ(oip, &hp->sh_mip->mi_objid)) { return hp->sh_mip; } for (i = 0; i < S_NUMTABS; ++i) /* try the table table */ if (!memcmp(tabtab[i].ti_mip->mi_objid.id, oip->id, tabtab[i].ti_mip->mi_objid.len * 2)) { return tabtab[i].ti_mip; } return 0; }