• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

C++ snmp_free_pdu函数代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了C++中snmp_free_pdu函数的典型用法代码示例。如果您正苦于以下问题:C++ snmp_free_pdu函数的具体用法?C++ snmp_free_pdu怎么用?C++ snmp_free_pdu使用的例子?那么恭喜您, 这里精选的函数代码示例或许可以为您提供帮助。



在下文中一共展示了snmp_free_pdu函数的20个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的C++代码示例。

示例1: _clone_pdu_header

/*
 * Creates and allocates a clone of the input PDU,
 * but does NOT copy the variables.
 * This function should be used with another function,
 * such as _copy_pdu_vars.
 *
 * Returns a pointer to the cloned PDU if successful.
 * Returns 0 if failure.
 */
static
netsnmp_pdu    *
_clone_pdu_header(netsnmp_pdu *pdu)
{
    netsnmp_pdu    *newpdu;
    struct snmp_secmod_def *sptr;

    newpdu = (netsnmp_pdu *) malloc(sizeof(netsnmp_pdu));
    if (!newpdu)
        return 0;
    memmove(newpdu, pdu, sizeof(netsnmp_pdu));

    /*
     * reset copied pointers if copy fails 
     */
    newpdu->variables = 0;
    newpdu->enterprise = 0;
    newpdu->community = 0;
    newpdu->securityEngineID = 0;
    newpdu->securityName = 0;
    newpdu->contextEngineID = 0;
    newpdu->contextName = 0;
    newpdu->transport_data = 0;

    /*
     * copy buffers individually. If any copy fails, all are freed. 
     */
    if (snmp_clone_mem((void **) &newpdu->enterprise, pdu->enterprise,
                       sizeof(oid) * pdu->enterprise_length) ||
        snmp_clone_mem((void **) &newpdu->community, pdu->community,
                       pdu->community_len) ||
        snmp_clone_mem((void **) &newpdu->contextEngineID,
                       pdu->contextEngineID, pdu->contextEngineIDLen)
        || snmp_clone_mem((void **) &newpdu->securityEngineID,
                          pdu->securityEngineID, pdu->securityEngineIDLen)
        || snmp_clone_mem((void **) &newpdu->contextName, pdu->contextName,
                          pdu->contextNameLen)
        || snmp_clone_mem((void **) &newpdu->securityName,
                          pdu->securityName, pdu->securityNameLen)
        || snmp_clone_mem((void **) &newpdu->transport_data,
                          pdu->transport_data,
                          pdu->transport_data_length)) {
        snmp_free_pdu(newpdu);
        return 0;
    }
    if ((sptr = find_sec_mod(newpdu->securityModel)) != NULL &&
        sptr->pdu_clone != NULL) {
        /*
         * call security model if it needs to know about this 
         */
        (*sptr->pdu_clone) (pdu, newpdu);
    }

    return newpdu;
}
开发者ID:AllardJ,项目名称:Tomato,代码行数:64,代码来源:snmp_client.c


示例2: send_trap_to_sess

/*
 * send_trap_to_sess: sends a trap to a session but assumes that the
 * pdu is constructed correctly for the session type. 
 */
