Hi Everyone,
How to use SIOCGIFCOUNT. I have tried using following code. I get error
saying that
SIOCGIFCOUNT(AF_INET): Invalid argument. I am interested to know when I
use SIOCGIFCOUNT, what parameters I nhave to pass.
#include <sys/socket.h>
#include <net/if.h>
#include <string.h>
#include <stdio.h>
#include <string.h>
#include <linux/sockios.h>
#include <netinet/in.h>
int main(void)
{
int s;
struct ifconf ifc;
struct ifreq ifr;
memset(&ifc, 0, sizeof(ifc));
memset(&ifr, 0, sizeof(ifr));
ifc.ifc_len = 0;
ifc.ifc_buf = NULL;
if ((s = socket(AF_INET, SOCK_DGRAM, 0)) < 0)
{
perror("socket(AF_INET)");
exit(-1);
}
if(ioctl(s, SIOCGIFCOUNT, &ifr) < 0)
{
perror("SIOCGIFCOUNT:");
exit(-1);
}
printf("Number of interfaces = %d\n",ifc.ifc_len/sizeof(struct
ifreq));
close(s);
}
Thank Yu,
Datha
|