[AGENT++] AGENTPP Digest, Vol 140, Issue 6

Zhenyu Zhou zzy.cs.sxfs at gmail.com
Sun Oct 23 03:01:49 CEST 2016


Hi Jochen,

Thanks for your reply! Please find my response inline.



> Date: Fri, 21 Oct 2016 22:08:03 +0200
> From: Jochen Katz <katz at agentpp.com>
> To: agentpp at agentpp.org
> Subject: Re: [AGENT++] OID value as IP address
> Message-ID: <8a714157-befe-533f-2f12-0dd25c73f6bc at agentpp.com>
> Content-Type: text/plain; charset=utf-8
>
> Hi,
>
> > I'm using SNMP++ library to parse the packet I received (by `unload()` to
> > convert snmpmsg into pdu). However, I find when the OID value is IP
> > address, even if my packet is valid, I will only get a pdu without any
> > variable bindings.
>
> so you are receiving the SNMP message through your own socket and
> calling SnmpMessage::unload() to parse it?
>

Yes. I want to use SNMP++ for (de)serializing the SNMP msg.


>
> > I debugged it and found SNMP++ checks whether the IP address is valid by
> > `gethostbyname()`. But of course such behavior makes the address given by
> > the remote device invalid and not being put into my pdu. (For example,
> the
> > address I got is "10.0.0.1" and it is not valid on my host machine.)
>
> I don't see why this should happen. Can you send a stack trace so I can
> see from where the hostname lookup is triggered?
>

The call stacks when I'm debugging is like (the line number is on my
version, perhaps could be slightly different from yours):

snmpmsg.h:
int unload( Pdu &pdu,                    // Pdu returned
                    OctetStr &community,         // community name
                    snmp_version &version)       // version
->
snmpmsg.cpp:
int unload( Pdu &pdu,                    // Pdu returned
                    OctetStr &community,         // community name
                    snmp_version &version,       // version
                    OctetStr *engine_id,         // optional v3
                    OctetStr *security_name, // optional v3
                    long int *security_model,
   UdpAddress *from_addr,
                    Snmp *snmp_session);
->
snmpmsg.cpp (L767):
      IpAddress ipaddress(buffer);
->
address.cpp:

   IpAddress::IpAddress(const char *inaddr)

AND

(L261)    valid_flag = parse_address(inaddr);

// Here valid_flag will be false because the address is considered to be
invalid

->

address.cpp:

  bool IpAddress::parse_address(const char *inaddr)

AND

(L854) error = getaddrinfo(inaddr, 0, &hints, &res);

// This statement get an error code as -9, which means:

# define EAI_ADDRFAMILY  -9	/* Address family for NAME not supported.  */

I guess this is caused by my local machine is configured to only use IPv6
and the address I got is in IPv4 format.


After that, the vb is considered to be invalid (valid_flag is false).


Then the code comes to

snmpmsg.cpp (L814):

    // append the vb to the pdu

    pdu += tempvb;

->

pdu.cpp:

Pdu& Pdu::operator+=(const Vb &vb)

{

  if (!vb.valid())                return *this; // dont add invalid Vbs

->

vb.cpp:

bool Vb::valid() const

{

  if (iv_vb_oid.valid() &&

      ((iv_vb_value == NULL) || (iv_vb_value && *iv_vb_value->valid()*)))

    return true;

  return false;

}

// iv_vb_value's type is "class DLLOPT Address : public SnmpSyntax" here

->

address.h:

  virtual bool valid() const { return valid_flag; }


// Therefore nothing happens with `pdu += tempvb` and such tempvb is lost.

That's the whole process I observed.


Another interesting thing:

In address.cpp, only when the macro "#ifdef HAVE_GETADDRINFO (L843)" is
enabled can the statement "(L854) error = getaddrinfo(inaddr, 0, &hints,
&res);" take effect. But I have no idea why this marco is enabled here.
Otherwise, the address won't be parsed in this way.


Do you have any more insights?


Thanks!


>
> Regards,
>   Jochen
>
>
>


More information about the AGENTPP mailing list