Search code examples
csnmpnet-snmp

snmpbulkwalk in c


is it possible to create an snmpbulkwalk in C with netsnmp?

A snmpget is quite easy - but I cannot find an example to send an snmpbulkwalk...

Here is a little example for an snmpget:

    #include <net-snmp/net-snmp-config.h>
    #include <net-snmp/net-snmp-includes.h>
    #include <string.h>

    int snmp_get(struct snmp_session *sess_handle){
            struct snmp_pdu *pdu;
            struct snmp_pdu *response;
            struct variable_list *vars;

            oid id_oid[MAX_OID_LEN];
            oid serial_oid[MAX_OID_LEN];
            size_t id_len = MAX_OID_LEN;
            size_t serial_len = MAX_OID_LEN;
            int status;

            pdu = snmp_pdu_create(SNMP_MSG_GET);
            read_objid("SNMPv2-MIB::sysName.0", id_oid, &id_len);
            snmp_add_null_var(pdu, id_oid, id_len);
            read_objid(".1.3.6.1.2.1.1.3.0", serial_oid, &serial_len);
            snmp_add_null_var(pdu, serial_oid, serial_len);

            status = snmp_synch_response(sess_handle, pdu, &response);

            for(vars = response->variables; vars; vars = vars->next_variable)
                    print_value(vars->name, vars->name_length, vars);

            snmp_free_pdu(response);

            return status;


    }

    struct snmp_session *setup_snmp_session(int version, char* community, char* host){

                    struct snmp_session session;
                    struct snmp_session *sess_handle;

                    init_snmp("poller");
                    snmp_sess_init( &session );
                    session.version = version;
                    session.community = community;
                    session.community_len = strlen(session.community);
                    session.peername = host;
                    sess_handle = snmp_open(&session);
                    return sess_handle;

    }

    int main(int argc, char ** argv)
    {
            if(argv[1] == NULL){
            printf("Please supply a hostname\n");
            exit(1);
            }
struct snmp_session   *sess_handle=setup_snmp_session(SNMP_VERSION_2c,"asdf",argv[1]);
snmp_get(sess_handle);
snmp_close(sess_handle);

        return (0);
}

I am looking for something equal - just doing an snmpbulkwalk! Thx for your help!

br, roegi


Solution

  • Are you aware that there is already a snmpbulkwalk command line implementation within Net-SNMP that would be a good example to look at? It does what you want already. If you want a single instance of a GETBULK, then you could look at the simpler snmpbulkget example instead.