void
send_trap_to_sess(netsnmp_session * sess, netsnmp_pdu *template_pdu)
{
    netsnmp_pdu    *pdu;
    int            result;
    char           tmp[SPRINT_MAX_LEN];
    int            len;


    if (!sess || !template_pdu)
        return;

    DEBUGMSGTL(("trap", "sending trap type=%d, version=%d\n",
                template_pdu->command, sess->version));

#ifndef NETSNMP_DISABLE_SNMPV1
    if (sess->version == SNMP_VERSION_1 &&
        (template_pdu->command != SNMP_MSG_TRAP))
        return;                 /* Skip v1 sinks for v2 only traps */
    if (sess->version != SNMP_VERSION_1 &&
        (template_pdu->command == SNMP_MSG_TRAP))
        return;                 /* Skip v2+ sinks for v1 only traps */
#endif
    template_pdu->version = sess->version;
    pdu = snmp_clone_pdu(template_pdu);
    pdu->sessid = sess->sessid; /* AgentX only ? */

    if ( template_pdu->command == SNMP_MSG_INFORM
#ifdef USING_AGENTX_PROTOCOL_MODULE
         || template_pdu->command == AGENTX_MSG_NOTIFY
#endif
       ) {
        result =
            snmp_async_send(sess, pdu, &handle_inform_response, NULL);
        
    } else {
        if ((sess->version == SNMP_VERSION_3) &&
                (pdu->command == SNMP_MSG_TRAP2) &&
                (pdu->securityEngineIDLen == 0)) {
            len = snmpv3_get_engineID(tmp, sizeof(tmp));
            memdup(&pdu->securityEngineID, tmp, len);
            pdu->securityEngineIDLen = len;
        }

        result = snmp_send(sess, pdu);
    }

    if (result == 0) {
        snmp_sess_perror("snmpd: send_trap", sess);
        snmp_free_pdu(pdu);
    } else {
        snmp_increment_statistic(STAT_SNMPOUTTRAPS);
        snmp_increment_statistic(STAT_SNMPOUTPKTS);
    }
}
开发者ID:grantc,项目名称:ingres-snmp-agent,代码行数:59,代码来源:agent_trap.c


示例3: getCurrentMeasurement

/** Get current from power supply
*/
double getCurrentMeasurement(HSNMP m_sessp, int channel) {
  double value;

  struct snmp_pdu* pdu = snmp_pdu_create(SNMP_MSG_GET);    // prepare get-request pdu

  // for(each GET request to one crate) {
    snmp_add_null_var(pdu,oidOutputMeasurementCurrent[channel],lengthOutputMeasurementCurrent[channel]);   // generate request data
  // } // endfor

  struct snmp_pdu* response;
	int status = snmp_sess_synch_response(m_sessp,pdu,&response);


  /*
  * Process the response.
  */
  if (status == STAT_SUCCESS && response->errstat == SNMP_ERR_NOERROR) {
    /*
    * SUCCESS: Print the result variables
    */
    struct variable_list *vars;
    
    // debug print
    //for(vars = response->variables; vars; vars = vars->next_variable)
    //  print_variable(vars->name, vars->name_length, vars);

    /* manipuate the information ourselves */
    for(vars = response->variables; vars; vars = vars->next_variable) {
			if (vars->type == ASN_OPAQUE_FLOAT) {				    // 0x78
        value = *vars->val.floatVal;
      }
			else if (vars->type == ASN_OPAQUE_DOUBLE) {			// 0x79
        value = *vars->val.doubleVal;
      }
			else if(vars->type == ASN_INTEGER) {				      // 0x02
				value = (double)*vars->val.integer;
      }
    }
  } else {
    /*
    * FAILURE: print what went wrong!
    */

    if (status == STAT_SUCCESS)
      fprintf(stderr, "Error in packet\nReason: %s\n",
      snmp_errstring(response->errstat));
    else
      snmp_sess_perror("snmpget",snmp_sess_session(m_sessp));
    return 0;
  }
  snmp_free_pdu(response);


  return value;
}
开发者ID:BillMills,项目名称:GRIFFIN-SOH,代码行数:57,代码来源:WIENER_SNMP.cpp


示例4: handle_subagent_set_response

