This is a discussion on how to get interface list using ioctl within the AIX Operating System forums, part of the Unix Operating Systems category; --> I have been trying to get all the interface list and ip addresses on my AIX box.....but it doesn't ...
| |||||||
| FAQ | Members List | Calendar | Search | Today's Posts | Mark Forums Read |
| ||||
| I have been trying to get all the interface list and ip addresses on my AIX box.....but it doesn't seem to work.......also I am unable to get the stateless ip addresses for IPV6 ....any help or suggestions how to do it........Below is my code....... #include <sys/types.h> #include <sys/socket.h> #include <sys/ioctl.h> #include <netdb.h> #include <netinet/in.h> #include <unistd.h> #include <net/if.h> #include <arpa/inet.h> #include <stdio.h> #include <string.h> #define num 5 int n; int main(){ int sd,err,ifsize; struct ifconf ifc; struct ifreq *ifr; struct ifreq ifreq; struct sockaddr_in *sa; char *cp,*i; sd=socket(AF_INET6,SOCK_STREAM,0); ifsize=num*sizeof(struct ifreq); ifc.ifc_buf=(char *)malloc(ifsize); ifc.ifc_len=ifsize; err=ioctl(sd, (int)SIOCGIFCONF, (caddr_t)&ifc); n=(ifc.ifc_len/sizeof(struct ifreq)); printf("Interfaces = %d\n",n); i=ifc.ifc_len+ifc.ifc_buf; for(cp=ifc.ifc_buf;cp<i;cp+=sizeof(ifr->ifr_name)+sizeof(ifr->ifr_addr)){ ifr=(struct ifreq *)cp; ifreq=*ifr; sa=(struct sockaddr_in *)&ifreq.ifr_addr; printf("interface name=%s %s\n",ifreq.ifr_name,inet_ntoa(sa->sin_addr)); ifc.ifc_req++; } close(sd); return 0; } Please let me know where i am making a mistake |