mailing list of musl libc
 help / color / mirror / code / Atom feed
* [PATCH] fix if_indextoname error case
@ 2016-09-15 15:27 Daniel Sabogal
  2016-09-15 15:27 ` [PATCH] fix type for ifc_ifcu.ifcu_buf field of struct ifconf Daniel Sabogal
  2016-09-16 22:03 ` [PATCH] fix if_indextoname error case Rich Felker
  0 siblings, 2 replies; 7+ messages in thread
From: Daniel Sabogal @ 2016-09-15 15:27 UTC (permalink / raw)
  To: musl

posix requires errno to be set to ENXIO if the interface does not exist.
linux returns ENODEV instead so we handle this.
---
 src/network/if_indextoname.c | 7 ++++++-
 1 file changed, 6 insertions(+), 1 deletion(-)

diff --git a/src/network/if_indextoname.c b/src/network/if_indextoname.c
index 6ee7f13..3b368bf 100644
--- a/src/network/if_indextoname.c
+++ b/src/network/if_indextoname.c
@@ -3,6 +3,7 @@
 #include <sys/socket.h>
 #include <sys/ioctl.h>
 #include <string.h>
+#include <errno.h>
 #include "syscall.h"
 
 char *if_indextoname(unsigned index, char *name)
@@ -14,5 +15,9 @@ char *if_indextoname(unsigned index, char *name)
 	ifr.ifr_ifindex = index;
 	r = ioctl(fd, SIOCGIFNAME, &ifr);
 	__syscall(SYS_close, fd);
-	return r < 0 ? 0 : strncpy(name, ifr.ifr_name, IF_NAMESIZE);
+	if (r < 0) {
+		if (errno == ENODEV) errno = ENXIO;
+		return 0;
+	}
+	return strncpy(name, ifr.ifr_name, IF_NAMESIZE);
 }
-- 
2.10.0



^ permalink raw reply	[flat|nested] 7+ messages in thread

end of thread, other threads:[~2016-09-16 22:03 UTC | newest]

Thread overview: 7+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-09-15 15:27 [PATCH] fix if_indextoname error case Daniel Sabogal
2016-09-15 15:27 ` [PATCH] fix type for ifc_ifcu.ifcu_buf field of struct ifconf Daniel Sabogal
2016-09-15 20:25   ` Alexander Monakov
2016-09-15 21:42     ` Daniel Sabogal
2016-09-16  8:12       ` Alexander Monakov
2016-09-16 14:57         ` Rich Felker
2016-09-16 22:03 ` [PATCH] fix if_indextoname error case Rich Felker

Code repositories for project(s) associated with this public inbox

	https://git.vuxu.org/mirror/musl/

This is a public inbox, see mirroring instructions
for how to clone and mirror all data and code used for this inbox;
as well as URLs for NNTP newsgroup(s).