Package: glibc-doc-reference, libc6
Version: 2.13-1, 2.13-38+deb7u1

I have been writing a program which needs to call if_nametoindex.
Naturally I need to deal with the possible error cases.


RFC3493, which appears to be the standards document describing it, has
this to say about its error behaviour:

   If ifname is the name of an interface, the if_nametoindex() function
   shall return the interface index corresponding to name ifname;
   otherwise, it shall return zero.  No errors are defined.

The glibc info document says, very similarly,

 -- Function: unsigned int if_nametoindex (const char *ifname)
     This function yields the interface index corresponding to a
     particular name.  If no interface exists with the name given, it
     returns 0.

Of course this leaves the implementors of if_nametoindex in a quandry:
what to do if the operation fails ?  And correspondingly, it doesn't
say how the callers are to distinguish "no such interface" from
"arrgh!".


I wrote a test program (see #749345) to discover the real behaviour.
It appears that if if_nametoindex fails it sets errno - on Debian
squeeze, FreeBSD 10 and OpenBSD 4.9, at least.

If the name is not that of an interface, it sets errno to ENXIO (which
is is specified on the RFC for if_indextoname in the analogous case).

If if_nametoindex fails for another reason, it returns 0 and leaves
errno set to whatever it got from the underlying failing system call.
We (mostly Mark Wooding and Richard Kettlewell) haven't been able to
get the BSDs to actually fail - the implementation has a fallback
strategy which meant that the ulimit trick doesn't work.  But FreeBSD
documents the behaviour (mostly):
  
http://www.freebsd.org/cgi/man.cgi?query=getifaddrs&sektion=3&apropos=0&manpath=FreeBSD+10.0-RELEASE


It would be good if the error behaviour were documented in the glibc
reference manual.


Thanks,
Ian.


-- 
To UNSUBSCRIBE, email to debian-glibc-requ...@lists.debian.org
with a subject of "unsubscribe". Trouble? Contact listmas...@lists.debian.org
Archive: 
https://lists.debian.org/21379.23603.494700.761...@chiark.greenend.org.uk

Reply via email to