⭐ 欢迎来到虫虫下载站! | 📦 资源下载 📁 资源专辑 ℹ️ 关于我们
⭐ 虫虫下载站

📄 agent.xs

📁 snmp的源代码,已经在我的ubuntu下编译通过
💻 XS
📖 第 1 页 / 共 2 页
字号:
                snmp_log(LOG_ERR, "couldn't parse %s (reg name: %s)\n",                        regoid, name);                RETVAL = NULL;                gotit = 0;            }        }        if (gotit) {            cb_data = (handler_cb_data *) malloc(sizeof(handler_cb_data));            RETVAL = netsnmp_create_handler_registration(name, handler_wrapper,                                                 myoid, myoid_len,                                                 HANDLER_CAN_RWRITE);            cb_data->perl_cb = newSVsv(perlcallback);            RETVAL->handler->myvoid = cb_data;        }    OUTPUT:        RETVALMODULE = NetSNMP::agent  PACKAGE = netsnmp_handler_registrationPtr  PREFIX = nsahr_voidnsahr_DESTROY(reginfo)	netsnmp_handler_registration *reginfo    CODE:	netsnmp_handler_registration_free(reginfo);intnsahr_register(me)        SV *me;        PREINIT:        netsnmp_handler_registration *reginfo;        CODE:            {                reginfo = (netsnmp_handler_registration *) SvIV(SvRV(me));                RETVAL = netsnmp_register_handler(reginfo);                if (!RETVAL) {                    /* the agent now has a "reference" to this reg pointer */                    SvREFCNT_inc(me);                }            }    OUTPUT:	RETVALvoidnsahr_getRootOID(me)    SV *me;    PREINIT:        int i;        netsnmp_oid *o;        netsnmp_handler_registration *reginfo;        SV *arg, *rarg;    PPCODE:    {        dSP;        PUSHMARK(SP);        reginfo = (netsnmp_handler_registration *) SvIV(SvRV(me));        o = SNMP_MALLOC_TYPEDEF(netsnmp_oid);        o->name = o->namebuf;        o->len = reginfo->rootoid_len;        memcpy(o->name, reginfo->rootoid,               reginfo->rootoid_len * sizeof(oid));        rarg = newSViv((int) 0);        arg = newSVrv(rarg, "netsnmp_oidPtr");        sv_setiv(arg, (int) o);        XPUSHs(rarg);        PUTBACK;        i = perl_call_pv("NetSNMP::OID::newwithptr", G_SCALAR);        SPAGAIN;        if (i != 1) {            snmp_log(LOG_ERR, "unhandled OID error.\n");            /* ack XXX */        }        ST(0) = POPs;        XSRETURN(1);    }MODULE = NetSNMP::agent  PACKAGE = NetSNMP::agent::netsnmp_request_infoPtr PREFIX = nari_voidgetOID(me)    SV *me;    PREINIT:        int i;        netsnmp_oid *o;        netsnmp_request_info *request;        SV *arg, *rarg;    PPCODE:    {        dSP;        PUSHMARK(SP);        request = (netsnmp_request_info *) SvIV(SvRV(me));        o = SNMP_MALLOC_TYPEDEF(netsnmp_oid);        o->name = o->namebuf;        o->len = request->requestvb->name_length;        memcpy(o->name, request->requestvb->name,               request->requestvb->name_length * sizeof(oid));        rarg = newSViv((int) 0);        arg = newSVrv(rarg, "netsnmp_oidPtr");        sv_setiv(arg, (int) o);        XPUSHs(rarg);        PUTBACK;        i = perl_call_pv("NetSNMP::OID::newwithptr", G_SCALAR);        SPAGAIN;        if (i != 1) {            snmp_log(LOG_ERR, "unhandled OID error.\n");            /* ack XXX */        }        ST(0) = POPs;        XSRETURN(1);    }        netsnmp_oid *nari_getOIDptr(me)        SV *me;        PREINIT:        netsnmp_request_info *request;        CODE:        request = (netsnmp_request_info *) SvIV(SvRV(me));        RETVAL = SNMP_MALLOC_TYPEDEF(netsnmp_oid);        RETVAL->name = RETVAL->namebuf;        RETVAL->len = request->requestvb->name_length;        memcpy(RETVAL->name, request->requestvb->name,               request->requestvb->name_length * sizeof(oid));    OUTPUT:        RETVALchar *nari_getValue(me)        SV *me;    PREINIT:        u_char *oidbuf = NULL;        size_t ob_len = 0, oo_len = 0;        netsnmp_request_info *request;    CODE:        request = (netsnmp_request_info *) SvIV(SvRV(me));	sprint_realloc_by_type(&oidbuf, &ob_len, &oo_len, 1,                               request->requestvb, 0, 0, 0);        RETVAL = oidbuf; /* mem leak */    OUTPUT:        RETVALintnari_getDelegated(me)        SV *me;    PREINIT:        netsnmp_request_info *request;    CODE:        request = (netsnmp_request_info *) SvIV(SvRV(me));        RETVAL = request->delegated;    OUTPUT:        RETVALvoidnari_setDelegated(me, newdelegated)        SV *me;        int newdelegated;    PREINIT:        netsnmp_request_info *request;    CODE:        request = (netsnmp_request_info *) SvIV(SvRV(me));        request->delegated = newdelegated;intnari_getProcessed(me)        SV *me;    PREINIT:        netsnmp_request_info *request;    CODE:        request = (netsnmp_request_info *) SvIV(SvRV(me));        RETVAL = request->processed;    OUTPUT:        RETVALvoidnari_setProcessed(me, newprocessed)        SV *me;        int newprocessed;    PREINIT:        netsnmp_request_info *request;    CODE:        request = (netsnmp_request_info *) SvIV(SvRV(me));        request->processed = newprocessed;intnari_getStatus(me)        SV *me;    PREINIT:        netsnmp_request_info *request;    CODE:        request = (netsnmp_request_info *) SvIV(SvRV(me));        RETVAL = request->status;    OUTPUT:        RETVALvoidnari_setStatus(me, newstatus)        SV *me;        int newstatus;    PREINIT:        netsnmp_request_info *request;    CODE:        request = (netsnmp_request_info *) SvIV(SvRV(me));        request->status = newstatus;intnari_getRepeat(me)        SV *me;    PREINIT:        netsnmp_request_info *request;    CODE:        request = (netsnmp_request_info *) SvIV(SvRV(me));        RETVAL = request->repeat;    OUTPUT:        RETVALvoidnari_setRepeat(me, newrepeat)        SV *me;        int newrepeat;    PREINIT:        netsnmp_request_info *request;    CODE:        request = (netsnmp_request_info *) SvIV(SvRV(me));        request->repeat = newrepeat;intnari_setValue(me, type, value)        SV *me;        int type;        SV *value;    PREINIT:        u_char *oidbuf = NULL;        size_t ob_len = 0, oo_len = 0;        netsnmp_request_info *request;        u_long utmp;        long ltmp;	oid myoid[MAX_OID_LEN];	size_t myoid_len;        STRLEN stringlen;        char * stringptr;    CODE:        request = (netsnmp_request_info *) SvIV(SvRV(me));        switch(type) {          case ASN_INTEGER:	      /* We want an integer here */	      if ((SvTYPE(value) == SVt_IV) || (SvTYPE(value) == SVt_PVMG)) {		  /* Good - got a real one (or a blessed object that we hope will turn out OK) */		  ltmp = SvIV(value);		  snmp_set_var_typed_value(request->requestvb, (u_char)type,					   (u_char *) &ltmp, sizeof(ltmp));		  RETVAL = 1;		  break;	      }	      else if (SvPOKp(value)) {	          /* Might be OK - got a string, so try to convert it, allowing base 10, octal, and hex forms */	          stringptr = SvPV(value, stringlen);		  ltmp = strtol( stringptr, NULL, 0 );		  if (errno == EINVAL) {		  	snmp_log(LOG_ERR, "Could not convert string to number in setValue: '%s'", stringptr);			RETVAL = 0;			break;		  }		  snmp_set_var_typed_value(request->requestvb, (u_char)type,					   (u_char *) &ltmp, sizeof(ltmp));		  RETVAL = 1;		  break;	      }	      else {		snmp_log(LOG_ERR, "Non-integer value passed to setValue with ASN_INTEGER: type was %d\n",			SvTYPE(value));		RETVAL = 0;		break;	      }          case ASN_UNSIGNED:          case ASN_COUNTER:          case ASN_COUNTER64:          case ASN_TIMETICKS:	      /* We want an integer here */	      if ((SvTYPE(value) == SVt_IV) || (SvTYPE(value) == SVt_PVMG)) {		  /* Good - got a real one (or a blessed scalar which we have to hope will turn out OK) */		  utmp = SvIV(value);                  snmp_set_var_typed_value(request->requestvb, (u_char)type,                                       (u_char *) &utmp, sizeof(utmp));		  RETVAL = 1;		  break;	      }	      else if (SvPOKp(value)) {	          /* Might be OK - got a string, so try to convert it, allowing base 10, octal, and hex forms */	          stringptr = SvPV(value, stringlen);		  utmp = strtoul( stringptr, NULL, 0 );		  if (errno == EINVAL) {		  	snmp_log(LOG_ERR, "Could not convert string to number in setValue: '%s'", stringptr);			RETVAL = 0;			break;		  }                  snmp_set_var_typed_value(request->requestvb, (u_char)type,                                       (u_char *) &utmp, sizeof(utmp));		  RETVAL = 1;		  break;	      }	      else {		snmp_log(LOG_ERR, "Non-unsigned-integer value passed to setValue with ASN_UNSIGNED/ASN_COUNTER/ASN_TIMETICKS: type was %d\n",			SvTYPE(value));		RETVAL = 0;		break;	      }          case ASN_OCTET_STR:          case ASN_BIT_STR:	      /* Check that we have been passed something with a string value (or a blessed scalar) */	      if (!SvPOKp(value) && (SvTYPE(value) != SVt_PVMG)) {		snmp_log(LOG_ERR, "Non-string value passed to setValue with ASN_OCTET_STR/ASN_BIT_STR: type was %d\n",			SvTYPE(value));		RETVAL = 0;		break;	      }	      /* Find length of string (strlen will *not* do, as these are binary strings) */	      stringptr = SvPV(value, stringlen);              snmp_set_var_typed_value(request->requestvb, (u_char)type,                                       (u_char *) stringptr,                                       stringlen);              RETVAL = 1;              break;          case ASN_IPADDRESS:	      /* IP addresses are passed as *binary* strings.	       * In the case of IPv4 addresses, these are 4 bytes long.	       * NOTE: the use of binary strings rather than dotted-quad or FQDNs was	       * introduced here by Andrew Findlay's patch of March 17th 2003,	       * and is effectively a change to the previous implied API which assumed	       * the value was a (valid) hostname.	       * Responsibility for decoding and resolving has been passed up to the Perl script.	       */	      /* Check that we have been passed something with a string value (or a blessed scalar) */	      if (!SvPOKp(value) && (SvTYPE(value) != SVt_PVMG)) {		snmp_log(LOG_ERR, "Non-string value passed to setValue with ASN_IPADDRESS: type was %d\n",			SvTYPE(value));		RETVAL = 0;		break;	      }	      /* Find length of string (strlen will *not* do, as these are binary strings) */	      stringptr = SvPV(value, stringlen);	      # snmp_log(LOG_ERR, "IP address returned with length %d: %u.%u.%u.%u\n", stringlen, stringptr[0],	      #     stringptr[1], stringptr[2], stringptr[3] );	      # Sanity check on address length	      if ((stringlen != 4) && (stringlen != 16)) {	      		snmp_log(LOG_ERR, "IP address of %d bytes passed to setValue with ASN_IPADDRESS\n", stringlen);			RETVAL = 0;			break;	      }              snmp_set_var_typed_value(request->requestvb, (u_char)type,                                   stringptr, stringlen);              RETVAL = 1;              break;          case ASN_OBJECT_ID:	      /* Check that we have been passed something with a string value (or a blessed scalar) */	      if (!SvPOKp(value) && (SvTYPE(value) != SVt_PVMG)) {		snmp_log(LOG_ERR, "Non-string value passed to setValue with ASN_OBJECT_ID: type was %d\n",			SvTYPE(value));		RETVAL = 0;		break;	      }	      /* Extract the string */	      stringptr = SvPV(value, stringlen);	      /* snmp_log(LOG_ERR, "setValue returning OID '%s'\n", stringptr); */	      myoid_len = MAX_OID_LEN;              if (!snmp_parse_oid(stringptr, myoid, &myoid_len)) {                  snmp_log(LOG_ERR, "couldn't parse %s in setValue\n", stringptr);		  RETVAL = 0;		  break;              } else {		  /* snmp_log(LOG_ERR, "setValue returning OID length %d\n", myoid_len); */                  request = (netsnmp_request_info *) SvIV(SvRV(me));                  snmp_set_var_typed_value(request->requestvb, (u_char)type,                                           (u_char *) myoid, (myoid_len * sizeof(myoid[0])) );              }              RETVAL = 1;              break;                          default:                snmp_log(LOG_ERR, "unknown var value type: %d\n",                        type);                RETVAL = 0;                break;        }    OUTPUT:        RETVAL        voidnari_setOID(me, value)        SV *me;        char *value;    PREINIT:	oid myoid[MAX_OID_LEN];	size_t myoid_len = MAX_OID_LEN;        netsnmp_request_info *request;    CODE:	myoid_len = MAX_OID_LEN;	if (!snmp_parse_oid(value, myoid, &myoid_len)) {            snmp_log(LOG_ERR, "couldn't parse %s in setOID\n", value);        } else {            request = (netsnmp_request_info *) SvIV(SvRV(me));            snmp_set_var_objid(request->requestvb, myoid, myoid_len);        }voidnari_setError(me, rinfo, ecode)        SV *me;        SV *rinfo;        int ecode;    PREINIT:	oid myoid[MAX_OID_LEN];	size_t myoid_len = MAX_OID_LEN;        netsnmp_request_info *request;        netsnmp_agent_request_info *reqinfo;    CODE:        request = (netsnmp_request_info *) SvIV(SvRV(me));        reqinfo = (netsnmp_agent_request_info *) SvIV(SvRV(rinfo));        netsnmp_set_request_error(reqinfo, request, ecode);SV *nari_next(me)        SV *me;    PREINIT:        netsnmp_request_info *request;        SV *arg, *rarg;    CODE:        {            request = (netsnmp_request_info *) SvIV(SvRV(me));            if (request && request->next) {                request = request->next;                rarg = newSViv(0);                arg = newSVrv(rarg, "NetSNMP::agent::netsnmp_request_infoPtr");                sv_setiv(arg, (int) request);                ST(0) = rarg;            } else {                ST(0) = &sv_undef;            }        }MODULE = NetSNMP::agent  PACKAGE = NetSNMP::agent::netsnmp_agent_request_info PREFIX = narqi_intnarqi_getMode(me)        SV *me;    PREINIT:        netsnmp_agent_request_info *reqinfo;    CODE:        reqinfo = (netsnmp_agent_request_info *) SvIV(SvRV(me));        RETVAL = reqinfo->mode;    OUTPUT:        RETVALvoidnarqi_setMode(me, newvalue)        SV *me;        int newvalue;    PREINIT:        netsnmp_agent_request_info *reqinfo;    CODE:        reqinfo = (netsnmp_agent_request_info *) SvIV(SvRV(me));        reqinfo->mode = newvalue;        MODULE = NetSNMP::agent		PACKAGE = NetSNMP::agent		

⌨️ 快捷键说明

复制代码 Ctrl + C
搜索代码 Ctrl + F
全屏模式 F11
切换主题 Ctrl + Shift + D
显示快捷键 ?
增大字号 Ctrl + =
减小字号 Ctrl + -