I used net-snmp-5.3.0.1, I also used
snmptrapd_add_session(netsnmp_transport *transport) to get the packet, and
in the function callback function --- snmp_input is used to process an
incoming trap through calling a new
function------trap_message_handler(netsnmp_pdu *, netsnmp_trapsport *,
netsnmp_trapd_handler *) which I add. The pdu is a struct netsnmp_pdu, and
unsigned char agent_addr[4] is the a item of the struct, I get the ip
through agent_addr as follow:
char *strIpAddress;
struct in_addr sInAddr = *(struct in_addr *)pdu->agent_addr;
strIpAddress = inet_ntoa(sInAddr);
printf("Agent address : %s\n", strIpAddress);
and the result is 0.0.0.0 as said in the previous letter.
I think the address I got is the agent address, why the result is 0.0.0.0,
Is it needed to set, how to set it?
Hi yao yu
To set the agent address, you need to change your agent .conf file (
snmpd.conf)
add this line (example):
agentaddress 10.10.10.10
restart your agent. Try again to get the agent address.
Note this only work to SNMPv1. Traps SNMPv2 and SNMPv3 will still get the
agent address with 0.0.0.0
you can see more configurations to net-snmp agent in this link:
http://www.net-snmp.org/docs/man/snmpd.conf.html
The second question is that how can I get the address of ip packets?
To get the address of ip packets you need to go a bit more deep into the
code (you need to get the ip address on the sockets!!)
Take a look in this function:
netsnmp_udp_recvfrom() (you can change udp for tcp, udp6, etc..)
This function is localized into /snmplib/snmpUDPDomain.c. (you can change
UDP for tcp, udp6, etc..)
In debug message you will find what are you looking for.......
--
Aluisio Leonello Victal
-------------------------------------------------------------------------
This SF.net email is sponsored by DB2 Express
Download DB2 Express C - the FREE version of DB2 express and take
control of your XML. No limits. Just data. Click to get it now.
http://sourceforge.net/powerbar/db2/
_______________________________________________
Net-snmp-coders mailing list
[email protected]
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders