Source-Changes-HG archive

[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]

[src/trunk]: src/lib/libc/net strictly conform to RFC2553 (specifically ENXIO...



details:   https://anonhg.NetBSD.org/src/rev/83f3b98d6e67
branches:  trunk
changeset: 499588:83f3b98d6e67
user:      itojun <itojun%NetBSD.org@localhost>
date:      Fri Nov 24 08:21:12 2000 +0000

description:
strictly conform to RFC2553 (specifically ENXIO case).  sync with KAME

diffstat:

 lib/libc/net/if_indextoname.3 |  19 +++++++++++++----
 lib/libc/net/if_indextoname.c |  44 ++++++++++++++++++++++++------------------
 lib/libc/net/if_nameindex.c   |  30 +++++++++++++++-------------
 lib/libc/net/if_nametoindex.c |  25 +++++++++++++++--------
 4 files changed, 71 insertions(+), 47 deletions(-)

diffs (264 lines):

diff -r b431a69304cb -r 83f3b98d6e67 lib/libc/net/if_indextoname.3
--- a/lib/libc/net/if_indextoname.3     Fri Nov 24 07:42:07 2000 +0000
+++ b/lib/libc/net/if_indextoname.3     Fri Nov 24 08:21:12 2000 +0000
@@ -1,5 +1,5 @@
-.\"    $NetBSD: if_indextoname.3,v 1.6 2000/09/21 10:43:49 ad Exp $
-.\"    $KAME: if_indextoname.3,v 1.8 2000/04/24 10:12:36 itojun Exp $
+.\"    $NetBSD: if_indextoname.3,v 1.7 2000/11/24 08:21:12 itojun Exp $
+.\"    $KAME: if_indextoname.3,v 1.10 2000/11/24 08:13:51 itojun Exp $
 .\"    BSDI    Id: if_indextoname.3,v 2.2 2000/04/17 22:38:05 dab Exp
 .\"
 .\" Copyright (c) 1997, 2000
@@ -81,7 +81,8 @@
 .Nm if_index
 of 0 and an
 .Nm if_name
-of NULL.  A NULL pointer is returned upon an error.
+of NULL.
+A NULL pointer is returned upon an error.
 .Pp
 The
 .Fn if_freenameindex
@@ -92,7 +93,11 @@
 Upon successful completion,
 .Fn if_nametoindex
 returns the index number of the interface.
-A value of 0 is returned if the interface is not found or an error
+If the interface is not found, a value of 0 is returned and
+.Va errno
+is set to
+.Er ENXIO .
+A value of 0 is also returned if an error
 occurs while retrieving the list of interfaces via
 .Xr getifaddrs 3 .
 .Pp
@@ -100,7 +105,11 @@
 .Fn if_indextoname
 returns
 .Ar ifname .
-A NULL pointer is returned if the interface is not found or an error
+If the interface is not found, a NULL pointer is returned and
+.Va errno
+is set to
+.Er ENXIO .
+A NULL pointer is also returned if an error
 occurs while retrieving the list of interfaces via
 .Xr getifaddrs 3 .
 .Pp
diff -r b431a69304cb -r 83f3b98d6e67 lib/libc/net/if_indextoname.c
--- a/lib/libc/net/if_indextoname.c     Fri Nov 24 07:42:07 2000 +0000
+++ b/lib/libc/net/if_indextoname.c     Fri Nov 24 08:21:12 2000 +0000
@@ -1,5 +1,5 @@
-/*     $NetBSD: if_indextoname.c,v 1.3 2000/07/06 02:54:55 christos Exp $      */
-/*     $KAME: if_indextoname.c,v 1.4 2000/04/24 10:08:41 itojun Exp $  */
+/*     $NetBSD: if_indextoname.c,v 1.4 2000/11/24 08:21:12 itojun Exp $        */
+/*     $KAME: if_indextoname.c,v 1.7 2000/11/08 03:09:30 itojun Exp $  */
 
 /*-
  * Copyright (c) 1997, 2000
@@ -28,7 +28,7 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: if_indextoname.c,v 1.3 2000/07/06 02:54:55 christos Exp $");
+__RCSID("$NetBSD: if_indextoname.c,v 1.4 2000/11/24 08:21:12 itojun Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include "namespace.h"
@@ -39,38 +39,41 @@
 #include <ifaddrs.h>
 #include <stdlib.h>
 #include <string.h>
+#include <errno.h>
 
 #ifdef __weak_alias
 __weak_alias(if_indextoname,_if_indextoname)
 #endif
 
 /*
- * From RFC 2133:
- *
- * 4.2.  Index-to-Name
+ * From RFC 2533:
  *
- *    The second function maps an interface index into its corresponding
- *    name.
+ * The second function maps an interface index into its corresponding
+ * name.
  *
- *        #include <net/if.h>
+ *    #include <net/if.h>
+ *
+ *    char  *if_indextoname(unsigned int ifindex, char *ifname);
  *
- *        char  *if_indextoname(unsigned int ifindex, char *ifname);
- *
- *    The ifname argument must point to a buffer of at least IFNAMSIZ bytes
- *    into which the interface name corresponding to the specified index is
- *    returned.  (IFNAMSIZ is also defined in <net/if.h> and its value
- *    includes a terminating null byte at the end of the interface name.)
- *    This pointer is also the return value of the function.  If there is
- *    no interface corresponding to the specified index, NULL is returned.
+ * The ifname argument must point to a buffer of at least IF_NAMESIZE
+ * bytes into which the interface name corresponding to the specified
+ * index is returned.  (IF_NAMESIZE is also defined in <net/if.h> and
+ * its value includes a terminating null byte at the end of the
+ * interface name.) This pointer is also the return value of the
+ * function.  If there is no interface corresponding to the specified
+ * index, NULL is returned, and errno is set to ENXIO, if there was a
+ * system error (such as running out of memory), if_indextoname returns
+ * NULL and errno would be set to the proper value (e.g., ENOMEM).
  */
 
 char *
 if_indextoname(unsigned int ifindex, char *ifname)
 {
        struct ifaddrs *ifaddrs, *ifa;
+       int error = 0;
 
        if (getifaddrs(&ifaddrs) < 0)
-               return(NULL);
+               return(NULL);   /* getifaddrs properly set errno */
 
        for (ifa = ifaddrs; ifa != NULL; ifa = ifa->ifa_next) {
                if (ifa->ifa_addr &&
@@ -80,12 +83,15 @@
                        break;
        }
 
-       if (ifa == NULL)
+       if (ifa == NULL) {
+               error = ENXIO;
                ifname = NULL;
+       }
        else
                strncpy(ifname, ifa->ifa_name, IFNAMSIZ);
 
        freeifaddrs(ifaddrs);
 
+       errno = error;
        return(ifname);
 }
diff -r b431a69304cb -r 83f3b98d6e67 lib/libc/net/if_nameindex.c
--- a/lib/libc/net/if_nameindex.c       Fri Nov 24 07:42:07 2000 +0000
+++ b/lib/libc/net/if_nameindex.c       Fri Nov 24 08:21:12 2000 +0000
@@ -1,5 +1,5 @@
-/*     $NetBSD: if_nameindex.c,v 1.4 2000/07/24 12:06:55 itojun Exp $  */
-/*     $KAME: if_nameindex.c,v 1.5 2000/07/24 12:03:31 itojun Exp $    */
+/*     $NetBSD: if_nameindex.c,v 1.5 2000/11/24 08:21:12 itojun Exp $  */
+/*     $KAME: if_nameindex.c,v 1.8 2000/11/24 08:20:01 itojun Exp $    */
 
 /*-
  * Copyright (c) 1997, 2000
@@ -28,7 +28,7 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: if_nameindex.c,v 1.4 2000/07/24 12:06:55 itojun Exp $");
+__RCSID("$NetBSD: if_nameindex.c,v 1.5 2000/11/24 08:21:12 itojun Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include "namespace.h"
@@ -45,25 +45,27 @@
 __weak_alias(if_freenameindex,_if_freenameindex)
 #endif
 /*
- * From RFC 2133:
+ * From RFC 2553:
+ *
+ * 4.3 Return All Interface Names and Indexes
  *
- * 4.3.  Return All Interface Names and Indexes
+ *    The if_nameindex structure holds the information about a single
+ *    interface and is defined as a result of including the <net/if.h>
+ *    header.
+ *
+ *       struct if_nameindex {
+ *         unsigned int   if_index;
+ *         char          *if_name;
+ *       };
  *
  *    The final function returns an array of if_nameindex structures, one
  *    structure per interface.
  *
- *        #include <net/if.h>
- *
- *        struct if_nameindex {
- *          unsigned int   if_index;  / * 1, 2, ... * /
- *          char          *if_name;   / * null terminated name: "le0", ... * /
- *        };
- *
- *        struct if_nameindex  *if_nameindex(void);
+ *       struct if_nameindex  *if_nameindex(void);
  *
  *    The end of the array of structures is indicated by a structure with
  *    an if_index of 0 and an if_name of NULL.  The function returns a NULL
- *    pointer upon an error.
+ *    pointer upon an error, and would set errno to the appropriate value.
  *
  *    The memory used for this array of structures along with the interface
  *    names pointed to by the if_name members is obtained dynamically.
diff -r b431a69304cb -r 83f3b98d6e67 lib/libc/net/if_nametoindex.c
--- a/lib/libc/net/if_nametoindex.c     Fri Nov 24 07:42:07 2000 +0000
+++ b/lib/libc/net/if_nametoindex.c     Fri Nov 24 08:21:12 2000 +0000
@@ -1,5 +1,5 @@
-/*     $NetBSD: if_nametoindex.c,v 1.3 2000/07/06 02:56:25 christos Exp $      */
-/*     $KAME: if_nametoindex.c,v 1.4 2000/04/24 10:08:41 itojun Exp $  */
+/*     $NetBSD: if_nametoindex.c,v 1.4 2000/11/24 08:21:12 itojun Exp $        */
+/*     $KAME: if_nametoindex.c,v 1.6 2000/11/24 08:18:54 itojun Exp $  */
 
 /*-
  * Copyright (c) 1997, 2000
@@ -28,7 +28,7 @@
 
 #include <sys/cdefs.h>
 #if defined(LIBC_SCCS) && !defined(lint)
-__RCSID("$NetBSD: if_nametoindex.c,v 1.3 2000/07/06 02:56:25 christos Exp $");
+__RCSID("$NetBSD: if_nametoindex.c,v 1.4 2000/11/24 08:21:12 itojun Exp $");
 #endif /* LIBC_SCCS and not lint */
 
 #include "namespace.h"
@@ -39,24 +39,29 @@
 #include <ifaddrs.h>
 #include <stdlib.h>
 #include <string.h>
+#include <errno.h>
 
 #ifdef __weak_alias
 __weak_alias(if_nametoindex,_if_nametoindex)
 #endif
 
 /*
- * From RFC 2133:
+ * From RFC 2553:
  *
- * 4.1.  Name-to-Index
+ * 4.1 Name-to-Index
+ *
  *
  *    The first function maps an interface name into its corresponding
  *    index.
  *
- *        #include <net/if.h>
+ *       #include <net/if.h>
+ *
+ *       unsigned int  if_nametoindex(const char *ifname);
  *
- *        unsigned int  if_nametoindex(const char *ifname);
- *
- *    If the specified interface does not exist, the return value is 0.
+ *    If the specified interface name does not exist, the return value is
+ *    0, and errno is set to ENXIO.  If there was a system error (such as
+ *    running out of memory), the return value is 0 and errno is set to the
+ *    proper value (e.g., ENOMEM).
  */
 
 unsigned int
@@ -81,5 +86,7 @@
        }
 
        freeifaddrs(ifaddrs);
+       if (!ni)
+               errno = ENXIO;
        return(ni);
 }



Home | Main Index | Thread Index | Old Index