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;  /* "net0", ... */
 101                              };
 102 
 103                            While   any   IPMP IP  interfaces  are
 104                            returned  by    *if_nameindex()*,  the
 105                            underlying IP interfaces that comprise
 106                            each IPMP group are not returned.
 107 
 108                            The end of the array of structures  is
 109                            indicated   by  a  structure  with  an
 110                            if_index of 0 and an if_name of  NULL.
 111                            The  function  returns  a null pointer
 112                            upon an error and sets  errno  to  the
 113                            appropriate value. The memory used for
 114                            this array of  structures  along  with
 115                            the  interface names pointed to by the
 116                            if_name members  is  obtained  dynami-
 117                            cally.  This  memory  is  freed by the
 118                            if_freenameindex() function.
 119 
 120 
 121      if_freenameindex()    The if_freenameindex() function  frees
 122                            the  dynamic memory that was allocated
 123                            by  if_nameindex().  The  argument  to
 124                            this  function  must be a pointer that
 125                            was returned by if_nameindex().
 126 
 127 
 128 
 129 
 130 
 131 SunOS 5.11          Last change: 12 Dec 2003                    2
 132 
 133 
 134 
 135 
 136 
 137 
 138 Sockets Library Functions                 if_nametoindex(3SOCKET)
 139 
 140 
 141 
 142 ATTRIBUTES
 143      See attributes(5) for descriptions of the  following  attri-
 144      butes:
 145 
 146 
 147 
 148      ____________________________________________________________
 149     |       ATTRIBUTE TYPE        |       ATTRIBUTE VALUE       |
 150     |_____________________________|_____________________________|
 151     | Availability                | SUNWcsl (32-bit)            |
 152     |                             | SUNWcslx (64-bit)           |
 153     |_____________________________|_____________________________|
 154     | MT Level                    | MT Safe                     |
 155     |_____________________________|_____________________________|
 156 
 157 
 158 SEE ALSO
 159      ifconfig(1M), if_nametoindex(3XNET), attributes(5), if(7P)
 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 
 193 
 194 
 195 
 196 
 197 SunOS 5.11          Last change: 12 Dec 2003                    3
 198 
 199 
 200