mailing list of musl libc
 help / color / mirror / code / Atom feed
* [PATCH] fix if_nametoindex return value when socket open fails
@ 2016-01-15  9:39 Ron Yorston
  2016-01-15 18:57 ` Rich Felker
  2016-01-17 22:34 ` Rich Felker
  0 siblings, 2 replies; 3+ messages in thread
From: Ron Yorston @ 2016-01-15  9:39 UTC (permalink / raw)
  To: musl

The return value of if_nametoindex is unsigned; it should return 0
on error.
---
 src/network/if_nametoindex.c | 2 +-
 1 file changed, 1 insertion(+), 1 deletion(-)

diff --git a/src/network/if_nametoindex.c b/src/network/if_nametoindex.c
index cb6ec05..331413c 100644
--- a/src/network/if_nametoindex.c
+++ b/src/network/if_nametoindex.c
@@ -10,7 +10,7 @@ unsigned if_nametoindex(const char *name)
 	struct ifreq ifr;
 	int fd, r;
 
-	if ((fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0)) < 0) return -1;
+	if ((fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0)) < 0) return 0;
 	strncpy(ifr.ifr_name, name, sizeof ifr.ifr_name);
 	r = ioctl(fd, SIOCGIFINDEX, &ifr);
 	__syscall(SYS_close, fd);
-- 
2.5.0



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

* Re: [PATCH] fix if_nametoindex return value when socket open fails
  2016-01-15  9:39 [PATCH] fix if_nametoindex return value when socket open fails Ron Yorston
@ 2016-01-15 18:57 ` Rich Felker
  2016-01-17 22:34 ` Rich Felker
  1 sibling, 0 replies; 3+ messages in thread
From: Rich Felker @ 2016-01-15 18:57 UTC (permalink / raw)
  To: musl

On Fri, Jan 15, 2016 at 09:39:44AM +0000, Ron Yorston wrote:
> The return value of if_nametoindex is unsigned; it should return 0
> on error.
> ---
>  src/network/if_nametoindex.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/network/if_nametoindex.c b/src/network/if_nametoindex.c
> index cb6ec05..331413c 100644
> --- a/src/network/if_nametoindex.c
> +++ b/src/network/if_nametoindex.c
> @@ -10,7 +10,7 @@ unsigned if_nametoindex(const char *name)
>  	struct ifreq ifr;
>  	int fd, r;
>  
> -	if ((fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0)) < 0) return -1;
> +	if ((fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0)) < 0) return 0;
>  	strncpy(ifr.ifr_name, name, sizeof ifr.ifr_name);
>  	r = ioctl(fd, SIOCGIFINDEX, &ifr);
>  	__syscall(SYS_close, fd);
> -- 
> 2.5.0

Looks good. Actually it's unclear from the spec what should happen,
since "No errors are defined":

http://pubs.opengroup.org/onlinepubs/9699919799/functions/if_nametoindex.html

But 0 is specified as the return value for names which do not exist.
It seems unfortunate that applications can't distinguish between
errors and "no such name", but I don't think we can fix this on our
end. Someone should file a bug in POSIX and the resolution should
probably be that if_nametoindex leaves errno unchanged and returns 0
when the name does not exist, and sets errno and returns 0 when an
internal error occurs.

Rich


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

* Re: [PATCH] fix if_nametoindex return value when socket open fails
  2016-01-15  9:39 [PATCH] fix if_nametoindex return value when socket open fails Ron Yorston
  2016-01-15 18:57 ` Rich Felker
@ 2016-01-17 22:34 ` Rich Felker
  1 sibling, 0 replies; 3+ messages in thread
From: Rich Felker @ 2016-01-17 22:34 UTC (permalink / raw)
  To: musl

On Fri, Jan 15, 2016 at 09:39:44AM +0000, Ron Yorston wrote:
> The return value of if_nametoindex is unsigned; it should return 0
> on error.
> ---
>  src/network/if_nametoindex.c | 2 +-
>  1 file changed, 1 insertion(+), 1 deletion(-)
> 
> diff --git a/src/network/if_nametoindex.c b/src/network/if_nametoindex.c
> index cb6ec05..331413c 100644
> --- a/src/network/if_nametoindex.c
> +++ b/src/network/if_nametoindex.c
> @@ -10,7 +10,7 @@ unsigned if_nametoindex(const char *name)
>  	struct ifreq ifr;
>  	int fd, r;
>  
> -	if ((fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0)) < 0) return -1;
> +	if ((fd = socket(AF_UNIX, SOCK_DGRAM|SOCK_CLOEXEC, 0)) < 0) return 0;
>  	strncpy(ifr.ifr_name, name, sizeof ifr.ifr_name);
>  	r = ioctl(fd, SIOCGIFINDEX, &ifr);
>  	__syscall(SYS_close, fd);

Committed.

Rich


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

end of thread, other threads:[~2016-01-17 22:34 UTC | newest]

Thread overview: 3+ messages (download: mbox.gz / follow: Atom feed)
-- links below jump to the message on this page --
2016-01-15  9:39 [PATCH] fix if_nametoindex return value when socket open fails Ron Yorston
2016-01-15 18:57 ` Rich Felker
2016-01-17 22:34 ` 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).