1if_nametoindex(3SOCKET)    Sockets Library Functions   if_nametoindex(3SOCKET)
2
3
4

NAME

6       if_nametoindex,  if_indextoname,  if_nameindex, if_freenameindex - rou‐
7       tines to map Internet Protocol network interface  names  and  interface
8       indexes
9

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

PARAMETERS

27       ifname     interface name
28
29
30       ifindex    interface index
31
32
33       ptr        pointer returned by if_nameindex()
34
35

DESCRIPTION

37       This  API  defines  two functions that map between an Internet Protocol
38       network interface name and index, a third function that returns all the
39       interface  names  and  indexes,  and  a  fourth  function to return the
40       dynamic memory allocated by the previous function.
41
42
43       Network interfaces are normally known by names such as eri0, sl1, ppp2,
44       and  the  like.  The ifname argument must point to a buffer of at least
45       IF_NAMESIZE bytes into which the interface name  corresponding  to  the
46       specified  index  is returned. IF_NAMESIZE is defined in <net/if.h> and
47       its value includes a terminating null byte at the end of the  interface
48       name.
49
50       if_nametoindex()      The  if_nametoindex() function returns the inter‐
51                             face index corresponding to  the  interface  name
52                             pointed  to  by the ifname pointer. If the speci‐
53                             fied interface name does not  exist,  the  return
54                             value  is  0, and errno is set to ENXIO. If there
55                             was a system error, such as running out  of  mem‐
56                             ory,  the  return  value is 0 and errno is set to
57                             the proper value, for example, ENOMEM.
58
59
60       if_indextoname()      The if_indextoname() function maps  an  interface
61                             index  into  its corresponding name. This pointer
62                             is also the return  value  of  the  function.  If
63                             there is no interface corresponding to the speci‐
64                             fied index, NULL is returned, and errno is set to
65                             ENXIO,  if there was a system error, such as run‐
66                             ning out of memory, if_indextoname() returns NULL
67                             and  errno  would be set to the proper value, for
68                             example, ENOMEM.
69
70
71       if_nameindex()        The if_nameindex() function returns an  array  of
72                             if_nameindex structures, one structure per inter‐
73                             face. The if_nameindex structure holds the infor‐
74                             mation  about  a  single interface and is defined
75                             when the <net/if.h> header is included:
76
77                               struct if_nameindex
78                                  unsigned int   if_index; /* 1, 2, ... */
79                                  char          *if_name;  /* "net0", ... */
80                               };
81
82                             While any IPMP  IP  interfaces  are  returned  by
83                             if_nameindex(), the underlying IP interfaces that
84                             comprise each IPMP group are not returned.
85
86                             The end of the array of structures  is  indicated
87                             by  a  structure  with  an  if_index  of 0 and an
88                             if_name of NULL.  The  function  returns  a  null
89                             pointer  upon  an  error  and  sets  errno to the
90                             appropriate value. The memory used for this array
91                             of  structures  along  with  the  interface names
92                             pointed to by the  if_name  members  is  obtained
93                             dynamically.   This   memory   is  freed  by  the
94                             if_freenameindex() function.
95
96
97       if_freenameindex()    The if_freenameindex() function frees the dynamic
98                             memory  that was allocated by if_nameindex(). The
99                             argument to this function must be a pointer  that
100                             was returned by if_nameindex().
101
102

ATTRIBUTES

104       See attributes(5) for descriptions of the following attributes:
105
106
107
108
109       ┌─────────────────────────────┬─────────────────────────────┐
110       │      ATTRIBUTE TYPE         │      ATTRIBUTE VALUE        │
111       ├─────────────────────────────┼─────────────────────────────┤
112       │Availability                 │SUNWcsl (32-bit)             │
113       │                             │SUNWcslx (64-bit)            │
114       ├─────────────────────────────┼─────────────────────────────┤
115       │MT-Level                     │MT-Safe                      │
116       └─────────────────────────────┴─────────────────────────────┘
117

SEE ALSO

119       ifconfig(1M), if_nametoindex(3XNET), attributes(5), if(7P)
120
121
122
123SunOS 5.11                        28 Jan 2009          if_nametoindex(3SOCKET)
Impressum