From: Daniel Sabogal <dsabogalcc@gmail.com>
To: musl@lists.openwall.com
Subject: [PATCH] fix if_indextoname error case
Date: Thu, 15 Sep 2016 11:27:30 -0400 [thread overview]
Message-ID: <20160915152731.4897-1-dsabogalcc@gmail.com> (raw)
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
next reply other threads:[~2016-09-15 15:27 UTC|newest]
Thread overview: 7+ messages / expand[flat|nested] mbox.gz Atom feed top
2016-09-15 15:27 Daniel Sabogal [this message]
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
Reply instructions:
You may reply publicly to this message via plain-text email
using any one of the following methods:
* Save the following mbox file, import it into your mail client,
and reply-to-all from there: mbox
Avoid top-posting and favor interleaved quoting:
https://en.wikipedia.org/wiki/Posting_style#Interleaved_style
* Reply using the --to, --cc, and --in-reply-to
switches of git-send-email(1):
git send-email \
--in-reply-to=20160915152731.4897-1-dsabogalcc@gmail.com \
--to=dsabogalcc@gmail.com \
--cc=musl@lists.openwall.com \
/path/to/YOUR_REPLY
https://kernel.org/pub/software/scm/git/docs/git-send-email.html
* If your mail client supports setting the In-Reply-To header
via mailto: links, try the mailto: link
Be sure your reply has a Subject: header at the top and a blank line
before the message body.
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).