I have a program that gets the list of interfaces, including virtual interfaces, in solaris machines(x86 & sparc).
I use the following codes to get it.
// create socket
int fd;
if ((fd = socket(PF_INET, SOCK_DGRAM, IPPROTO_IP)) < 0)
return 0;
// Get list of interfaces
struct ifconf Ifc;
struct ifreq IfcBuf[MAX_NUM_IFREQ];
struct ifreq* pIfr;
Ifc.ifc_len = sizeof(IfcBuf);
Ifc.ifc_buf = (char*) IfcBuf;
if (ioctl(fd, SIOCGIFCONF, &Ifc) < 0)
return 0;
// loop interfaces
int num_ifreq = Ifc.ifc_len / sizeof(struct ifreq);
int i;
for (pIfr = Ifc.ifc_req, i = 0; i < num_ifreq; pIfr++, i++)
{
// Request the address
if (ioctl(fd, SIOCGIFADDR, pIfr) < 0)
return 0;
// get interfaceName
char* interfaceName= (char*) lstrdup(pIfr->ifr_name);
...
}
In Solaris x86, the program works as expected. It can get all the interfaces including the virtual ones. However, in Solaris Sparc, the name of the virtual interface is incorrect.
For example, if I have the following interfaces (ifconfig -a): vxx1111111111:1 is a virtual interface of vxx1111111111.
lo0: flags=2001000849<UP,LOOPBACK,RUNNING,MULTICAST,IPv4,VIRTUAL> mtu 8232 index 1
inet 127.0.0.1 netmask ff000000
vxxx11111111111: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 2
inet 192.168.101.208 netmask ffffff00 broadcast 192.168.101.255
ether 1:1:11:11:11:11
vxxx11111111111:1: flags=1000843<UP,BROADCAST,RUNNING,MULTICAST,IPv4> mtu 1500 index 2
inet 192.168.101.220 netmask ffffff00 broadcast 192.168.101.255
The program's resulting interface names are: lo0, vxxx11111111111, vxxx11111111111. The third one should have been 'vxxx11111111111:1'
If I run the same code on a Solaris x86, I get the correct interface names for virtual interfaces.
Why can't I get the correct interface name for virtual interfaces on Solaris Sparc machines?