int
handle_subagent_set_response(int op, netsnmp_session * session, int reqid,
                             netsnmp_pdu *pdu, void *magic)
{
    netsnmp_session *retsess;
    struct agent_netsnmp_set_info *asi;

    if (op != NETSNMP_CALLBACK_OP_RECEIVED_MESSAGE || magic == NULL) {
        return 1;
    }

    DEBUGMSGTL(("agentx/subagent",
                "handling agentx subagent set response (mode=%d,req=0x%x,"
                "trans=0x%x,sess=0x%x)\n",
                pdu->command, pdu->reqid,pdu->transid, pdu->sessid));
    pdu = snmp_clone_pdu(pdu);

    asi = (struct agent_netsnmp_set_info *) magic;
    retsess = asi->sess;
    asi->errstat = pdu->errstat;

    if (asi->mode == SNMP_MSG_INTERNAL_SET_RESERVE1) {
        /*
         * reloop for RESERVE2 mode, an internal only agent mode 
         */
        /*
         * XXX: check exception statuses of reserve1 first 
         */
        if (!pdu->errstat) {
            asi->mode = pdu->command = SNMP_MSG_INTERNAL_SET_RESERVE2;
            snmp_async_send(agentx_callback_sess, pdu,
                            handle_subagent_set_response, asi);
            DEBUGMSGTL(("agentx/subagent",
                        "  going from RESERVE1 -> RESERVE2\n"));
            return 1;
        }
    } else {
        if (asi->mode == SNMP_MSG_INTERNAL_SET_FREE ||
            asi->mode == SNMP_MSG_INTERNAL_SET_UNDO ||
            asi->mode == SNMP_MSG_INTERNAL_SET_COMMIT) {
            free_set_vars(retsess, pdu);
        }
        pdu->variables = NULL;  /* the variables were added by us */
    }

    netsnmp_assert(retsess != NULL);
    pdu->command = AGENTX_MSG_RESPONSE;
    pdu->version = retsess->version;

    if (!snmp_send(retsess, pdu)) {
        snmp_free_pdu(pdu);
    }
    DEBUGMSGTL(("agentx/subagent", "  FINISHED\n"));
    return 1;
}
开发者ID:AllardJ,项目名称:Tomato,代码行数:55,代码来源:subagent.c


示例5: setOutputRampUp

/** Write RampUp to power supply
*/
double  setOutputRampUp(HSNMP m_sessp,int channel,double value) {
  struct snmp_pdu* pdu = snmp_pdu_create(SNMP_MSG_SET);    // prepare set-request pdu
  pdu->community = (u_char*)strdup(writeCommunity);
  pdu->community_len = strlen(writeCommunity);

  // for(each SET request to one crate) {
  float v = (float) value;
  snmp_pdu_add_variable(pdu,oidOutputRampUp[channel],lengthOutputRampUp[channel],ASN_OPAQUE_FLOAT,(u_char*)&v,sizeof(v));
  // } // endfor

  struct snmp_pdu* response;
	int status = snmp_sess_synch_response(m_sessp,pdu,&response);

  /*
  * Process the response.
  */
  if (status == STAT_SUCCESS && response->errstat == SNMP_ERR_NOERROR) {
    /*
    * SUCCESS: Print the result variables
    */
    struct variable_list *vars;
    
    // debug print
    //for(vars = response->variables; vars; vars = vars->next_variable)
    //  print_variable(vars->name, vars->name_length, vars);

    /* manipuate the information ourselves */
    for(vars = response->variables; vars; vars = vars->next_variable) {
			if (vars->type == ASN_OPAQUE_FLOAT) {				    // 0x78
        value = *vars->val.floatVal;
      }
			else if (vars->type == ASN_OPAQUE_DOUBLE) {			// 0x79
        value = *vars->val.doubleVal;
      }
			else if(vars->type == ASN_INTEGER) {				      // 0x02
				value = (double)*vars->val.integer;
      }
    }
  } else {
    /*
    * FAILURE: print what went wrong!
    */

    if (status == STAT_SUCCESS)
      fprintf(stderr, "Error in packet\nReason: %s\n",
      snmp_errstring(response->errstat));
    else
      snmp_sess_perror("snmpget",snmp_sess_session(m_sessp));
    return 0;
  }
  snmp_free_pdu(response);


  return value;
}
开发者ID:BillMills,项目名称:GRIFFIN-SOH,代码行数:57,代码来源:WIENER_SNMP.cpp


示例6: NotifyingEntry

static void
NotifyingEntry(UNUSED tState self)
{
    netsnmp_pdu* act = snmp_clone_pdu(pdu);
    if(act) {
        act->sessid = session;
        act->transid = 0;
        act->reqid = ++packetid;
        if(snmp_sess_send(sessp, act) == 0)
            snmp_free_pdu(act);
    }
}
开发者ID:nnathan,项目名称:net-snmp,代码行数:12,代码来源:agentxtrap.c


示例7: powernet_snmp_kill_ups_power

int powernet_snmp_kill_ups_power(UPSINFO *ups)
{
   /* Was 1} change submitted by Kastus Shchuka ([email protected]) 10Dec03 */
   oid upsBasicControlConserveBattery[] =
      { 1, 3, 6, 1, 4, 1, 318, 1, 1, 1, 6, 1, 1, 0 };
   struct snmp_ups_internal_data *Sid =
      (struct snmp_ups_internal_data *)ups->driver_internal_data;
   struct snmp_session *s = &Sid->session;
   struct snmp_session *peer;
   struct snmp_pdu *request, *response;
   int status;

   /*
    * Set up the SET request.
    */
   request = snmp_pdu_create(SNMP_MSG_SET);

   /*
    * Set upsBasicControlConserveBattery variable (INTEGER) to
    * turnOffUpsToConserveBattery(2) value. Will turn on the UPS only
    * when power returns.
    */
   if (snmp_add_var(request, upsBasicControlConserveBattery,
         sizeof(upsBasicControlConserveBattery) / sizeof(oid), 'i', "2")) {
      return 0;
   }

   peer = snmp_open(s);

   if (!peer) {
      Dmsg0(0, "Can not open the SNMP connection.\n");
      return 0;
   }

   status = snmp_synch_response(peer, request, &response);

   if (status != STAT_SUCCESS) {
      Dmsg0(0, "Unable to communicate with UPS.\n");
      return 0;
   }

   if (response->errstat != SNMP_ERR_NOERROR) {
      Dmsg1(0, "Unable to kill UPS power: can not set SNMP variable (%d).\n", response->errstat);
      return 0;
   }

   if (response)
      snmp_free_pdu(response);

   snmp_close(peer);

   return 1;
}
开发者ID:AllardJ,项目名称:Tomato,代码行数:53,代码来源:drv_powernet.c


示例8: snmp_pdu_create

QVariant QSnmp::get(const QString &oid) {
	struct snmp_pdu *pdu;
	struct snmp_pdu *response;
//	oid anOID[MAX_OID_LEN];
	u_long anOID[MAX_OID_LEN];
	size_t anOID_len = MAX_OID_LEN;
	int status;
	struct variable_list *vars;

	pdu = snmp_pdu_create(SNMP_MSG_GET);
	read_objid(oid.toUtf8().constData(), anOID, &anOID_len);
	snmp_add_null_var(pdu, anOID, anOID_len);
	status = snmp_synch_response(ss, pdu, &response);

	if (status != STAT_SUCCESS || response->errstat != SNMP_ERR_NOERROR) {
		qDebug("QSnmp: failed to get an oid");
		if (response) snmp_free_pdu(response);
		return QVariant();
	}

	for(vars = response->variables; vars; vars = vars->next_variable) {
		if (vars->type == ASN_OCTET_STR) {
			// string
			QByteArray res(vars->val_len, '\0');
			memcpy(res.data(), vars->val.string, vars->val_len);
			snmp_free_pdu(response);
			return res;
		}
		if (vars->type == ASN_INTEGER) {
			int res = (int)*vars->val.integer;
			snmp_free_pdu(response);
			return res;
		}
		print_variable(vars->name, vars->name_length, vars);
		qDebug("QSnmp: unknown var type %d", vars->type);
	}

	snmp_free_pdu(response);
	return QVariant();
}
开发者ID:MagicalTux,项目名称:door,代码行数:40,代码来源:QSnmp.cpp


示例9: ml

