All pastes #57129 Raw Edit

Miscellany

public text v1 · immutable
#57129 ·published 2006-05-19 17:18 UTC
rendered paste body
#include <snmpkit>
#include <string>
#include <iostream>

static const char SYSDESC[]="1.3.6.1.2.1.1.1.0";

using std::cerr;
using std::cout;
using std::endl;
using std::flush;
using std::list;
using std::string;

struct HostInfo { char *sysDesc; };

void host_insert_sysdesc(void *dest_ptr, const char *str)
{
        HostInfo *dest = reinterpret_cast<HostInfo*>(dest_ptr);
        dest->sysDesc = strdup(str);
}

void *do_req(SNMP_session *sender)
{
        HostInfo hinfo;
        SNMP_structFiller table(*sender);
        table.append_string(SYSDESC, host_insert_sysdesc);
        try
        {
                table.get(&hinfo);
                cout << sender->Hostname() << ' ' << hinfo.sysDesc << endl;
        }
        catch (SNMPNoResponseException) {}
        return NULL;
}

int main(int argc, char **argv)
{
        set_snmpsock_props(5,1);
        list<SNMP_session*> sessions;
        string hosts(argv[1]);
        SNMP_sessions(sessions, hosts, do_req);
        SNMP_sessions_done();
        exit(1);
}