d680d4eb3f57adc023108b9957726243eaf7f6e7
[openwrt/openwrt.git] / toolchain / musl / patches / 030-fix-if_indextoname-error-case.patch
1 From 32055d52ca43d867d6dbb763dc5213a8d3536a23 Mon Sep 17 00:00:00 2001
2 From: Daniel Sabogal <dsabogalcc@gmail.com>
3 Date: Thu, 15 Sep 2016 11:27:30 -0400
4 Subject: fix if_indextoname error case
5
6 posix requires errno to be set to ENXIO if the interface does not exist.
7 linux returns ENODEV instead so we handle this.
8 ---
9 src/network/if_indextoname.c | 7 ++++++-
10 1 file changed, 6 insertions(+), 1 deletion(-)
11
12 diff --git a/src/network/if_indextoname.c b/src/network/if_indextoname.c
13 index 6ee7f13..3b368bf 100644
14 --- a/src/network/if_indextoname.c
15 +++ b/src/network/if_indextoname.c
16 @@ -3,6 +3,7 @@
17 #include <sys/socket.h>
18 #include <sys/ioctl.h>
19 #include <string.h>
20 +#include <errno.h>
21 #include "syscall.h"
22
23 char *if_indextoname(unsigned index, char *name)
24 @@ -14,5 +15,9 @@ char *if_indextoname(unsigned index, char *name)
25 ifr.ifr_ifindex = index;
26 r = ioctl(fd, SIOCGIFNAME, &ifr);
27 __syscall(SYS_close, fd);
28 - return r < 0 ? 0 : strncpy(name, ifr.ifr_name, IF_NAMESIZE);
29 + if (r < 0) {
30 + if (errno == ENODEV) errno = ENXIO;
31 + return 0;
32 + }
33 + return strncpy(name, ifr.ifr_name, IF_NAMESIZE);
34 }
35 --
36 cgit v0.11.2