Branch: Tag:

2013-11-06

2013-11-06 16:27:32 by Henrik Grubbström (Grubba) <grubba@grubba.org>

NetUtils: Support Solaris 10 in netmask_to_cidr().

Solaris 10 has the netmask in hexadecimal without the 0x prefix. Eg:

lo0: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu 8232 index 1
inet 127.0.0.1 netmask ff000000

97:   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();   }