Unix Technical Forum

how to get interface list using ioctl

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 ...


Go Back   Unix Technical Forum > Unix Operating Systems > AIX Operating System

FAQ Members List Calendar Search Today's Posts Mark Forums Read
  #1 (permalink)  
Old 01-05-2008, 11:21 AM
mkatiyar
 
Posts: n/a
Default how to get interface list using ioctl

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

Digg this Post!Add Post to del.icio.usBookmark Post in TechnoratiFurl this Post!
Reply With Quote
Reply


Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are On
Forum Jump


All times are GMT. The time now is 12:12 PM.


Powered by vBulletin® Version 3.6.5
Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
SEO by vBSEO 3.2.0
www.UnixAdminTalk.com