Re: obtaining ip address
th exterit <[email protected]>
| Newsgroups | gmane.network.net-snmp.user |
|---|---|
| Message-ID | <[email protected]> |
Thanks for the reply.
>From some digging about, it looks like I should be able to grab the ip from
"pdu->agent_addr" but I'm getting null when trying to print it out and
test. So that didn't work.
Then it looked like I may be able to get my hands on the sockaddr_in's by
doing (in the callback):
netsnmp_transport *t = (netsnmp_transport *)(session->callback_magic);
//callback_magic was given the transport variable earlier
netsnmp_udp_addr_pair *pp = (netsnmp_udp_addr_pair *)(t->data);
where netsnmp_udp_addr_pair is a struct:
typedef struct netsnmp_udp_addr_pair_s {
struct sockaddr_in remote_addr;
struct in_addr local_addr;
} netsnmp_udp_addr_pair;
However, this was returning NULL as well! i.e. t->data was null and
accordingly t->data_length is 0. Maybe I'm not setting up the
transport/session variables properly or something? Here's the gist of what
I have:
in main():
netsnmp_session *ss;
netsnmp_transport *transport;
transport = netsnmp_transport_open_server(
"snmptrap", "udp:162");
ss = snmptrapd_add_session(transport);
my snmptrapd_add_session() function:
static netsnmp_session *
snmptrapd_add_session(netsnmp_transport *t)
{
netsnmp_session sess, *session = &sess, *rc = NULL;
snmp_sess_init(session);
session->peername = SNMP_DEFAULT_PEERNAME; /* Original code had NULL
here */
session->version = SNMP_DEFAULT_VERSION;
session->community_len = SNMP_DEFAULT_COMMUNITY_LEN;
session->retries = SNMP_DEFAULT_RETRIES;
session->timeout = SNMP_DEFAULT_TIMEOUT;
session->callback = trap_handler_callback;
session->callback_magic = (void *) t; //this is where I give it the
transport variable
session->authenticator = NULL;
sess.isAuthoritative = SNMP_SESS_UNKNOWNAUTH;
rc = snmp_add(session, t, NULL, NULL);
if (rc == NULL) {
snmp_sess_perror("exteritytrapd", session);
}
return rc;
}
Can anyone see anything that I'm doing wrong?
Thanks,
Tom
On Wed, Feb 16, 2011 at 10:46 AM, Abraham Varricatt <
[email protected]> wrote:
> On Wed, Feb 16, 2011 at 2:29 PM, th exterit <[email protected]> wrote:
>
>> Unfortunately I do not have a choice. Also, we have a specific network
>> setup where traps are broadcast on the LAN by specific devices with a known
>> OID. I'm not sure I need worry about those cases you brought up but I could
>> be wrong. So there is definitely no way to grab the IP from the callback or
>> some such?
>>
>
> A creative (and un-tested) method, is to run multiple agents on different
> ports. If this is just a small LAN network with a handful of agents, you
> could simply have the different agents send the traps to different pots on
> the snmp-manager system. That way, depending on which port the request came
> in, you could isolate which agent sent the message.
>
> A possible limitation of this, is that we have no way of protecting the
> setup against spoofing. Also, I haven't had the need to work with snmp traps
> (yet), so take my advice with a grain of salt.
>
> -Abraham V.
>
------------------------------------------------------------------------------
The ultimate all-in-one performance toolkit: Intel(R) Parallel Studio XE:
Pinpoint memory and threading errors before they happen.
Find and fix more than 250 security defects in the development cycle.
Locate bottlenecks in serial and parallel code that limit performance.
http://p.sf.net/sfu/intel-dev2devfeb
_______________________________________________
Net-snmp-users mailing list
[email protected]
Please see the following page to unsubscribe or change other options:
https://lists.sourceforge.net/lists/listinfo/net-snmp-users