bool Session::getVariable(const QString &oid, QVariant &retvar, uint32_t &status)
{
	QMutexLocker ml(&m_mutex);
	struct snmp_pdu *response = NULL;
	if ( ! m_session )
	{
		status = 0xFFFFFFFF;
		return false;
	}
	
	// Buffer requestd for net-snmp library
	u_long anOID[MAX_OID_LEN];
	size_t anOID_len = MAX_OID_LEN;
	
	// Prepare the PDU for a GET command
	struct snmp_pdu *pdu = snmp_pdu_create(SNMP_MSG_GET);
	get_node(oid.latin1(), anOID, &anOID_len);
	snmp_add_null_var(pdu, anOID, anOID_len);
	
	status = snmp_synch_response(m_session, pdu, &response);
	
	//! @todo Error handling should be changed in a more OO way.
	if ( status != STAT_SUCCESS )
	{
		snmp_sess_perror("snmpget", m_session);
		return false;
	}
	
	if ( response->errstat != SNMP_ERR_NOERROR )
	{
		kdWarning() << "Error in packet: " << snmp_errstring(response->errstat) << endl;
		snmp_free_pdu(response);
		return false;
	}

	retvar = snmpvarToVariant(response->variables);
	snmp_free_pdu(response);
	
	return true;
}
开发者ID:Flameeyes,项目名称:libksnmp,代码行数:40,代码来源:session.cpp


示例10: collect

netsnmp_variable_list *
collect(netsnmp_session * ss, netsnmp_pdu *pdu,
        oid * base, size_t base_length)
{
    netsnmp_pdu    *response;
    int             running = 1;
    netsnmp_variable_list *saved = NULL, **vlpp = &saved;
    int             status;

    while (running) {
        /*
         * gotta catch em all, gotta catch em all! 
         */
        status = snmp_synch_response(ss, pdu, &response);
        if (status != STAT_SUCCESS || !response) {
            snmp_sess_perror("snmpdf", ss);
            exit(1);
        }
        if (response->errstat != SNMP_ERR_NOERROR) {
	    fprintf(stderr, "snmpdf: Error in packet: %s\n",
                    snmp_errstring(response->errstat));
            exit(1);
        }
        if (response && snmp_oid_compare(response->variables->name,
                                         SNMP_MIN(base_length,
                                                  response->variables->
                                                  name_length), base,
                                         base_length) != 0)
            running = 0;
        else {
            /*
             * get response 
             */
            *vlpp = response->variables;
            (*vlpp)->next_variable = NULL;      /* shouldn't be any, but just in case */

            /*
             * create the next request 
             */
            pdu = snmp_pdu_create(SNMP_MSG_GETNEXT);
            snmp_add_null_var(pdu, (*vlpp)->name, (*vlpp)->name_length);

            /*
             * finish loop setup 
             */
            vlpp = &((*vlpp)->next_variable);
            response->variables = NULL; /* ahh, forget about it */
        }
        snmp_free_pdu(response);
    }
    return saved;
}
开发者ID:ColdStart,项目名称:SNMPD,代码行数:52,代码来源:snmpdf.c


示例11: collect_mem

int collect_mem(netsnmp_session *ss, struct memStats *mem)
{
    netsnmp_pdu    *pdu;
    netsnmp_pdu    *response;
    int status;
    int ret = 0;

    pdu = snmp_pdu_create(SNMP_MSG_GET);
    add(pdu, "UCD-SNMP-MIB:memTotalSwap.0", NULL, 0);
    add(pdu, "UCD-SNMP-MIB:memAvailSwap.0", NULL, 0);
    add(pdu, "UCD-SNMP-MIB:memTotalReal.0", NULL, 0);
    add(pdu, "UCD-SNMP-MIB:memAvailReal.0", NULL, 0);
    add(pdu, "UCD-SNMP-MIB:memShared.0", NULL, 0);
    add(pdu, "UCD-SNMP-MIB:memBuffer.0", NULL, 0);
    add(pdu, "UCD-SNMP-MIB:memCached.0", NULL, 0);

    status = snmp_synch_response(ss, pdu, &response);
    memset(mem, 0, sizeof(*mem));
    if (status != STAT_SUCCESS || !response ||
            response->errstat != SNMP_ERR_NOERROR) {
        goto out;
    }
    else {
        netsnmp_variable_list *vlp = response->variables;
        if (vlp->type == SNMP_NOSUCHOBJECT) goto out;
        mem->totalSwap = *vlp->val.integer;
        vlp = vlp->next_variable;
        if (vlp->type == SNMP_NOSUCHOBJECT) goto out;
        mem->availSwap = *vlp->val.integer;
        vlp = vlp->next_variable;
        if (vlp->type == SNMP_NOSUCHOBJECT) goto out;
        mem->totalReal = *vlp->val.integer;
        vlp = vlp->next_variable;
        if (vlp->type == SNMP_NOSUCHOBJECT) goto out;
        mem->availReal = *vlp->val.integer;
        vlp = vlp->next_variable;

        ret = 1;

        if (vlp->type == SNMP_NOSUCHOBJECT) goto out;
        mem->shared = *vlp->val.integer;
        vlp = vlp->next_variable;
        if (vlp->type == SNMP_NOSUCHOBJECT) goto out;
        mem->buffer = *vlp->val.integer;
        vlp = vlp->next_variable;
        if (vlp->type == SNMP_NOSUCHOBJECT) goto out;
        mem->cached = *vlp->val.integer;
    }
out:
    if (response) snmp_free_pdu(response);
    return ret;
}
开发者ID:michalklempa,项目名称:net-snmp,代码行数:52,代码来源:snmpps.c


