Re: Can we extract (agent)IP address for which get/set request is generated in table handler
parveen yadav <[email protected]>
| Newsgroups | gmane.network.net-snmp.user |
|---|---|
| Message-ID | <[email protected]> |
Fulko Hew wrote: > > > On Tue, May 12, 2009 at 9:03 AM, parveen yadav > <[email protected] <mailto:[email protected]>> wrote: > > Fulko Hew wrote: >> >> On Tue, May 12, 2009 at 2:23 AM, parveen yadav >> <[email protected] <mailto:[email protected]>> >> wrote: >> >> Fulko Hew wrote: >>> On Sat, May 9, 2009 at 5:18 AM, parveen yadav >>> <[email protected] >>> <mailto:[email protected]>> wrote: >>> >>> Wes Hardaker wrote: >>>>>>>>> On Tue, 05 May 2009 14:27:53 +0530, parveen yadav <[email protected]> <mailto:[email protected]> said: >>>>>>>>> >>>> py> I am trying to extract agent IP address for which get/set request is >>>> py> generated by snmpget in get_first_data_point,get_next_data_point and >>>> py> table handler. I am table iterator for my table. >>>> >>>> No, you can't. Though technically possible some of the time it's >>>> generally not something that you should be doing. SNMP wasn't designed >>>> to work that way, and although it's possible it breaks under some >>>> conditions. EG, if you ever want to run your code as an AgentX subagent >>>> that information isn't available at all. >>>> >>> But i think we can extract request ip in case net-snmp >>> is working as main agent and we do not need to handle >>> AgentX. But it is hard to find the storage location. I >>> have tried request structure. >>> Do i need to look some where else also?? >>> >>> >>> If I understand correctly, then this was something I needed >>> and I recently >>> added to the Perl interface for agents, its available in the >>> upcoming >>> release, but only for IPv4 based requests, and I don't think >>> it'll work >>> for AgentX based agents either. >> thanks for reply >> >> I have traced packet from snmp_read. But there is still >> confusion about Ipaddress of request. Can somebody clear the >> doubt. >> >> >> Can you be more specific? What are you confused about? >> What language are you using? >> >> If you are using Perl, your agent code would look something like >> this: >> >> if (!$agent) { >> print "The mandatory Perl agent is not defined in this >> Net-SNMP installation\n"; >> return; >> } >> $agent->register('myprog', '1.2.3.4', \&my_snmp_handler); >> >> sub my_snmp_handler { >> my ($handler, $registration_info, $request_info, $requests) = @_; >> >> my $targetIp = inet_ntoa($request_info->getTargetIp()); >> for (my $request = $requests; $request; $request = >> $request->next()) { >> handle_oid($targetIp, $request_info, $request); >> } >> } >> >> > I am using C language agent. There is netsnmp_request_info > structure in agent. In table handler , through requests list > handler finds the request to process. > But there is no method like getTargetIp(). It must be perl > specific and there must be some alternate. > I will try to explore this . This must be looking in request info > for Ip. > > > Correct. getTargetIp() is a function I added to the Perl binding to > NetSnmp. > Below is the C code (for that Perl binding) > I've highlighted the two relevant lines of code. > When I investigated the Net-SNMP C code, I found that the requestor's IP > address was in the reqinfo->asp->pdu->transport_data in the standard inet > structure form. Unfortunately this address in the trasnsport_data > structure > is the 'raw' address in whatever protocol it may have arrived in (IPv4 > IPv6, IPX etc.) > and the actual protocol type was lost (thrown away) at a higher level in > the calling stack. So all I could do for my Perl/C stuff was assume I > was receiving the request from an IPv4 address and look at it as such. > > To do it correctly would require a change to Net-SNMP so that the address > is correctly decoded and passed down in the reqinfo structure (where there > is already a place where it could reside). I was looking for a quick > and simple change that would meet my needs. > > If you want to see my full analysis, I documented it in my change request > to Net-SNMP for my Perl patch. Refer to this for that information: > > https://sourceforge.net/tracker/?func=detail&aid=2709705&group_id=12694&atid=312694 > <https://sourceforge.net/tracker/?func=detail&aid=2709705&group_id=12694&atid=312694> > > I hope this helps you! > Fulko > > > SV * > narqi_getTargetIp(me) > SV *me; > PREINIT: > netsnmp_agent_request_info *reqinfo; > struct netsnmp_udp_addr_pair_s *addr_pair; > struct in_addr *to; > SV *rarg; > > CODE: > reqinfo = (netsnmp_agent_request_info *) SvIV(SvRV(me)); > > addr_pair = (struct netsnmp_udp_addr_pair_s *) > (reqinfo->asp->pdu->transport_data); <----- > to = (struct in_addr *) > &(addr_pair->local_addr); <----- > rarg = newSVpv((unsigned char *)(&to->s_addr), > sizeof(to->s_addr)); > RETVAL = rarg; > OUTPUT: > RETVAL > thanks Using transport _data, I am able to extract source and destination IP in table handler. I tried to pass request info to to first and next data point using raw pointer myvoid in iinfo(iterator info). After dong that i am able to extract required info in these function also. I will test few more cases before updating net-snmp code. ------------------------------------------------------------------------------ The NEW KODAK i700 Series Scanners deliver under ANY circumstances! Your production scanning environment may not be a perfect world - but thanks to Kodak, there's a perfect scanner to get the job done! With the NEW KODAK i700 Series Scanner you'll get full speed at 300 dpi even with all image processing features enabled. http://p.sf.net/sfu/kodak-com _______________________________________________ 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