Jump to content
Sign in to follow this  
game-game

Nak Buat Snmp Programming

Recommended Posts

selamat pagi semua..

actually aku nk tanye, snmp ni dalam kategori ape dalam subtopic2 dalam ebooks? dalam network? aku tak jmpe kat ctu..

sape2 tau tak? bagi example paling ringkas pon takpe.. aku cme nak tngok ape command die je.. cam get request, trap ke..

thanks..

Share this post


Link to post
Share on other sites

thanks untuk info tu.. aku ade jmpe satu coding ni

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

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

#include <string.h>

int main(int argc, char ** argv)

{

struct snmp_session session;

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;

struct tree * mib_tree;

/*********************/

if(argv[1] == NULL){

printf("Please supply a hostname\n");

exit(1);

}

init_snmp("APC Check");

snmp_sess_init( &session );

session.version = SNMP_VERSION_1;

session.community = "public";

session.community_len = strlen(session.community);

session.peername = argv[1];

sess_handle = snmp_open(&session);

add_mibdir(".");

mib_tree = read_mib("PowerNet-MIB.txt");

pdu = snmp_pdu_create(SNMP_MSG_GET);

read_objid("PowerNet-MIB::upsBasicIdentModel.0", id_oid, &id_len);

snmp_add_null_var(pdu, id_oid, id_len);

read_objid("PowerNet-MIB::upsAdvIdentSerialNumber.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);

snmp_close(sess_handle);

return (0);

}

ble aku run,

gcc 'net-snmp-config --cflags' 'net-snmp-config --libs''net-snmp-config --external-libs' snmp_test.c -o snmp_test

die cakap,

gcc: net-snmp-config --cflags: No such file or directory

gcc: net-snmp-config --libsnet-snmp-config --external-libs: No such file or directory

snmp_test.c:1:38: error: net-snmp/net-snmp-config.h: No such file or directory

snmp_test.c:2:40: error: net-snmp/net-snmp-includes.h: No such file or directory

snmp_test.c: In function ‘main’:

snmp_test.c:6: error: storage size of ‘session’ isn’t known

snmp_test.c:11: error: ‘oid’ undeclared (first use in this function)

snmp_test.c:11: error: (Each undeclared identifier is reported only once

snmp_test.c:11: error: for each function it appears in.)

snmp_test.c:11: error: expected ‘;’ before ‘id_oid’

snmp_test.c:12: error: expected ‘;’ before ‘serial_oid’

snmp_test.c:13: error: ‘MAX_OID_LEN’ undeclared (first use in this function)

snmp_test.c:19: warning: incompatible implicit declaration of built-in function ‘printf’

snmp_test.c:20: warning: incompatible implicit declaration of built-in function ‘exit’

snmp_test.c:24: error: ‘SNMP_VERSION_1’ undeclared (first use in this function)

snmp_test.c:28: warning: assignment makes pointer from integer without a cast

snmp_test.c:30: warning: assignment makes pointer from integer without a cast

snmp_test.c:31: error: ‘SNMP_MSG_GET’ undeclared (first use in this function)

snmp_test.c:31: warning: assignment makes pointer from integer without a cast

snmp_test.c:32: error: ‘id_oid’ undeclared (first use in this function)

snmp_test.c:34: error: ‘serial_oid’ undeclared (first use in this function)

snmp_test.c:37: error: dereferencing pointer to incomplete type

snmp_test.c:37: error: dereferencing pointer to incomplete type

snmp_test.c:38: error: dereferencing pointer to incomplete type

snmp_test.c:38: error: dereferencing pointer to incomplete type

kenape ek? aku dah install net-snmp ni..

untuk mkluman korang, aku refer guide ni...The Cuddletech Guide to SNMP Programming

Share this post


Link to post
Share on other sites

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

Loading...
Sign in to follow this  

×
×
  • Create New...