示例12: _copy_pdu_vars

/*
 * Copy some or all variables from source PDU to target PDU.
 * This function consolidates many of the needs of PDU variables:
 * Clone PDU : copy all the variables.
 * Split PDU : skip over some variables to copy other variables.
 * Fix PDU   : remove variable associated with error index.
 *
 * Designed to work with _clone_pdu_header.
 *
 * If drop_err is set, drop any variable associated with errindex.
 * If skip_count is set, skip the number of variable in pdu's list.
 * While copy_count is greater than zero, copy pdu variables to newpdu.
 *
 * If an error occurs, newpdu is freed and pointer is set to 0.
 *
 * Returns a pointer to the cloned PDU if successful.
 * Returns 0 if failure.
 */
static
netsnmp_pdu    *
_copy_pdu_vars(netsnmp_pdu *pdu,        /* source PDU */
               netsnmp_pdu *newpdu,     /* target PDU */
               int drop_err,    /* !=0 drop errored variable */
               int skip_count,  /* !=0 number of variables to skip */
               int copy_count)
{                               /* !=0 number of variables to copy */
    netsnmp_variable_list *var, *oldvar;
    int             ii, copied, drop_idx;

    if (!newpdu)
        return 0;               /* where is PDU to copy to ? */

    if (drop_err)
        drop_idx = pdu->errindex - skip_count;
    else
        drop_idx = 0;

    var = pdu->variables;
    while (var && (skip_count-- > 0))   /* skip over pdu variables */
        var = var->next_variable;

    oldvar = 0;
    ii = 0;
    copied = 0;
    if (pdu->flags & UCD_MSG_FLAG_FORCE_PDU_COPY)
        copied = 1;             /* We're interested in 'empty' responses too */

    newpdu->variables = _copy_varlist(var, drop_idx, copy_count);
    if (newpdu->variables)
        copied = 1;

#if ALSO_TEMPORARILY_DISABLED
    /*
     * Error if bad errindex or if target PDU has no variables copied 
     */
    if ((drop_err && (ii < pdu->errindex))
#if TEMPORARILY_DISABLED
        /*
         * SNMPv3 engineID probes are allowed to be empty.
         * See the comment in snmp_api.c for further details 
         */
        || copied == 0
#endif
        ) {
        snmp_free_pdu(newpdu);
        return 0;
    }
#endif
    return newpdu;
}
开发者ID:AllardJ,项目名称:Tomato,代码行数:70,代码来源:snmp_client.c


示例13: agentx_unregister

