if_enum_by_af bug

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index]

 



 Hi , I have found some bug in

      ip_helper_generic.c =>

----------------------------------------------------------------------------------------------------
#elif defined(SIOCGIFCONF) && \
      defined(PJ_HAS_NET_IF_H) && PJ_HAS_NET_IF_H != 0
/* Note: this does not work with IPv6 */
static pj_status_t if_enum_by_af(int af,unsigned *p_cnt,pj_sockaddr ifs[])
----------------------------------------------------------------------------------------------------------

In the for loop below this function , the

------------------------------------------------------------------------
if ((itf->ifr_flags & IFF_UP)==0) {
     TRACE_((THIS_FILE, "  interface is down"));
     continue; /* Skip when interface is down*/
 }

 if (itf->ifr_flags & IFF_LOOPBACK) {
     TRACE_((THIS_FILE, "  loopback interface"));
     continue; /* Skip loopback interface */
 }
-------------------------------------------------------------------------

will be always fail ( in my test ) !!

I have found the reason is  "ifr_addr" and "ifr_flags" are occupied the same
memory space
(union , refer below codes from <linux/if.h> ) !!

I modified two place by myself and hope have correct version by the original
authors !!

<1> Added
ioctl(sock, SIOCGIFFLAGS, &ifreq_temp) != 0
before check ifr_flags !!
ifreq_temp is local variable just for checking flags !!

<2>Modified
pj_sock_close(sock);
place to the end of this function
because <1> will use it !!

                                              Thanks for your pjsip !!
---------------------------------------------------------------------------------
struct ifreq
{
#define IFHWADDRLEN     6
#define IFNAMSIZ        16
        union
        {
                char    ifrn_name[IFNAMSIZ];            /* if name, e.g.
"en0" */
        } ifr_ifrn;
        union {
                struct  sockaddr ifru_addr;
                struct  sockaddr ifru_dstaddr;
                struct  sockaddr ifru_broadaddr;
                struct  sockaddr ifru_netmask;
                struct  sockaddr ifru_hwaddr;
                short   ifru_flags;
                int     ifru_ivalue;
                int     ifru_mtu;
                struct  ifmap ifru_map;
                char    ifru_slave[IFNAMSIZ];   /* Just fits the size */
                char    ifru_newname[IFNAMSIZ];
                char *  ifru_data;
                struct  if_settings ifru_settings;
        } ifr_ifru;
};
#define ifr_name        ifr_ifrn.ifrn_name      /* interface name       */
#define ifr_hwaddr      ifr_ifru.ifru_hwaddr    /* MAC address          */
#define ifr_addr        ifr_ifru.ifru_addr      /* address              */
#define ifr_dstaddr     ifr_ifru.ifru_dstaddr   /* other end of p-p lnk */
#define ifr_broadaddr   ifr_ifru.ifru_broadaddr /* broadcast address    */
#define ifr_netmask     ifr_ifru.ifru_netmask   /* interface net mask   */
#define ifr_flags       ifr_ifru.ifru_flags     /* flags                */
#define ifr_metric      ifr_ifru.ifru_ivalue    /* metric               */
#define ifr_mtu         ifr_ifru.ifru_mtu       /* mtu                  */
#define ifr_map         ifr_ifru.ifru_map       /* device map           */
#define ifr_slave       ifr_ifru.ifru_slave     /* slave device         */
#define ifr_data        ifr_ifru.ifru_data      /* for use by interface */
#define ifr_ifindex     ifr_ifru.ifru_ivalue    /* interface index      */
#define ifr_bandwidth   ifr_ifru.ifru_ivalue    /* link bandwidth       */
#define ifr_qlen        ifr_ifru.ifru_ivalue    /* Queue length         */
#define ifr_newname     ifr_ifru.ifru_newname   /* New name             */
#define ifr_settings    ifr_ifru.ifru_settings  /* Device/proto settings*/
---------------------------------------------------------------------------------------------------
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.pjsip.org/pipermail/pjsip_lists.pjsip.org/attachments/20081021/b4eb4174/attachment.html>


[Index of Archives]     [Asterisk Users]     [Asterisk App Development]     [Linux ARM Kernel]     [Linux ARM]     [Linux Omap]     [Fedora ARM]     [IETF Annouce]     [Security]     [Bugtraq]     [Linux]     [Linux OMAP]     [Linux MIPS]     [Linux API]
  Powered by Linux