Source-Changes-HG archive
[Date Prev][Date Next][Thread Prev][Thread Next][Date Index][Thread Index][Old Index]
[src/trunk]: src/lib/libc use BSDI-origin if_{index, name}* functions. they u...
details: https://anonhg.NetBSD.org/src/rev/e2c546361d07
branches: trunk
changeset: 485291:e2c546361d07
user: itojun <itojun%NetBSD.org@localhost>
date: Mon Apr 24 10:24:46 2000 +0000
description:
use BSDI-origin if_{index,name}* functions. they use getifaddrs(3) as
backend and are more robust against SIOCGIFCONF alignment issue.
now getifaddrs always takes care of the issue. (sync with kame tree)
use weak symbol just in case.
diffstat:
lib/libc/include/namespace.h | 6 +-
lib/libc/net/Makefile.inc | 8 +-
lib/libc/net/if_indextoname.3 | 187 ++++++++++++++--------------------
lib/libc/net/if_indextoname.c | 85 +++++++++++++++
lib/libc/net/if_nameindex.c | 148 +++++++++++++++++++++++++++
lib/libc/net/if_nametoindex.c | 79 ++++++++++++++
lib/libc/net/ifname.c | 224 ------------------------------------------
7 files changed, 397 insertions(+), 340 deletions(-)
diffs (truncated from 832 to 300 lines):
diff -r 0bbb607e528c -r e2c546361d07 lib/libc/include/namespace.h
--- a/lib/libc/include/namespace.h Mon Apr 24 09:27:30 2000 +0000
+++ b/lib/libc/include/namespace.h Mon Apr 24 10:24:46 2000 +0000
@@ -1,4 +1,4 @@
-/* $NetBSD: namespace.h,v 1.49 2000/04/24 09:27:30 itojun Exp $ */
+/* $NetBSD: namespace.h,v 1.50 2000/04/24 10:24:46 itojun Exp $ */
/*-
* Copyright (c) 1997, 1998 The NetBSD Foundation, Inc.
@@ -233,6 +233,10 @@
#define hesiod_init _hesiod_init
#define hesiod_resolve _hesiod_resolve
#define hesiod_to_bind _hesiod_to_bind
+#define if_freenameindex _if_freenameindex
+#define if_indextoname _if_indextoname
+#define if_nameindex _if_nameindex
+#define if_nametoindex _if_nametoindex
#define in6addr_any _in6addr_any
#define in6addr_linklocal_allnodes _in6addr_linklocal_allnodes
#define in6addr_loopback _in6addr_loopback
diff -r 0bbb607e528c -r e2c546361d07 lib/libc/net/Makefile.inc
--- a/lib/libc/net/Makefile.inc Mon Apr 24 09:27:30 2000 +0000
+++ b/lib/libc/net/Makefile.inc Mon Apr 24 10:24:46 2000 +0000
@@ -1,4 +1,4 @@
-# $NetBSD: Makefile.inc,v 1.53 2000/03/14 14:34:50 sjg Exp $
+# $NetBSD: Makefile.inc,v 1.54 2000/04/24 10:24:47 itojun Exp $
# @(#)Makefile.inc 8.2 (Berkeley) 9/5/93
# net sources
@@ -18,10 +18,8 @@
CPPFLAGS+=-DRESOLVSORT -I.
# IPv6
-SRCS+= getaddrinfo.c getnameinfo.c ifname.c ip6opt.c rthdr.c vars6.c
-# need to revisit
-#SRCS+= name6.c freehostent.c
-#CPPFLAGS+= -DUSE_GETIPNODEBY
+SRCS+= getaddrinfo.c getnameinfo.c ip6opt.c rthdr.c vars6.c
+SRCS+= if_indextoname.c if_nameindex.c if_nametoindex.c
LPREFIX=_nsyy
YPREFIX=_nsyy
diff -r 0bbb607e528c -r e2c546361d07 lib/libc/net/if_indextoname.3
--- a/lib/libc/net/if_indextoname.3 Mon Apr 24 09:27:30 2000 +0000
+++ b/lib/libc/net/if_indextoname.3 Mon Apr 24 10:24:46 2000 +0000
@@ -1,26 +1,20 @@
-.\" Copyright (c) 1983, 1991, 1993
-.\" The Regents of the University of California. All rights reserved.
+.\" $NetBSD: if_indextoname.3,v 1.5 2000/04/24 10:24:47 itojun Exp $
+.\" $KAME: if_indextoname.3,v 1.8 2000/04/24 10:12:36 itojun Exp $
+.\" BSDI Id: if_indextoname.3,v 2.2 2000/04/17 22:38:05 dab Exp
+.\"
+.\" Copyright (c) 1997, 2000
+.\" Berkeley Software Design, Inc. All rights reserved.
.\"
.\" Redistribution and use in source and binary forms, with or without
.\" modification, are permitted provided that the following conditions
.\" are met:
.\" 1. Redistributions of source code must retain the above copyright
.\" notice, this list of conditions and the following disclaimer.
-.\" 2. Redistributions in binary form must reproduce the above copyright
-.\" notice, this list of conditions and the following disclaimer in the
-.\" documentation and/or other materials provided with the distribution.
-.\" 3. All advertising materials mentioning features or use of this software
-.\" must display the following acknowledgement:
-.\" This product includes software developed by the University of
-.\" California, Berkeley and its contributors.
-.\" 4. Neither the name of the University nor the names of its contributors
-.\" may be used to endorse or promote products derived from this software
-.\" without specific prior written permission.
.\"
-.\" THIS SOFTWARE IS PROVIDED BY THE REGENTS AND CONTRIBUTORS ``AS IS'' AND
+.\" THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``AS IS'' AND
.\" ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
.\" IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
-.\" ARE DISCLAIMED. IN NO EVENT SHALL THE REGENTS OR CONTRIBUTORS BE LIABLE
+.\" ARE DISCLAIMED. IN NO EVENT SHALL Berkeley Software Design, Inc. BE LIABLE
.\" FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL
.\" DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS
.\" OR SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
@@ -29,10 +23,7 @@
.\" OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
.\" SUCH DAMAGE.
.\"
-.\" From: @(#)rcmd.3 8.1 (Berkeley) 6/4/93
-.\" KAME Id: if_indextoname.3,v 1.4 1999/12/10 04:07:00 itojun Exp
-.\"
-.Dd May 21, 1998
+.Dd "July 11, 1997"
.Dt IF_NAMETOINDEX 3
.Os
.Sh NAME
@@ -40,119 +31,95 @@
.Nm if_indextoname ,
.Nm if_nameindex ,
.Nm if_freenameindex
-.Nd convert interface index to name, and vice versa
-.Sh LIBRARY
-.Lb libc
+.Nd provide mappings between interface names and indexes
.Sh SYNOPSIS
.Fd #include <net/if.h>
-.Ft "unsigned int"
+.Ft unsigned int
.Fn if_nametoindex "const char *ifname"
-.Ft "char *"
+.Ft char *
.Fn if_indextoname "unsigned int ifindex" "char *ifname"
-.Ft "struct if_nameindex *"
+.Ft struct if_nameindex *
.Fn if_nameindex "void"
-.Ft "void"
+.Ft void
.Fn if_freenameindex "struct if_nameindex *ptr"
.Sh DESCRIPTION
-The functions map interface index to readable interface name
-.Po
-such as
-.Dq Li lo0
-.Pc
-, and vice versa.
-.Pp
The
.Fn if_nametoindex
-function
-converts an interface name specified by the
-.Fa ifname
-argument to an interface index
-.Pq positive integer value .
-If the specified interface does not exist, 0 will be returned.
+function maps the interface name specified in
+.Ar ifname
+to its corresponding index.
+If the specified interface does not exist, it returns 0.
.Pp
-.Fn if_indextoname
-converts an interface index specified by the
-.Fa ifindex
-argument to an interface name.
The
-.Fa ifname
-argument must point to a buffer of at least
-.Dv IF_NAMESIZE
-bytes into which the interface name corresponding to the specified index is
-returned.
-.Po
-.Dv IF_NAMESIZE
-is also defined in
-.Aq Li net/if.h
-and its value includes a terminating null byte at the end of the
-interface name.
-.Pc
+.Fn if_indextoname
+function maps the interface index specified in
+.Ar ifindex
+to it corresponding name, which is copied into the
+buffer pointed to by
+.Ar ifname ,
+which must be of at least IFNAMSIZ bytes.
This pointer is also the return value of the function.
-If there is no interface corresponding to the specified index,
-.Dv NULL
-is returned.
+If there is no interface corresponding to the specified
+index, NULL is returned.
.Pp
+The
.Fn if_nameindex
-returns an array of
-.Fa if_nameindex
-structures.
-.Fa if_nametoindex
-is also defined in
-.Aq Li net/if.h ,
-and is as follows:
-.Bd -literal -offset
-struct if_nameindex {
+function returns an array of
+.Nm if_nameindex
+structures, one structure per interface, as
+defined in the include file
+.Aq Pa net/if.h .
+The
+.Nm if_nameindex
+structure contains at least the following entries:
+.Bd -literal
unsigned int if_index; /* 1, 2, ... */
char *if_name; /* null terminated name: "le0", ... */
-};
.Ed
.Pp
-The end of the array of structures is indicated by a structure with
-an
-.Fa if_index
+The end of the array of structures is indicated by a structure with an
+.Nm if_index
of 0 and an
-.Fa if_name
-of
-.Dv NULL .
-The function returns a
-.Dv NULL
-pointer upon an error.
-The memory used for this array of structures along with the interface
-names pointed to by the
-.Fa if_name
-members is obtained dynamically.
-This memory is freed by the
+.Nm if_name
+of NULL. A NULL pointer is returned upon an error.
+.Pp
+The
.Fn if_freenameindex
-function.
+function frees the dynamic memory that was
+allocated by
+.Fn if_nameindex .
+.Sh RETURN VALUES
+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
+occurs while retrieving the list of interfaces via
+.Xr getifaddrs 3 .
.Pp
-.Fn if_freenameindex
-takes a pointer that was returned by
+Upon successful completion,
+.Fn if_indextoname
+returns
+.Ar ifname .
+A NULL pointer is returned if the interface is not found or an error
+occurs while retrieving the list of interfaces via
+.Xr getifaddrs 3 .
+.Pp
+The
.Fn if_nameindex
-as argument
-.Pq Fa ptr ,
-and it reclaims the region allocated.
-.Sh DIAGNOSTICS
-.Fn if_nametoindex
-returns 0 on error, positive integer on success.
-.Fn if_indextoname
-and
-.Fn if_nameindex
-return
-.Dv NULL
-on errors.
+returns a NULL pointer if an error
+occurs while retrieving the list of interfaces via
+.Xr getifaddrs 3 ,
+or if sufficient memory cannot be allocated.
.Sh SEE ALSO
-.Rs
-.%A R. Gilligan
-.%A S. Thomson
-.%A J. Bound
-.%A W. Stevens
-.%T Basic Socket Interface Extensions for IPv6
-.%R RFC2553
-.%D March 1999
-.Re
+.Xr getifaddrs 3 ,
+.Xr networking 4
+.Sh STANDARDS
+The
+.Fn if_nametoindex ,
+.Fn if_indextoname ,
+.Fn if_nameindex ,
+and
+.Fn if_freenameindex
+functions conform to RFC 2553.
.Sh HISTORY
-The implementation first appeared in WIDE Hydrangea IPv6 protocol stack kit.
-.Sh STANDARDS
-These functions are defined in
-.Dq Basic Socket Interface Extensions for IPv6
-.Pq RFC2533 .
+The implementation first appeared in BSDI BSD/OS.
diff -r 0bbb607e528c -r e2c546361d07 lib/libc/net/if_indextoname.c
--- /dev/null Thu Jan 01 00:00:00 1970 +0000
+++ b/lib/libc/net/if_indextoname.c Mon Apr 24 10:24:46 2000 +0000
@@ -0,0 +1,85 @@
+/* $NetBSD: if_indextoname.c,v 1.1 2000/04/24 10:24:47 itojun Exp $ */
+/* $KAME: if_indextoname.c,v 1.4 2000/04/24 10:08:41 itojun Exp $ */
+
+/*-
+ * Copyright (c) 1997, 2000
+ * Berkeley Software Design, Inc. All rights reserved.
+ *
+ * Redistribution and use in source and binary forms, with or without
+ * modification, are permitted provided that the following conditions
+ * are met:
+ * 1. Redistributions of source code must retain the above copyright
+ * notice, this list of conditions and the following disclaimer.
+ *
+ * THIS SOFTWARE IS PROVIDED BY Berkeley Software Design, Inc. ``AS IS'' AND
+ * ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE
+ * IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE
Home |
Main Index |
Thread Index |
Old Index