obtaining client ip address

th exterit <[email protected]>
Newsgroups gmane.network.net-snmp.user
Message-ID <[email protected]>
Apologies for this, but I truly mucked up the last thread when replying.
I'm trying to get the client ip address from a trap listener I wrote.

>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

------------------------------------------------------------------------------
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
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.