If someone knows why the following piece of code fails, please let me
know.
I a m trying to use ioctl call to obtain a ifconf structure.
#include <stdio.h>
#include <sys/types.h>
#include <fcntl.h>
#include <sys/ioctl.h>
#include <errno.h>
#include <sys/socket.h>
#include <net/if.h>
#include <sys/sockio.h>
main()
{
int ne;
struct ifconf *ifstat;
int code;
ne = open( "/dev/net/we0", O_RDONLY );
if (ne == -1)
{
printf("FATAL : Unable to open network device\n");
exit(-1);
}
ifstat = (struct ifconf *) malloc(sizeof(struct ifconf));
if (ifstat == NULL)
{
printf("FATAL : Unable to allocate memory (%d)\n",sizeof(struct
ifconf));
memset(ifstat,0,sizeof(struct ifconf));
ifstat->ifc_len = 100;
code = ioctl(ne,SIOCGIFCONF , &ifstat);
if (code == -1)
{
printf("FATAL : IOCTL failed (%d)\n",errno);
exit(-1);
}
exit(-1);Quote:}
}
ioctl fails with errno 22, I do not see why.
Anyone ?
here is the output :
FATAL : IOCTL failed (22)
If anyone can help, please drop me an e-mail
-mariusz