int
agentx_unregister( struct snmp_session *ss, oid start[], size_t startlen,
                   int priority, int range_subid, oid range_ubound)
{
    struct snmp_pdu *pdu, *response;

    if (! IS_AGENTX_VERSION( ss->version ))
        return 0;

    DEBUGMSGTL(("agentx/subagent","unregistering: "));
    DEBUGMSGOID(("agentx/subagent", start, startlen));
    DEBUGMSG(("agentx/subagent","\n"));
    pdu = snmp_pdu_create(AGENTX_MSG_UNREGISTER);
    if ( pdu == NULL )
        return 0;
    pdu->time = 0;
    pdu->priority = priority;
    pdu->sessid = ss->sessid;
    pdu->range_subid = range_subid;
    if ( range_subid ) {
        snmp_pdu_add_variable( pdu, start, startlen,
                               ASN_OBJECT_ID, (u_char *)start, startlen);
        pdu->variables->val.objid[ range_subid-1 ] = range_ubound;
    }
    else
        snmp_add_null_var( pdu, start, startlen);

    if ( agentx_synch_response(ss, pdu, &response) != STAT_SUCCESS )
        return 0;

    if ( response->errstat != SNMP_ERR_NOERROR ) {
        snmp_free_pdu(response);
        return 0;
    }

    snmp_free_pdu(response);
    DEBUGMSGTL(("agentx/subagent","unregistered\n"));
    return 1;
}
开发者ID:BackupTheBerlios,项目名称:wl530g-svn,代码行数:39,代码来源:client.c


示例14: pdu_create_opt_context

static netsnmp_pdu*
pdu_create_opt_context(int command, const char* context, size_t len)
{
    netsnmp_pdu* res = snmp_pdu_create(command);
    if (res)
        if (context) {
            if (snmp_clone_mem((void**)&res->contextName, context, len)) {
                snmp_free_pdu(res);
                res = NULL;
            } else
                res->contextNameLen = len;
        }
    return res;
}
开发者ID:nnathan,项目名称:net-snmp,代码行数:14,代码来源:agentxtrap.c


示例15: send_pdu

static int send_pdu(netsnmp_session *ss, netsnmp_pdu *pdu, int kind, int link_id)
{
	int status;
	netsnmp_callback cb;

	cb = kind == SNMP_LINK_UP ? link_up_cb : link_down_cb;

	status = snmp_async_send(ss, pdu, cb, (void *) link_id);
	if (status == 0) {
		snmp_log(LOG_ERR, "Failed to send async request.\n");
		snmp_free_pdu(pdu);
	}

	return status;
}
开发者ID:FreeRADIUS,项目名称:freeradius-server,代码行数:15,代码来源:snmp_mtp.c


示例16: ClosingEntry

static void
ClosingEntry(UNUSED tState self)
{
    /* CLOSE pdu->errstat */
    netsnmp_pdu* act =
        pdu_create_opt_context(AGENTX_MSG_CLOSE, context, contextLen);
    if(act) {
        act->sessid = session;
        act->transid = 0;
        act->reqid = ++packetid;
        act->errstat = AGENTX_CLOSE_SHUTDOWN;
        if(snmp_sess_send(sessp, act) == 0)
            snmp_free_pdu(act);
    }
}
开发者ID:nnathan,项目名称:net-snmp,代码行数:15,代码来源:agentxtrap.c


示例17: OpeningEntry

static void
OpeningEntry(UNUSED tState self)
{
    netsnmp_pdu* act =
        pdu_create_opt_context(AGENTX_MSG_OPEN, context, contextLen);
    if(act) {
        act->sessid = 0;
        act->transid = 0;
        act->reqid = ++packetid;
        act->time = 0;
        snmp_pdu_add_variable(act, NULL, 0, ASN_OCTET_STR, NULL, 0);
        if(snmp_sess_send(sessp, act) == 0)
            snmp_free_pdu(act);
    }
}
开发者ID:nnathan,项目名称:net-snmp,代码行数:15,代码来源:agentxtrap.c


示例18: send_agentx_error

static void send_agentx_error (netsnmp_session * session, netsnmp_pdu * pdu, int errstat, int errindex)
{
    pdu = snmp_clone_pdu (pdu);
    pdu->command = AGENTX_MSG_RESPONSE;
    pdu->version = session->version;
    pdu->errstat = errstat;
    pdu->errindex = errindex;
    snmp_free_varbind (pdu->variables);
    pdu->variables = NULL;

    DEBUGMSGTL (("agentx/subagent", "Sending AgentX response error stat %d idx %d\n", errstat, errindex));
    if (!snmp_send (session, pdu))
    {
        snmp_free_pdu (pdu);
    }
}
开发者ID:274914765,项目名称:C,代码行数:16,代码来源:subagent.c


