Operating System - HP-UX
1831962 Members
3345 Online
110034 Solutions
New Discussion

How to determine number of interfaces on HPUX in IPv6

 
Manish_33
Advisor

How to determine number of interfaces on HPUX in IPv6

Hi friends,

I am having some problems determining the number of interfaces on my HPUX box with IPv6 configured.

Below is my code.

#include
#include
#include
extern int errno;
int main(){
int sd,n_ifs;
#ifdef A
sd=socket(AF_INET6,SOCK_DGRAM,0);
while (ioctl(sd, SIOCGLIFNUM, &n_ifs) < 0){
#else
sd=socket(AF_INET,SOCK_DGRAM,0);
while (ioctl(sd, SIOCGIFNUM, &n_ifs) < 0){
#endif
printf("errno = %d\n",errno);
perror("ioctl failed :");
if (errno != EINTR)
exit(-1);
break;
}
printf("socket descriptor = %d\n",sd);
printf("Retrieved # of interfaces=[%d]\n",n_ifs);
close(sd);
return 0;
}



Output from the above code is :

/home/katiyar> cc hello.c
/home/katiyar> ./a.out
socket descriptor = 3
Retrieved # of interfaces=[3]

/home/katiyar> cc -DA hello.c
/home/katiyar> ./a.out
socket descriptor = 3
Retrieved # of interfaces=[2]


As you can see the number of interfaces returned is different in both the cases. Shouldn't it be same ?? .

Also is there any way by which I can retrieve both the IPv4 and IPv6 addresses using a common data structure and the information of interfaces. Below is the information of my machine.

/# lanscan
Hardware Station Crd Hdw Net-Interface NM MAC HP-DLPI DLPI
Path Address In# State NamePPA ID Type Support Mjr#
10/0/12/0 0x0030D30128E0 0 UP lan0 snap0 1 ETHER Yes 119
/# ifconfig lan0
lan0: flags=843
inet 9.192.185.161 netmask fffffc00 broadcast 9.192.185.255
lan0: flags=4800841
inet6 fe80::230:d3ff:fe01:28e0 prefix 10
/# ifconfig lo0
lo0: flags=849
inet 127.0.0.1 netmask ff000000
lo0: flags=849
inet6 ::1 prefix 128
/#


Thanks in advance
6 REPLIES 6
rick jones
Honored Contributor

Re: How to determine number of interfaces on HPUX in IPv6

The don't necessarily need to be the same. Interface and NIC are not really interchangable terms even if they are often used that way.

Those are IIRC interfaces in the mind of network layer not necessarily in the mind of the data-link. There can be for example lan0:1, lan0:2 etc etc or even "tunnel" interfaces which would not appear in lanscan output.

There can be interfaces in lanscan which are not ifconfig'd for either IPv4 or IPv6.

To see what the actual differences are, you might expand your program to print a bit about each interface it finds, perhaps that wil
there is no rest for the wicked yet the virtuous have no pillows
Manish_33
Advisor

Re: How to determine number of interfaces on HPUX in IPv6

Thanks once again rick,

Basically what i am looking for is a way to get and print all the available IP's on the system through a common data structure.
rick jones
Honored Contributor

Re: How to determine number of interfaces on HPUX in IPv6

I think the two ioctls you have are the way to go. I do not believe there is "one call" you can make to get both IPv4 and IPv6 addresses.
there is no rest for the wicked yet the virtuous have no pillows
Manish_33
Advisor

Re: How to determine number of interfaces on HPUX in IPv6

That's a bad news :-( .....coz I have a working code for AIX where I am able to use struct ifconf along with ifreq, and able to extract all the available IP's on the system with a single ioctl call and I was expecting same for HPUX too.
rick jones
Honored Contributor

Re: How to determine number of interfaces on HPUX in IPv6

is it _really_ that big a deal? as you can see from you test case it isn't all that much more code
there is no rest for the wicked yet the virtuous have no pillows
Manish_33
Advisor

Re: How to determine number of interfaces on HPUX in IPv6

As such its not that big deal if you have to write a new application....but in my case since we are porting our existing application....I have some existing structures and would take considerable effort reqd.....that is why i was just trying to find out if there is any easy way to do it....