1 Sockets Library Functions                 if_nametoindex(3SOCKET)
   2 
   3 
   4 
   5 NAME
   6      if_nametoindex,        if_indextoname,         if_nameindex,
   7      if_freenameindex - routines to map Internet Protocol network
   8      interface names and interface indexes
   9 
  10 SYNOPSIS
  11      cc [ flag... ] file... -lsocket [ library... ]
  12      #include <net/if.h>
  13 
  14      unsigned int if_nametoindex(const char *ifname);
  15 
  16 
  17      char *if_indextoname(unsigned int ifindex, char *ifname);
  18 
  19 
  20      struct if_nameindex *if_nameindex(void)
  21 
  22 
  23      void if_freenameindex(struct if_nameindex *ptr);
  24 
  25 
  26 PARAMETERS
  27      ifname     interface name
  28 
  29 
  30      ifindex    interface index
  31 
  32 
  33      ptr        pointer returned by if_nameindex()
  34 
  35 
  36 DESCRIPTION
  37      This API defines two functions that map between an  Internet
  38      Protocol  network interface name and index, a third function
  39      that returns all the interface  names  and  indexes,  and  a
  40      fourth  function  to  return the dynamic memory allocated by
  41      the previous function.
  42 
  43 
  44      Network interfaces are normally known by names such as eri0,
  45      sl1,  ppp2, and the like.  The ifname argument must point to
  46      a buffer of at least IF_NAMESIZE bytes into which the inter-
  47      face  name corresponding to the specified index is returned.
  48      IF_NAMESIZE is defined in <net/if.h> and its value  includes
  49      a terminating null byte at the end of the interface name.
  50 
  51      if_nametoindex()      The if_nametoindex() function  returns
  52                            the  interface  index corresponding to
  53                            the interface name pointed to  by  the
  54                            ifname   pointer.   If  the  specified
  55                            interface name  does  not  exist,  the
  56                            return value is 0, and errno is set to
  57 
  58 
  59 
  60 SunOS 5.11          Last change: 12 Dec 2003                    1
  61 
  62 
  63 
  64 
  65 
  66 
  67 Sockets Library Functions                 if_nametoindex(3SOCKET)
  68 
  69 
  70 
  71                            ENXIO. If there was  a  system  error,
  72                            such  as  running  out  of memory, the
  73                            return value is 0 and errno is set  to
  74                            the proper value, for example, ENOMEM.
  75 
  76 
  77      if_indextoname()      The if_indextoname() function maps  an
  78                            interface index into its corresponding
  79                            name. This pointer is also the  return
  80                            value of the function.  If there is no
  81                            interface corresponding to the  speci-
  82                            fied  index,  NULL  is  returned,  and
  83                            errno is set to ENXIO, if there was  a
  84                            system  error,  such as running out of
  85                            memory, if_indextoname() returns  NULL
  86                            and  errno  would be set to the proper
  87                            value, for example, ENOMEM.
  88 
  89 
  90      *if_nameindex()       The if_nameindex() function returns an
  91                            array  of if_nameindex structures, one
  92                            structure    per    interface.     The
  93                            if_nameindex   structure   holds   the
  94                            information about a  single  interface
  95                            and  is  defined  when  the <net/if.h>
  96                            header is included:
  97 
  98                              struct if_nameindex
  99                                unsigned int   if_index; /* 1, 2, ... */
 100                                char          *if_name;  /* null terminated name: "eri0", ... */
 101                              };
 102 
 103                            The end of the array of structures  is
 104                            indicated   by  a  structure  with  an
 105                            if_index of 0 and an if_name of  NULL.
 106                            The  function  returns  a null pointer
 107                            upon an error and sets  errno  to  the
 108                            appropriate value. The memory used for
 109                            this array of  structures  along  with
 110                            the  interface names pointed to by the
 111                            if_name members  is  obtained  dynami-
 112                            cally.  This  memory  is  freed by the
 113                            if_freenameindex() function.
 114 
 115 
 116      if_freenameindex()    The if_freenameindex() function  frees
 117                            the  dynamic memory that was allocated
 118                            by  if_nameindex().  The  argument  to
 119                            this  function  must be a pointer that
 120                            was returned by if_nameindex().
 121 
 122 
 123 
 124 
 125 
 126 SunOS 5.11          Last change: 12 Dec 2003                    2
 127 
 128 
 129 
 130 
 131 
 132 
 133 Sockets Library Functions                 if_nametoindex(3SOCKET)
 134 
 135 
 136 
 137 ATTRIBUTES
 138      See attributes(5) for descriptions of the  following  attri-
 139      butes:
 140 
 141 
 142 
 143      ____________________________________________________________
 144     |       ATTRIBUTE TYPE        |       ATTRIBUTE VALUE       |
 145     |_____________________________|_____________________________|
 146     | Availability                | SUNWcsl (32-bit)            |
 147     |                             | SUNWcslx (64-bit)           |
 148     |_____________________________|_____________________________|
 149     | MT Level                    | MT Safe                     |
 150     |_____________________________|_____________________________|
 151 
 152 
 153 SEE ALSO
 154      ifconfig(1M), if_nametoindex(3XNET), attributes(5), if(7P)
 155 
 156 
 157 
 158 
 159 
 160 
 161 
 162 
 163 
 164 
 165 
 166 
 167 
 168 
 169 
 170 
 171 
 172 
 173 
 174 
 175 
 176 
 177 
 178 
 179 
 180 
 181 
 182 
 183 
 184 
 185 
 186 
 187 
 188 
 189 
 190 
 191 
 192 SunOS 5.11          Last change: 12 Dec 2003                    3
 193 
 194 
 195