3 * Interface Identification APIs from:
4 * RFC 3493: Basic Socket Interface Extensions for IPv6
5 * Section 4: Interface Identification
7 * @defgroup if_api Interface Identification API
12 * Copyright (c) 2017 Joel Cunningham, Garmin International, Inc. <joel.cunningham@garmin.com>
13 * All rights reserved.
15 * Redistribution and use in source and binary forms, with or without modification,
16 * are permitted provided that the following conditions are met:
18 * 1. Redistributions of source code must retain the above copyright notice,
19 * this list of conditions and the following disclaimer.
20 * 2. Redistributions in binary form must reproduce the above copyright notice,
21 * this list of conditions and the following disclaimer in the documentation
22 * and/or other materials provided with the distribution.
23 * 3. The name of the author may not be used to endorse or promote products
24 * derived from this software without specific prior written permission.
26 * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
27 * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
28 * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT
29 * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
30 * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT
31 * OF SUBSTITUTE GOODS OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS
32 * INTERRUPTION) HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN
33 * CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING
34 * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
37 * This file is part of the lwIP TCP/IP stack.
39 * Author: Joel Cunningham <joel.cunningham@me.com>
46 #include "lwip/errno.h"
47 #include "lwip/if_api.h"
48 #include "lwip/netifapi.h"
49 #include "lwip/priv/sockets_priv.h"
53 * Maps an interface index to its corresponding name.
54 * @param ifindex interface index
55 * @param ifname shall point to a buffer of at least {IF_NAMESIZE} bytes
56 * @return If ifindex is an interface index, then the function shall return the
57 * value supplied in ifname, which points to a buffer now containing the interface name.
58 * Otherwise, the function shall return a NULL pointer.
61 lwip_if_indextoname(unsigned int ifindex
, char *ifname
)
64 if (ifindex
<= 0xff) {
65 err_t err
= netifapi_netif_index_to_name((u8_t
)ifindex
, ifname
);
66 if (!err
&& ifname
[0] != '\0') {
70 #else /* LWIP_NETIF_API */
71 LWIP_UNUSED_ARG(ifindex
);
72 LWIP_UNUSED_ARG(ifname
);
73 #endif /* LWIP_NETIF_API */
80 * Returs the interface index corresponding to name ifname.
81 * @param ifname Interface name
82 * @return The corresponding index if ifname is the name of an interface;
86 lwip_if_nametoindex(const char *ifname
)
92 err
= netifapi_netif_name_to_index(ifname
, &idx
);
96 #else /* LWIP_NETIF_API */
97 LWIP_UNUSED_ARG(ifname
);
98 #endif /* LWIP_NETIF_API */
99 return 0; /* invalid index */
102 #endif /* LWIP_SOCKET */