示例19: asynch_response

/*
 * response handler
 */
int asynch_response(int operation, struct snmp_session *sp, int reqid,
		    struct snmp_pdu *pdu, void *magic)
{
	struct session *host = (struct session *)magic;
	struct snmp_pdu *req;
	struct oid *op;

	if (operation == NETSNMP_CALLBACK_OP_RECEIVED_MESSAGE) {
		if (print_result(STAT_SUCCESS, host->sess, pdu)) {
/*			host->current_oid++;			*/ /* send next GET (if any) */
			op = host->current_oid;
			op++;
			while(op->hostname)
			{
/*				printf("[%s] [%s]\n",op->hostname, host->current_oid->hostname); */
				if(strcmp(op->hostname,host->current_oid->hostname)==0) {
					host->current_oid = op;
					break;
				}
				op++;
			}

			if (op->hostname && host->current_oid->Name) {
				req = snmp_pdu_create(SNMP_MSG_GET);
				snmp_add_null_var(req, host->current_oid->Oid, host->current_oid->OidLen);
				if (snmp_send(host->sess, req))
					return 1;
				else {
					snmp_perror("snmp_send");
					snmp_free_pdu(req);
				}
			}
			else
			{
/*				printf("No more OIDs for [%s]\n", host->current_oid->hostname); */
			}
		}
	}
	else
		print_result(STAT_TIMEOUT, host->sess, pdu);

/* something went wrong (or end of variables) 
* this host not active any more
*/
	active_hosts--;
	return 1;
}
开发者ID:Shmuma,项目名称:z,代码行数:50,代码来源:snmp.c


示例20: snmp_synch_response

char *session_query(struct snmp_session *ss, struct snmp_pdu *pdu) {

  struct snmp_pdu *response;
  struct variable_list *vars;
  int status;
  char buf[SPRINT_MAX_LEN];
  char *rbuffer=NULL;
    
  /* Send the Request */
  status = snmp_synch_response(ss, pdu, &response);

  /* Process the response */
  if (status == STAT_SUCCESS && response->errstat == SNMP_ERR_NOERROR )
 {
    /* Success: Print the results */
    /* for (vars=response->variables; vars; vars=vars->next_variable) { */
    vars=response->variables;
    
    if (vars!=NULL && vars->type <ASN_LONG_LEN) {
      if (vars->type == ASN_INTEGER) {
         sprintf(buf,"%ld",*vars->val.integer);
		 rbuffer=malloc(sizeof(char)*(strlen(buf)+1));
     	 memset(rbuffer,'\0',strlen(buf)+1);
         strncpy(rbuffer,buf,strlen(buf));
      } else {
         snprint_variable(buf, sizeof (buf), vars->name, vars->name_length, vars);
         rbuffer=malloc(sizeof(char)*(strlen(buf)+1));
     	 memset(rbuffer,'\0',strlen(buf)+1);
         strncpy(rbuffer,buf,strlen(buf));
	  }
    } else rbuffer = NULL;     

  } else {
    /* Failure: print what went wrong */
    if (status == STAT_SUCCESS)
      fprintf(stderr,"Error in packet.\nReason: %s\n", snmp_errstring(response->errstat));
    else
      snmp_sess_perror("snmpget ", ss);
  }

  /* Clean up */
  if (response) snmp_free_pdu(response);

//  printf("Result : %s\n",rbuffer);
  return rbuffer;
}
开发者ID:Ancient,项目名称:NetGuard,代码行数:46,代码来源:snmp_layer.c



注:本文中的snmp_free_pdu函数示例由纯净天空整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
C++ snmp_get_sysuptime函数代码示例发布时间:2022-05-30
下一篇:
C++ snmp_fold_field函数代码示例发布时间:2022-05-30
热门推荐
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap