Hello,

I have a problem using snmpd from net-snmp 5.7.2 on HPUX (version 11.23 and 
11.31, IA version).


When using UDP, the daemon doesn't send back correctly the reply. There is a 
mistake in defining
the distant IP address : the snmpd daemon sends the replies to itself, the 
distant IP address is always replaced with a local one.

I have had a look at the code : the problem comes from a wrong use of the 
IP_RECVDSTADDR socket option.

Let me detail this :

Focussing on the send/receive functions using UDP protocol only (files  
snmpUDPBaseDomain.c, snmpUDPDomain.c and snmpUDPIPv4BaseDomain.c), i can 
summarize the ways used to send/receive packets to these lines :

     - the use of recvmsg() and sendmsg() with the socket option IP_RECVDSTADDR,
     - the use of recvmsg() and sendmsg() on linux with the socket option 
IP_PKTINFO,
     - for the others the use of recvfrom() and sendto() without any option.

By default, on HPUX we use the third one (the default "configure" settings).

The problem i described earlier is because the socket option IP_RECVDSTADDR is 
defined in the
system files (in /usr/include/netinet/in.h). So we are by default using the 
recvfrom()/sendto() with
the socket option IP_RECVDSTADDR. This last statment explains the problem i 
have. The code doesn't
handle this mix.

The solution i found was to "comment" the lines :

snmpUDPIPv4BaseDomain.c (line 132) :

    132  #elif defined(IP_RECVDSTADDR)
    133          { /*
    134              int sockopt = 1;
    135              if (setsockopt(t->sock, IPPROTO_IP, IP_RECVDSTADDR, 
&sockopt, sizeof sockopt) == -1) {
    136                  DEBUGMSGTL(("netsnmp_udp", "couldn't set 
IP_RECVDSTADDR: %s\n",
    137                              strerror(errno)));
    138                  netsnmp_transport_free(t);
    139                  return NULL;
    140              }
    141              DEBUGMSGTL(("netsnmp_udp", "set IP_RECVDSTADDR\n"));
    142        */  }
    143  #endif


Now, i want to do it more properly. The question are How and Where ?

The choices are for me :
     - add an #undef at the begining all three files or in the corresponding 
header files ?
     - change the "configure" step to handle this option,
     - change the code from " #elif defined(IP_RECVDSTADDR)" to the test done 
to enable the
        use of this option in the sendmsg()/recvmsg() :
                        #if defined(IP_RECVDSTADDR) && 
HAVE_STRUCT_MSGHDR_MSG_CONTROL \
                                 && HAVE_STRUCT_MSGHDR_MSG_FLAGS

Due to the many uses of this option in the source code, the best way for me is 
to "#undef" this
option globally for now. But the question stays : how ? I have tried the -U 
CFLAGS without any success. .... Any ideas ?


Thanks in advance.

Regards,
JPV


---
Ce courrier électronique ne contient aucun virus ou logiciel malveillant parce 
que la protection avast! Antivirus est active.
http://www.avast.com


------------------------------------------------------------------------------
November Webinars for C, C++, Fortran Developers
Accelerate application performance with scalable programming models. Explore
techniques for threading, error checking, porting, and tuning. Get the most 
from the latest Intel processors and coprocessors. See abstracts and register
http://pubads.g.doubleclick.net/gampad/clk?id=60136231&iu=/4140/ostg.clktrk
_______________________________________________
Net-snmp-coders mailing list
Net-snmp-coders@lists.sourceforge.net
https://lists.sourceforge.net/lists/listinfo/net-snmp-coders

Reply via email to