[Toybox] Fallen down the rathole of netstat cleanup.

Rob Landley rob at landley.net
Fri Jun 10 19:01:52 PDT 2016


Alice says hi.

Ok, in toys/pending/netstat.c we have:

/*
 * used to get the flag values for route command.
 */
static void get_flag_value(char *flagstr, int flags)
{
  int i = 0;
  char *str = flagstr;
  static const char flagchars[] = "GHRDMDAC";
  static const unsigned flagarray[] = {
    RTF_GATEWAY, RTF_HOST, RTF_REINSTATE, RTF_DYNAMIC, RTF_MODIFIED,
    RTF_DEFAULT, RTF_ADDRCONF, RTF_CACHE
  };
  *str++ = 'U';

  while ( (*str = flagchars[i]) ) {
    if (flags & flagarray[i++]) ++str;
  }
}

The above is only ever called once:

    //Get flag Values
    get_flag_value(flag_val, flags & IPV4_MASK);

And IPV4_MASK is:

  #define IPV4_MASK \
   (RTF_GATEWAY|RTF_HOST|RTF_REINSTATE|RTF_DYNAMIC|RTF_MODIFIED)

Translation: the RTF_DEFAULT, RTF_ADDRCONF,and RTF_CACHE in the above
flagarray[] are filtered out before the call, and thus the "DAC" at the
end of flagchars[] can never be set. (The D is redundant, but hey.)

If this is right, shouldn't the flagarray[] and flagchars[] just be
shorter, so we don't need to mask because we're testing fewer values? Or
is it wrong, and we shouldn't be masking?

Confused,

Rob



More information about the Toybox mailing list