While trying to get interface name using below code, returned pointer p is crashing. Can someone help?
char *p = NULL, buf[IFNAMSIZ]='';
int i = 0;
for(i=0; i<50; i++)
{
p = if_indextoname(i,buf);
if(p == NULL)
continue;
printf("p = %s",p);
}
Though pointer address is valid, unable to access its value.
I tried initialising the pointer and the buffer & added null check before printing pointer p. But it didn’t help
New contributor
Ganesan Sudalai is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.