Fix for x86_64 build fail
[platform/upstream/connectedhomeip.git] / third_party / lwip / repo / lwip / src / api / if.c
1 /**
2  * @file
3  * Interface Identification APIs from:
4  *              RFC 3493: Basic Socket Interface Extensions for IPv6
5  *                  Section 4: Interface Identification
6  */
7
8 /*
9  * Copyright (c) 2017 Joel Cunningham <joel.cunningham@me.com>
10  * All rights reserved.
11  *
12  * Redistribution and use in source and binary forms, with or without modificat
13 ion,
14  * are permitted provided that the following conditions are met:
15  *
16  * 1. Redistributions of source code must retain the above copyright notice,
17  *    this list of conditions and the following disclaimer.
18  * 2. Redistributions in binary form must reproduce the above copyright notice,
19  *    this list of conditions and the following disclaimer in the documentation
20  *    and/or other materials provided with the distribution.
21  * 3. The name of the author may not be used to endorse or promote products
22  *    derived from this software without specific prior written permission.
23  *
24  * THIS SOFTWARE IS PROVIDED BY THE AUTHOR ``AS IS'' AND ANY EXPRESS OR IMPLIED
25  * WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF
26  * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO E
27 VENT
28  * SHALL THE AUTHOR BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL,
29  * EXEMPLARY, OR CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREM
30 ENT
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) ARIS
34 ING
35  * IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY
36  * OF SUCH DAMAGE.
37  *
38  * This file is part of the lwIP TCP/IP stack.
39  *
40  * Author: Joel Cunningham <joel.cunningham@me.com>
41  *
42  */
43 #include "lwip/opt.h"
44
45 #if LWIP_SOCKET
46
47 #include "lwip/netifapi.h"
48
49 char *
50 lwip_if_indextoname(unsigned ifindex, char *ifname)
51 {
52   err_t err;
53   if (ifindex > 0xff) {
54     return NULL;
55   }
56   
57   err = netifapi_netif_index_to_name((u8_t)ifindex, ifname);
58   if (!err && ifname[0] != '\0') {
59     return ifname;
60   }
61   return NULL;
62 }
63
64 unsigned int
65 lwip_if_nametoindex(const char *ifname)
66 {
67   err_t err;
68   u8_t index;
69   
70   err = netifapi_netif_name_to_index(ifname, &index);
71   if (!err) {
72     return index;
73   }
74   return 0; /* invalid index */
75 }
76
77 #endif /* LWIP_SOCKET */