elvis30901 2019-05-06 17:40 采纳率: 0%
浏览 698

snmpset 一直跑出 Reason: noAccess 怎麼辦?

小弟目前在cyclone v 架設 snmp
在測試snmpset時一直發生以下錯誤:

Error in packet.
Reason: noAccess
Failed object: Test-MIB::GetTime.0

上網查了之後覺得是權限問題,所以修改了snmpd.conf 如下
图片说明

應該要能寫入了但仍然不行
附上程式碼:

#include
#include
#include
#include "Test.h"
#include

#include
#include
#include
#include
#include
#include
#include
#include
#include
#include
/** Initializes the Test module */

void
init_Test(void)
{
const oid GetTime_oid[] = { 1, 3, 6, 1, 4, 1, 16535, 1, 1 };

DEBUGMSGTL(("Test", "Initializing\n"));

netsnmp_register_scalar(netsnmp_create_handler_registration
                        ("GetTime", handle_GetTime, GetTime_oid,
                         OID_LENGTH(GetTime_oid), HANDLER_CAN_RONLY));

}

int
handle_GetTime(netsnmp_mib_handler *handler,
netsnmp_handler_registration *reginfo,
netsnmp_agent_request_info *reqinfo,
netsnmp_request_info *requests)
{ int ret;
int id = 219;
switch (reqinfo->mode) {

case MODE_GET:



    snmp_set_var_typed_value(requests->requestvb, ASN_INTEGER,(u_char *) &id
                             /* XXX: a pointer to the scalar's data */
                             , sizeof(id)
                             /*
                              * XXX: the length of the data in bytes 
                              */ );
    break;

   case MODE_SET_RESERVE1: 

        ret = netsnmp_check_vb_type(requests->requestvb, ASN_OCTET_STR);
        if ( ret != SNMP_ERR_NOERROR ) {
            netsnmp_set_request_error(reqinfo, requests, ret );
        }
        break;



    case MODE_SET_FREE:
        /* XXX: free resources allocated in RESERVE1 and/or
           RESERVE2.  Something failed somewhere, and the states
           below won't be called. */
        break;

  case MODE_SET_ACTION:

        id = *requests->requestvb->val.integer;

    break;
default:
    /*
     * we should never get here, so this is a really bad error 
     */
    snmp_log(LOG_ERR, "unknown mode (%d) in handle_GetTime\n",
             reqinfo->mode);
    return SNMP_ERR_GENERR;
}

return SNMP_ERR_NOERROR;

}

...麻煩各位幫我看一下了…萬分感謝~

  • 写回答

0条回答 默认 最新

    报告相同问题?

    悬赏问题

    • ¥15 maple软件,用solve求反函数出现rootof,怎么办?
    • ¥65 汇编语言除法溢出问题
    • ¥15 Visual Studio问题
    • ¥15 state显示变量是字符串形式,但是仍然红色,无法引用,并显示类型不匹配
    • ¥20 求一个html代码,有偿
    • ¥100 关于使用MATLAB中copularnd函数的问题
    • ¥20 在虚拟机的pycharm上
    • ¥15 jupyterthemes 设置完毕后没有效果
    • ¥15 matlab图像高斯低通滤波
    • ¥15 针对曲面部件的制孔路径规划,大家有什么思路吗