if_freenameindex()--Free Dynamic Memory Allocated by if_nameindex()



  Syntax
  #include  <net/if.h>

  void if_freenameindex(struct if_nameindex *ptr);

  Service Program Name: QSOSRV2
  Default Public Authority: *USE
  Threadsafe: Yes

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.


Parameters

ptr  (Input) 
Array of if_nameindex structures. ptr MUST be a pointer that was returned by if_nameindex().

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 */
      };

Authorities

No authorization is required.


Return Value

None.


Error Conditions

errno can be set to:

[EFAULT]
The memory pointed to by ptr can not be accessed.

Related Information


Example

The following example shows how if_freenameindex() is used.

Note: By using the code examples, you agree to the terms of the Code license and disclaimer information.

#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;
  }

  ...

}


API introduced: V5R4

[ Back to top | UNIX-Type APIs | APIs by category ]