hi,
iam trying to get the network interface information and the default
information.After doing some googling i found out the relevant
structures and the ioctl calls for getting the interfaces information(
i suppose i have all that right).
struct ifconf(and using the ioctl SIOCGIFCONF).
there is another structure
struct ifreq
but i dont think i need that one.
Now how do i do to get the interface address(aliases also).i have
written a small program, but dont know where iam going wrong.the code
is
#include <stdio.h>
#include <stdlib.h>
#include <sys/ioctl.h>
#include <sys/types.h>
#include <net/if.h>
#include <netinet/in.h>
int
main(int argc, char* argv[])
{
struct ifconf ifc;
struct ifreq *ifr;
struct sockaddr_in *sin;
char buf[128];
if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0) {
perror("socket");
return 1;
}
ifc.ifc_buf = buf;
ifc.ifc_len = sizeof(buf);
if (ioctl(s, SIOCGIFCONF, &ifc) < 0) {
perror("ioctl SIOCGIFCONF");
return 1;
}
ifc.ifc_len /= sizeof(struct ifreq);
for (i=0; i<ifc.ifc_len; i++) {
ifr = (struct ifreq *) &ifc.ifc_req[i];
sin = (struct sockaddr_in *) &ifr->ifr_addr;
printf("%s \n",sin->sin_addr);
}
}
return 0;
And how can i get the default gateway address within my program.Quote:}
any help will be highly appreciated.
thanks
rohit