if_freenameindex()--Free Dynamic Memory Allocated by if_nameindex()#include <net/if.h> void if_freenameindex(struct if_nameindex *ptr);Service Program Name: QSOSRV2
The if_freenameindex() function frees the dynamic memory that was allocated by if_nameindex(). After if_freenameindex() has been called, the application should not use the array of which ptr is the address.
The structure struct if_nameindex is defined in <net/if.h>.
struct if_nameindex
{
unsigned int if_index; /* 1, 2, ... */
char *if_name; /* null terminated name */
};
No authorization is required.
None.
errno can be set to:
See Code disclaimer information for information pertaining to code examples.
The following example shows how if_freenameindex() is used:
#include <net/if.h>
#include <sys/types.h>
#include <errno.h>
void main()
{
struct if_nameindex *interfaceArray = NULL;
interfaceArray = if_nameindex(void); /* retrieve the current interfaces */
if (interfaceArray != NULL)
{
...
if_freenameindex(interfaceArray); /* free the dynamic memory */
interfaceArray = NULL; /* prevent use after free */
}
else
{
printf("if_nameindex() failed with errno = %d %s \n",
errno,strerror(errno));
return;
}
...
}
| Top | UNIX-Type APIs | APIs by category |