Start of changeif_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:

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

Related Information


Example

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

  ...

}
End of change

API introduced: V5R4
Top | UNIX-Type APIs | APIs by category