0

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?

kuarissu
  • 15
  • 6
  • What versions of the OS? Post the output from `uname -a` on each machine. – Andrew Henle May 17 '17 at 10:09
  • OS versions: SunOS solaris-dev 5.10 Generic_142910-17 i86pc i386 i86pc, SunOS name1 5.10 Generic_Virtual sun4v sparc sun4v – kuarissu May 17 '17 at 10:41
  • i think i got it. My guess is that the interface name is too long... i'm still looking for the maximum length allowed by the system. This does not happen in Sunx86 because its interfaces have shorter names. – kuarissu May 17 '17 at 10:57

1 Answers1

0

The resulting virtual interface name is too long. according to this, the maximum length is 16 characters.

kuarissu
  • 15
  • 6