ReactOS 0.4.16-dev-1059-gb1cf981
if_api.c
Go to the documentation of this file.
1
11/*
12 * Copyright (c) 2017 Joel Cunningham, Garmin International, Inc. <joel.cunningham@garmin.com>
13 * All rights reserved.
14 *
15 * Redistribution and use in source and binary forms, with or without modification,
16 * are permitted provided that the following conditions are met:
17 *
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.
25 *
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
35 * OF SUCH DAMAGE.
36 *
37 * This file is part of the lwIP TCP/IP stack.
38 *
39 * Author: Joel Cunningham <joel.cunningham@me.com>
40 *
41 */
42#include "lwip/opt.h"
43
44#if LWIP_SOCKET
45
46#include "lwip/errno.h"
47#include "lwip/if_api.h"
48#include "lwip/netifapi.h"
50
60char *
61lwip_if_indextoname(unsigned int ifindex, char *ifname)
62{
63#if LWIP_NETIF_API
64 if (ifindex <= 0xff) {
65 err_t err = netifapi_netif_index_to_name((u8_t)ifindex, ifname);
66 if (!err && ifname[0] != '\0') {
67 return ifname;
68 }
69 }
70#else /* LWIP_NETIF_API */
71 LWIP_UNUSED_ARG(ifindex);
72 LWIP_UNUSED_ARG(ifname);
73#endif /* LWIP_NETIF_API */
74 set_errno(ENXIO);
75 return NULL;
76}
77
85unsigned int
86lwip_if_nametoindex(const char *ifname)
87{
88#if LWIP_NETIF_API
89 err_t err;
90 u8_t idx;
91
92 err = netifapi_netif_name_to_index(ifname, &idx);
93 if (!err) {
94 return idx;
95 }
96#else /* LWIP_NETIF_API */
97 LWIP_UNUSED_ARG(ifname);
98#endif /* LWIP_NETIF_API */
99 return 0; /* invalid index */
100}
101
102#endif /* LWIP_SOCKET */
#define NULL
Definition: types.h:112
unsigned int idx
Definition: utils.c:41
#define ENXIO
Definition: errno.h:12
uint8_t u8_t
Definition: arch.h:125
#define LWIP_UNUSED_ARG(x)
Definition: arch.h:373
s8_t err_t
Definition: err.h:96
#define err(...)