当前位置: 首页>>代码示例>>C++>>正文


C++ snmp_free_pdu函数代码示例

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


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


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