pike.git / lib / modules / NetUtils.pmod

version» Context lines:

pike.git/lib/modules/NetUtils.pmod:90:      //! Returns the CIDR of a given netmask. Only returns the correct   //! value for netmasks with all-zeroes at the end (eg, 255.255.255.128   //! works, while 255.255.255.3 will give the wrong return value)   //!   //! @seealso   //! http://en.wikipedia.org/wiki/Classless_Inter-Domain_Routing#CIDR_notation   int netmask_to_cidr( string mask )   {    if( has_prefix( mask, "0x" ) ) -  { +  mask = mask[2..];    int i; -  if( sscanf( mask, "0x%x", i ) == 1 ) +  string s; +  if( sscanf( mask, "%x%s", i, s ) == 2 && s == "")    return i->popcount(); -  } +     return string_to_ip( mask )->popcount();   }      //! Converts a string with an IP address and mask (in CIDR notation)   //! into a binary IP address and bitmask.   //!   //! @param cidr   //! The CIDR-notation input string.   //! @returns   //! An array containing: