summaryrefslogtreecommitdiff
path: root/usr/src
diff options
context:
space:
mode:
Diffstat (limited to 'usr/src')
-rw-r--r--usr/src/cmd/cmd-inet/Makefile22
-rw-r--r--usr/src/cmd/cmd-inet/common/Makefile53
-rw-r--r--usr/src/cmd/cmd-inet/common/ifaddrlist.c218
-rw-r--r--usr/src/cmd/cmd-inet/common/ifaddrlist.h63
-rw-r--r--usr/src/cmd/cmd-inet/usr.sbin/ping/Makefile33
-rw-r--r--usr/src/cmd/cmd-inet/usr.sbin/ping/ping.c4
-rw-r--r--usr/src/cmd/cmd-inet/usr.sbin/ping/ping_aux.c4
-rw-r--r--usr/src/cmd/cmd-inet/usr.sbin/ping/ping_aux6.c6
-rw-r--r--usr/src/cmd/cmd-inet/usr.sbin/ping/req.flg29
-rw-r--r--usr/src/cmd/cmd-inet/usr.sbin/traceroute/Makefile29
-rw-r--r--usr/src/cmd/cmd-inet/usr.sbin/traceroute/req.flg8
-rw-r--r--usr/src/cmd/cmd-inet/usr.sbin/traceroute/traceroute.c5
-rw-r--r--usr/src/cmd/cmd-inet/usr.sbin/traceroute/traceroute_aux.c4
-rw-r--r--usr/src/cmd/cmd-inet/usr.sbin/traceroute/traceroute_aux6.c4
-rw-r--r--usr/src/cmd/rcm_daemon/Makefile.com6
-rw-r--r--usr/src/cmd/rcm_daemon/common/ip_anon_rcm.c216
-rw-r--r--usr/src/lib/libinetutil/Makefile.com7
-rw-r--r--usr/src/lib/libinetutil/common/ifaddrlist.c192
-rw-r--r--usr/src/lib/libinetutil/common/libinetutil.h38
-rw-r--r--usr/src/lib/libinetutil/spec/inetutil.spec8
20 files changed, 283 insertions, 666 deletions
diff --git a/usr/src/cmd/cmd-inet/Makefile b/usr/src/cmd/cmd-inet/Makefile
index 748b76e4c5..fc35bd8e68 100644
--- a/usr/src/cmd/cmd-inet/Makefile
+++ b/usr/src/cmd/cmd-inet/Makefile
@@ -22,17 +22,13 @@
#
#ident "%Z%%M% %I% %E% SMI"
#
-# Copyright (c) 1989-2000 by Sun Microsystems, Inc.
-# All rights reserved.
+# Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+# Use is subject to license terms.
#
-#
-# include global definitions
-include ../Makefile.cmd
-SUBDIR1= common
-SUBDIR2= etc sbin usr.bin usr.sbin usr.lib usr.sadm
-SUBDIRS= $(SUBDIR1) $(SUBDIR2)
+include ../Makefile.cmd
+SUBDIRS= etc sbin usr.bin usr.sbin usr.lib usr.sadm
MSGSUBDIRS= usr.bin usr.sbin usr.lib usr.sadm
POFILES= usr.bin/usr.bin.po usr.sbin/usr.sbin.po usr.sadm/usr.sadm.po
POFILE= cmd-inet.po
@@ -48,9 +44,7 @@ _msg:= TARGET= _msg
.PARALLEL: $(SUBDIRS)
-all install lint: $(SUBDIR1) .WAIT $(SUBDIR2)
-
-clean: $(SUBDIRS)
+all clean install lint: $(SUBDIRS)
clobber: $(SUBDIRS) local_clobber
@@ -59,11 +53,11 @@ local_clobber:
_msg: $(MSGSUBDIRS)
$(RM) $(POFILE)
- cat $(POFILES) > $(POFILE)
+ $(CAT) $(POFILES) > $(POFILE)
$(RM) $(MSGDOMAIN)/$(POFILE)
- cp $(POFILE) $(MSGDOMAIN)
+ $(CP) $(POFILE) $(MSGDOMAIN)
$(SUBDIRS): FRC
- @cd $@; pwd; $(MAKE) $(MFLAGS) $(TARGET)
+ @cd $@; pwd; $(MAKE) $(TARGET)
FRC:
diff --git a/usr/src/cmd/cmd-inet/common/Makefile b/usr/src/cmd/cmd-inet/common/Makefile
deleted file mode 100644
index 370372df32..0000000000
--- a/usr/src/cmd/cmd-inet/common/Makefile
+++ /dev/null
@@ -1,53 +0,0 @@
-#
-# CDDL HEADER START
-#
-# The contents of this file are subject to the terms of the
-# Common Development and Distribution License, Version 1.0 only
-# (the "License"). You may not use this file except in compliance
-# with the License.
-#
-# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
-# or http://www.opensolaris.org/os/licensing.
-# See the License for the specific language governing permissions
-# and limitations under the License.
-#
-# When distributing Covered Code, include this CDDL HEADER in each
-# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
-# If applicable, add the following below this CDDL HEADER, with the
-# fields enclosed by brackets "[]" replaced with your own identifying
-# information: Portions Copyright [yyyy] [name of copyright owner]
-#
-# CDDL HEADER END
-#
-#
-# Copyright 1998-2002 Sun Microsystems, Inc. All rights reserved.
-# Use is subject to license terms.
-#
-# ident "%Z%%M% %I% %E% SMI"
-#
-
-OBJS= ifaddrlist.o
-
-SRCS= $(OBJS:.o=.c)
-HDRS= ifaddrlist.h
-
-include ../../Makefile.cmd
-
-CPPFLAGS += -O -I.
-
-.KEEP_STATE:
-
-all: $(OBJS)
-
-clean:
- $(RM) $(OBJS)
-
-lint: lint_SRCS
-
-install: all
-
-# When an internationalized code is added to this directory, _msg has to be
-# defined in order to generate message catalog. Also, move 'common' directory
-# from 'SUBDIR1' to 'SUBDIR2' in usr/src/cmd/cmd-inet/Makefile
-
-include ../../Makefile.targ
diff --git a/usr/src/cmd/cmd-inet/common/ifaddrlist.c b/usr/src/cmd/cmd-inet/common/ifaddrlist.c
deleted file mode 100644
index 91638f1995..0000000000
--- a/usr/src/cmd/cmd-inet/common/ifaddrlist.c
+++ /dev/null
@@ -1,218 +0,0 @@
-/*
- * Copyright 1997,2002-2003 Sun Microsystems, Inc. All rights reserved.
- * Use is subject to license terms.
- */
-
-/*
- * Copyright (c) 1997
- * The Regents of the University of California. 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 Computer Systems
- * Engineering Group at Lawrence Berkeley Laboratory.
- * 4. Neither the name of the University nor of the Laboratory 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
- * 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
- * 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)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- * @(#) $Header: ifaddrlist.c,v 1.2 97/04/22 13:31:05 leres Exp $ (LBL)
- */
-
-#pragma ident "%Z%%M% %I% %E% SMI"
-
-#include <sys/param.h>
-#include <sys/file.h>
-#include <sys/ioctl.h>
-#include <sys/socket.h>
-#include <sys/sockio.h>
-#include <sys/time.h>
-
-#include <net/if.h>
-#include <netinet/in.h>
-
-#include <ctype.h>
-#include <errno.h>
-#include <memory.h>
-#include <stdio.h>
-#include <stdlib.h>
-#include <string.h>
-#include <unistd.h>
-#include <libintl.h>
-
-#include "ifaddrlist.h"
-
-/*
- * Construct the interface list with given address family.
- * If it fails, returns -1 and an error message in *errbuf;
- * otherwise, returns number of interfaces, and the interface list in *ipaddrp.
- */
-int
-ifaddrlist(struct ifaddrlist **ipaddrp, int family, char *errbuf)
-{
- int fd;
- struct lifreq *lifrp, *lifend;
- struct sockaddr_in *sin;
- struct sockaddr_in6 *sin6;
- struct ifaddrlist *al;
- struct lifconf lifc;
- struct lifreq *ibuf, lifr;
- char device[LIFNAMSIZ + 1];
- struct ifaddrlist *ifaddrlist;
- struct lifnum lifn;
- int lifc_flags = 0;
- int count;
-
- if (family != AF_INET && family != AF_INET6) {
- (void) sprintf(errbuf, "invalid address family");
- return (-1);
- }
-
- fd = socket(family, SOCK_DGRAM, 0);
- if (fd < 0) {
- (void) snprintf(errbuf, ERRBUFSIZE, "socket: %s",
- strerror(errno));
- return (-1);
- }
-
- /* determine the number of interfaces */
- lifn.lifn_family = family;
- lifn.lifn_flags = lifc_flags;
- if (ioctl(fd, SIOCGLIFNUM, &lifn) < 0) {
- (void) snprintf(errbuf, ERRBUFSIZE, "SIOCGLIFNUM: %s",
- strerror(errno));
- (void) close(fd);
- return (-1);
- }
-
- /* allocate memory for the determined number of interfaces */
- ifaddrlist = calloc((size_t)lifn.lifn_count,
- (size_t)sizeof (struct ifaddrlist));
- if (ifaddrlist == NULL) {
- (void) snprintf(errbuf, ERRBUFSIZE, "calloc: %s",
- strerror(errno));
- (void) close(fd);
- return (-1);
- }
-
- ibuf = calloc((size_t)lifn.lifn_count, (size_t)sizeof (struct lifreq));
- if (ibuf == NULL) {
- (void) snprintf(errbuf, ERRBUFSIZE, "calloc: %s",
- strerror(errno));
- free(ifaddrlist);
- (void) close(fd);
- return (-1);
- }
-
- /* pull out the interface list from the kernel */
- lifc.lifc_family = family;
- lifc.lifc_len = (int)(lifn.lifn_count * sizeof (struct lifreq));
- lifc.lifc_buf = (caddr_t)ibuf;
- lifc.lifc_flags = lifc_flags;
-
- if (ioctl(fd, SIOCGLIFCONF, (char *)&lifc) < 0 ||
- lifc.lifc_len < sizeof (struct lifreq)) {
- (void) snprintf(errbuf, ERRBUFSIZE, "SIOCGLIFCONF: %s",
- strerror(errno));
- free(ifaddrlist);
- free(ibuf);
- (void) close(fd);
- return (-1);
- }
-
- lifrp = ibuf;
- /* LINTED */
- lifend = (struct lifreq *)((char *)ibuf + lifc.lifc_len);
-
- al = ifaddrlist;
- count = 0;
-
- /* let's populate the interface entries in the ifaddrlist */
- for (; lifrp < lifend; lifrp++) {
- /*
- * Need a template to preserve address info that is
- * used below to locate the next entry. (Otherwise,
- * SIOCGLIFFLAGS stomps over it because the requests
- * are returned in a union.)
- */
- (void) strlcpy(lifr.lifr_name, lifrp->lifr_name,
- sizeof (lifr.lifr_name));
- if (ioctl(fd, SIOCGLIFFLAGS, (char *)&lifr) < 0) {
- if (errno == ENXIO) {
- continue;
- }
- (void) snprintf(errbuf, ERRBUFSIZE,
- "SIOCGLIFFLAGS: %.*s: %s",
- (int)sizeof (lifr.lifr_name), lifr.lifr_name,
- strerror(errno));
- free(ifaddrlist);
- free(ibuf);
- (void) close(fd);
- return (-1);
- }
-
- al->flags = lifr.lifr_flags;
-
- /* get the interface address */
- (void) strncpy(device, lifr.lifr_name, sizeof (device));
- device[sizeof (device) - 1] = '\0';
- if (ioctl(fd, SIOCGLIFADDR, (char *)&lifr) < 0) {
- (void) snprintf(errbuf, ERRBUFSIZE,
- "SIOCGLIFADDR: %s: %s", device, strerror(errno));
- free(ifaddrlist);
- free(ibuf);
- (void) close(fd);
- return (-1);
- }
-
- if (family == AF_INET) {
- sin = (struct sockaddr_in *)&lifr.lifr_addr;
- al->addr.addr = sin->sin_addr;
- } else {
- sin6 = (struct sockaddr_in6 *)&lifr.lifr_addr;
- al->addr.addr6 = sin6->sin6_addr;
- }
-
- (void) strlcpy(al->device, device, sizeof (device));
-
- /* get the interface index */
- if (ioctl(fd, SIOCGLIFINDEX, (char *)&lifr) < 0) {
- (void) snprintf(errbuf, ERRBUFSIZE,
- "SIOCGLIFADDR: %s: %s", device, strerror(errno));
- free(ifaddrlist);
- free(ibuf);
- (void) close(fd);
- return (-1);
- }
-
- al->index = lifr.lifr_index;
-
- ++al;
- ++count;
- }
-
- free(ibuf);
- (void) close(fd);
-
- *ipaddrp = ifaddrlist;
- return (count);
-}
diff --git a/usr/src/cmd/cmd-inet/common/ifaddrlist.h b/usr/src/cmd/cmd-inet/common/ifaddrlist.h
deleted file mode 100644
index d413aac289..0000000000
--- a/usr/src/cmd/cmd-inet/common/ifaddrlist.h
+++ /dev/null
@@ -1,63 +0,0 @@
-/*
- * Copyright (c) 1997 by Sun Microsystems, Inc.
- * All rights reserved.
- */
-
-
-/*
- * Copyright (c) 1997
- * The Regents of the University of California. All rights reserved.
- *
- * Redistribution and use in source and binary forms, with or without
- * modification, are permitted provided that: (1) source code distributions
- * retain the above copyright notice and this paragraph in its entirety, (2)
- * distributions including binary code include the above copyright notice and
- * this paragraph in its entirety in the documentation or other materials
- * provided with the distribution, and (3) all advertising materials mentioning
- * features or use of this software display the following acknowledgement:
- * ``This product includes software developed by the University of California,
- * Lawrence Berkeley Laboratory and its contributors.'' 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 ``AS IS'' AND WITHOUT ANY EXPRESS OR IMPLIED
- * WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
- * MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
- *
- * @(#) $Header: traceroute.h,v 1.1 97/01/04 19:33:33 leres Locked $ (LBL)
- */
-
-
-#ifndef _IFADDRLIST_H
-#define _IFADDRLIST_H
-
-#pragma ident "%Z%%M% %I% %E% SMI"
-
-#ifdef __cplusplus
-extern "C" {
-#endif
-
-#include <net/if.h>
-
-#define ERRBUFSIZE 128
-
-/* can store both IPv4 and IPv6 address */
-union any_in_addr {
- struct in6_addr addr6;
- struct in_addr addr;
-};
-
-struct ifaddrlist {
- int index; /* interface index */
- union any_in_addr addr; /* interface address */
- char device[LIFNAMSIZ + 1]; /* interface name */
- uint64_t flags; /* interface flags */
-};
-
-int ifaddrlist(struct ifaddrlist **, int, char *);
-
-#ifdef __cplusplus
-}
-#endif
-
-#endif /* _IFADDRLIST_H */
diff --git a/usr/src/cmd/cmd-inet/usr.sbin/ping/Makefile b/usr/src/cmd/cmd-inet/usr.sbin/ping/Makefile
index 47fb328f66..9a737a6f25 100644
--- a/usr/src/cmd/cmd-inet/usr.sbin/ping/Makefile
+++ b/usr/src/cmd/cmd-inet/usr.sbin/ping/Makefile
@@ -20,53 +20,37 @@
# CDDL HEADER END
#
#
-# Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+# Copyright 2006 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
# ident "%Z%%M% %I% %E% SMI"
#
PROG= ping
-PINGOBJS= ping.o ping_aux.o ping_aux6.o
-COMMONOBJS= ifaddrlist.o
-OBJS= $(PINGOBJS) $(COMMONOBJS)
-SUIDPROG= ping
+OBJS= ping.o ping_aux.o ping_aux6.o
+SRCS= $(OBJS:.o=.c)
include ../../../Makefile.cmd
-include ../../Makefile.cmd-inet
-
-PINGSRCS= $(PINGOBJS:.o=.c)
-COMMONSRCS= $(CMDINETCOMMONDIR)/$(COMMONOBJS:.o=.c)
-SRCS= $(PINGSRCS) $(COMMONSRCS)
-HDRS= ping.h $(CMDINETCOMMONDIR)/ifaddrlist.h
$(ROOTUSRSBIN)/ping := FILEMODE= 04555
$(ROOTUSRSBIN)/ping := OWNER= root
-
-CPPFLAGS += -I$(CMDINETCOMMONDIR)
-
# Ping uses the ancillary data feature which is available only through
# UNIX 98 standards version of Socket interface. This interface is supposed to
# be accessed by -lxnet. In addition -lsocket and -lnsl are used to
# capture new not-yet-standard interfaces. Someday -lxnet alone should be enough
# when IPv6 inspired new interfaces are part of standards.
-LDLIBS += -lxnet -lsocket -lnsl -lm
+LDLIBS += -lxnet -lsocket -lnsl -lm -linetutil
-# these #defines are required to use UNIX 98 interfaces
-_D_UNIX98_EXTN = -D_XOPEN_SOURCE=500 -D__EXTENSIONS__
-
-$(PINGOBJS) := CPPFLAGS += $(_D_UNIX98_EXTN)
-
-LINTFLAGS += $(_D_UNIX98_EXTN)
+# These #defines are required to use UNIX 98 interfaces
+CPPFLAGS += -D_XOPEN_SOURCE=500 -D__EXTENSIONS__
# Setting the above defines to use the UNIX98 ancillary data feature
# causes lint to output warnings about lint library declarations conflicting
# with those in the header files. Since we need these features the best
# course of action is to switch the types of the resulting warnings off
# when running lint.
-LINTFLAGS += -erroff=E_INCONS_VAL_TYPE_DECL2 -erroff=E_INCONS_ARG_DECL2 \
- -erroff=E_FUNC_DECL_VAR_ARG2
+LINTFLAGS += -erroff=E_INCONS_VAL_TYPE_DECL2 -erroff=E_INCONS_ARG_DECL2
.KEEP_STATE:
.PARALLEL:
@@ -77,9 +61,6 @@ $(PROG): $(OBJS)
$(LINK.c) -o $@ $(OBJS) $(LDLIBS)
$(POST_PROCESS)
-$(COMMONOBJS): $(COMMONSRCS)
- $(COMPILE.c) $(COMMONSRCS)
-
install: all $(ROOTUSRSBINPROG)
clean:
diff --git a/usr/src/cmd/cmd-inet/usr.sbin/ping/ping.c b/usr/src/cmd/cmd-inet/usr.sbin/ping/ping.c
index 8678b9530d..50fcd8e1c0 100644
--- a/usr/src/cmd/cmd-inet/usr.sbin/ping/ping.c
+++ b/usr/src/cmd/cmd-inet/usr.sbin/ping/ping.c
@@ -19,7 +19,7 @@
*
* CDDL HEADER END
*
- * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -71,7 +71,7 @@
#include <stdlib.h>
#include <priv_utils.h>
-#include <ifaddrlist.h>
+#include <libinetutil.h>
#include "ping.h"
/*
diff --git a/usr/src/cmd/cmd-inet/usr.sbin/ping/ping_aux.c b/usr/src/cmd/cmd-inet/usr.sbin/ping/ping_aux.c
index dae7a6e1fe..d76fae0aaf 100644
--- a/usr/src/cmd/cmd-inet/usr.sbin/ping/ping_aux.c
+++ b/usr/src/cmd/cmd-inet/usr.sbin/ping/ping_aux.c
@@ -20,7 +20,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -58,7 +58,7 @@
#include <netdb.h>
#include <stdlib.h>
-#include <ifaddrlist.h>
+#include <libinetutil.h>
#include "ping.h"
diff --git a/usr/src/cmd/cmd-inet/usr.sbin/ping/ping_aux6.c b/usr/src/cmd/cmd-inet/usr.sbin/ping/ping_aux6.c
index 29353b4af8..374c88fd1e 100644
--- a/usr/src/cmd/cmd-inet/usr.sbin/ping/ping_aux6.c
+++ b/usr/src/cmd/cmd-inet/usr.sbin/ping/ping_aux6.c
@@ -19,8 +19,8 @@
*
* CDDL HEADER END
*/
-/*
- * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+/*
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -60,7 +60,7 @@
#include <netdb.h>
#include <stdlib.h>
-#include <ifaddrlist.h>
+#include <libinetutil.h>
#include "ping.h"
void check_reply6(struct addrinfo *, struct msghdr *, int, ushort_t);
diff --git a/usr/src/cmd/cmd-inet/usr.sbin/ping/req.flg b/usr/src/cmd/cmd-inet/usr.sbin/ping/req.flg
deleted file mode 100644
index 19f083c41a..0000000000
--- a/usr/src/cmd/cmd-inet/usr.sbin/ping/req.flg
+++ /dev/null
@@ -1,29 +0,0 @@
-#!/bin/sh
-#
-# CDDL HEADER START
-#
-# The contents of this file are subject to the terms of the
-# Common Development and Distribution License, Version 1.0 only
-# (the "License"). You may not use this file except in compliance
-# with the License.
-#
-# You can obtain a copy of the license at usr/src/OPENSOLARIS.LICENSE
-# or http://www.opensolaris.org/os/licensing.
-# See the License for the specific language governing permissions
-# and limitations under the License.
-#
-# When distributing Covered Code, include this CDDL HEADER in each
-# file and include the License file at usr/src/OPENSOLARIS.LICENSE.
-# If applicable, add the following below this CDDL HEADER, with the
-# fields enclosed by brackets "[]" replaced with your own identifying
-# information: Portions Copyright [yyyy] [name of copyright owner]
-#
-# CDDL HEADER END
-#
-#pragma ident "%Z%%M% %I% %E% SMI"
-
-echo_file usr/src/cmd/cmd-inet/Makefile.cmd-inet
-echo_file usr/src/cmd/cmd-inet/common/Makefile
-echo_file usr/src/cmd/cmd-inet/common/ifaddrlist.c
-echo_file usr/src/cmd/cmd-inet/common/ifaddrlist.h
-
diff --git a/usr/src/cmd/cmd-inet/usr.sbin/traceroute/Makefile b/usr/src/cmd/cmd-inet/usr.sbin/traceroute/Makefile
index a8f2d2e491..c98dae83b0 100644
--- a/usr/src/cmd/cmd-inet/usr.sbin/traceroute/Makefile
+++ b/usr/src/cmd/cmd-inet/usr.sbin/traceroute/Makefile
@@ -1,5 +1,5 @@
#
-# Copyright 2003 Sun Microsystems, Inc. All rights reserved.
+# Copyright 2006 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
# ident "%Z%%M% %I% %E% SMI"
@@ -27,37 +27,23 @@
# @(#) $Header: Makefile.in,v 1.24 97/04/22 13:31:20 leres Exp $ (LBL)
PROG= traceroute
-TRACEROUTEOBJS= traceroute.o traceroute_aux.o traceroute_aux6.o
-COMMONOBJS= ifaddrlist.o
-OBJS= $(TRACEROUTEOBJS) $(COMMONOBJS)
-SUIDPROG= traceroute
+OBJS= traceroute.o traceroute_aux.o traceroute_aux6.o
+SRCS= $(OBJS:.o=.c)
include ../../../Makefile.cmd
-include ../../Makefile.cmd-inet
-
-TRACEROUTESRCS= $(TRACEROUTEOBJS:.o=.c)
-COMMONSRCS= $(CMDINETCOMMONDIR)/$(COMMONOBJS:.o=.c)
-SRCS= $(TRACEROUTESRCS) $(COMMONSRCS)
-HDRS= traceroute.h $(CMDINETCOMMONDIR)/ifaddrlist.h
$(ROOTUSRSBIN)/traceroute := FILEMODE= 04555
$(ROOTUSRSBIN)/traceroute := OWNER= root
-CPPFLAGS += -I$(CMDINETCOMMONDIR)
-
# Traceroute uses the ancillary data feature which is available only through
# UNIX 98 standards version of Socket interface. This interface is supposed to
# be accessed by -lxnet. In addition -lsocket and -lnsl are used to
# capture new not-yet-standard interfaces. Someday -lxnet alone should be enough
# when IPv6 inspired new interfaces are part of standards.
-LDLIBS += -lxnet -lsocket -lnsl
-
-# these #defines are required to use UNIX 98 interfaces
-_D_UNIX98_EXTN= -D_XOPEN_SOURCE=500 -D__EXTENSIONS__
+LDLIBS += -lxnet -lsocket -lnsl -linetutil
-$(TRACEROUTEOBJS) := CPPFLAGS += $(_D_UNIX98_EXTN)
-
-LINTFLAGS += $(_D_UNIX98_EXTN)
+# These #defines are required to use UNIX 98 interfaces
+CPPFLAGS += -D_XOPEN_SOURCE=500 -D__EXTENSIONS__
#
# Setting the above defines to use the UNIX98 ancillary data feature
@@ -77,9 +63,6 @@ $(PROG): $(OBJS)
$(LINK.c) -o $@ $(OBJS) $(LDLIBS)
$(POST_PROCESS)
-$(COMMONOBJS): $(COMMONSRCS)
- $(COMPILE.c) $(COMMONSRCS)
-
install: all $(ROOTUSRSBINPROG)
clean:
diff --git a/usr/src/cmd/cmd-inet/usr.sbin/traceroute/req.flg b/usr/src/cmd/cmd-inet/usr.sbin/traceroute/req.flg
deleted file mode 100644
index 91c08ee16f..0000000000
--- a/usr/src/cmd/cmd-inet/usr.sbin/traceroute/req.flg
+++ /dev/null
@@ -1,8 +0,0 @@
-#!/bin/sh
-#pragma ident "%Z%%M% %I% %E% SMI"
-
-echo_file usr/src/cmd/cmd-inet/Makefile.cmd-inet
-echo_file usr/src/cmd/cmd-inet/common/Makefile
-echo_file usr/src/cmd/cmd-inet/common/ifaddrlist.c
-echo_file usr/src/cmd/cmd-inet/common/ifaddrlist.h
-
diff --git a/usr/src/cmd/cmd-inet/usr.sbin/traceroute/traceroute.c b/usr/src/cmd/cmd-inet/usr.sbin/traceroute/traceroute.c
index 8c9f903ebc..b51fb0b062 100644
--- a/usr/src/cmd/cmd-inet/usr.sbin/traceroute/traceroute.c
+++ b/usr/src/cmd/cmd-inet/usr.sbin/traceroute/traceroute.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -66,8 +66,7 @@
#include <priv_utils.h>
-
-#include <ifaddrlist.h>
+#include <libinetutil.h>
#include "traceroute.h"
#define MAX_SEQ 65535 /* max sequence value for ICMP */
diff --git a/usr/src/cmd/cmd-inet/usr.sbin/traceroute/traceroute_aux.c b/usr/src/cmd/cmd-inet/usr.sbin/traceroute/traceroute_aux.c
index 3c5fce7a9b..2f4dc04838 100644
--- a/usr/src/cmd/cmd-inet/usr.sbin/traceroute/traceroute_aux.c
+++ b/usr/src/cmd/cmd-inet/usr.sbin/traceroute/traceroute_aux.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -49,7 +49,7 @@
#include <arpa/inet.h>
#include <netdb.h>
-#include <ifaddrlist.h>
+#include <libinetutil.h>
#include "traceroute.h"
/*
diff --git a/usr/src/cmd/cmd-inet/usr.sbin/traceroute/traceroute_aux6.c b/usr/src/cmd/cmd-inet/usr.sbin/traceroute/traceroute_aux6.c
index b610aceac3..ecd985dbf8 100644
--- a/usr/src/cmd/cmd-inet/usr.sbin/traceroute/traceroute_aux6.c
+++ b/usr/src/cmd/cmd-inet/usr.sbin/traceroute/traceroute_aux6.c
@@ -1,5 +1,5 @@
/*
- * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -52,7 +52,7 @@
#include <arpa/inet.h>
-#include <ifaddrlist.h>
+#include <libinetutil.h>
#include "traceroute.h"
int check_reply6(struct msghdr *, int, int, uchar_t *, uchar_t *);
diff --git a/usr/src/cmd/rcm_daemon/Makefile.com b/usr/src/cmd/rcm_daemon/Makefile.com
index f513993c04..399dab44be 100644
--- a/usr/src/cmd/rcm_daemon/Makefile.com
+++ b/usr/src/cmd/rcm_daemon/Makefile.com
@@ -20,7 +20,7 @@
# CDDL HEADER END
#
#
-# Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+# Copyright 2006 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
# ident "%Z%%M% %I% %E% SMI"
@@ -29,7 +29,6 @@
include ../../Makefile.cmd
COMMON = ../common
-CMDINETCOMMON = $(SRC)/cmd/cmd-inet/common
RCM_SRC = \
$(COMMON)/rcm_event.c \
@@ -99,7 +98,7 @@ CLOBBERFILES = $(COMMON_RCM_MODS) $($(MACH)_RCM_MODS) $(RCM_DAEMON)
LINT_MODULES = $(COMMON_MOD_SRC:.c=.ln) $($(MACH)_MOD_SRC:.c=.ln)
-CPPFLAGS += -I.. -I $(CMDINETCOMMON)
+CPPFLAGS += -I..
CPPFLAGS += -D_POSIX_PTHREAD_SEMANTICS -D_REENTRANT
CFLAGS += $(CCVERBOSE) $(C_PICFLAGS)
@@ -110,6 +109,7 @@ SUNW_pool_rcm.so := LDLIBS_MODULES += -L$(ROOT)/usr/lib -lpool
SUNW_svm_rcm.so := LDLIBS_MODULES += -L$(ROOT)/usr/lib -lmeta
SUNW_network_rcm.so := LDLIBS_MODULES += -L$(ROOT)/lib -llaadm
SUNW_ip_rcm.so := LDLIBS_MODULES += -L$(ROOT)/lib -linetutil
+SUNW_ip_anon_rcm.so := LDLIBS_MODULES += -L$(ROOT)/lib -linetutil
LDLIBS += -lgen -lelf -lcmd -lrcm -lnvpair -ldevinfo -lnsl -lsocket -lrt
diff --git a/usr/src/cmd/rcm_daemon/common/ip_anon_rcm.c b/usr/src/cmd/rcm_daemon/common/ip_anon_rcm.c
index cb35558622..35fb7b8171 100644
--- a/usr/src/cmd/rcm_daemon/common/ip_anon_rcm.c
+++ b/usr/src/cmd/rcm_daemon/common/ip_anon_rcm.c
@@ -20,7 +20,7 @@
* CDDL HEADER END
*/
/*
- * Copyright 2002-2003 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -58,9 +58,9 @@
#include <netinet/ip6.h>
#include <inet/ip.h>
#include <inet/ip6.h>
+#include <libinetutil.h>
#include "rcm_module.h"
-#include "ifaddrlist.h"
#define SUNW_IP "SUNW_ip/"
#define IP_REG_SIZE (9 + INET6_ADDRSTRLEN)
@@ -163,7 +163,7 @@ ip_anon_register(rcm_handle_t *hdl)
{
int bootflags;
struct ifaddrlist *al = NULL, *al6 = NULL;
- char errbuf[ERRBUFSIZE] = "", errbuf6[ERRBUFSIZE] = "";
+ char errbuf[ERRBUFSIZE];
char treg[IP_REG_SIZE], tstr[IP_REG_SIZE];
cladm_netaddrs_t exclude_addrs;
int num_ifs, num_ifs6, i, ret;
@@ -271,20 +271,15 @@ ip_anon_register(rcm_handle_t *hdl)
}
}
-
-
/* obtain a list of all IPv4 and IPv6 addresses in the system */
rcm_log_message(RCM_DEBUG,
"ip_anon: obtaining list of IPv4 addresses.\n");
num_ifs = ifaddrlist(&al, AF_INET, errbuf);
-
- if ((num_ifs == -1) && (errno != 0) && (errno != ENOENT) &&
- (errno != EINVAL)) {
+ if (num_ifs == -1) {
rcm_log_message(RCM_ERROR,
gettext("cannot get IPv4 address list errno=%d (%s)\n"),
errno, errbuf);
- free(al);
(void) mutex_unlock(&ip_list_lock);
return (RCM_FAILURE);
}
@@ -292,14 +287,12 @@ ip_anon_register(rcm_handle_t *hdl)
rcm_log_message(RCM_DEBUG,
"ip_anon: obtaining list of IPv6 addresses.\n");
- num_ifs6 = ifaddrlist(&al6, AF_INET6, errbuf6);
- if ((num_ifs6 == -1) && (errno != 0) && (errno != ENOENT) &&
- (errno != EINVAL)) {
+ num_ifs6 = ifaddrlist(&al6, AF_INET6, errbuf);
+ if (num_ifs6 == -1) {
rcm_log_message(RCM_ERROR,
gettext("cannot get IPv6 address list errno=%d (%s)\n"),
- errno, errbuf6);
+ errno, errbuf);
free(al);
- free(al6);
(void) mutex_unlock(&ip_list_lock);
return (RCM_FAILURE);
}
@@ -704,198 +697,3 @@ exclude_ipv6(cladm_netaddrs_t exclude_addrs, uint32_t address[4])
taddr);
return (0);
}
-
-/*
- * The code below is taken from usr/src/cmd/cmd-inet/common/ifaddrlist.c
- */
-
-/*
- * Copyright (c) 1997
- * The Regents of the University of California. 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 Computer Systems
- * Engineering Group at Lawrence Berkeley Laboratory.
- * 4. Neither the name of the University nor of the Laboratory 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
- * 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
- * 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)
- * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
- * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
- * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
- * SUCH DAMAGE.
- *
- */
-
-/*
- * Construct the interface list with given address family.
- * If it fails, returns -1 and an error message in *errbuf;
- * otherwise, returns number of interfaces, and the interface list in *ipaddrp.
- */
-int
-ifaddrlist(struct ifaddrlist **ipaddrp, int family, char *errbuf)
-{
- int fd;
- struct lifreq *lifrp, *lifend;
- struct sockaddr_in *sin;
- struct sockaddr_in6 *sin6;
- struct ifaddrlist *al;
- struct lifconf lifc;
- struct lifreq *ibuf, lifr;
- char device[LIFNAMSIZ + 1];
- struct ifaddrlist *ifaddrlist;
- struct lifnum lifn;
- int lifc_flags = 0;
- int count;
-
- if (family != AF_INET && family != AF_INET6) {
- (void) sprintf(errbuf, "invalid address family");
- return (-1);
- }
-
- fd = socket(family, SOCK_DGRAM, 0);
- if (fd < 0) {
- (void) snprintf(errbuf, ERRBUFSIZE, "socket: %s",
- strerror(errno));
- return (-1);
- }
-
- /* determine the number of interfaces */
- lifn.lifn_family = family;
- lifn.lifn_flags = lifc_flags;
- if (ioctl(fd, SIOCGLIFNUM, &lifn) < 0) {
- (void) snprintf(errbuf, ERRBUFSIZE, "SIOCGLIFNUM: %s",
- strerror(errno));
- (void) close(fd);
- return (-1);
- }
-
- /* allocate memory for the determined number of interfaces */
- ifaddrlist = calloc((size_t)lifn.lifn_count,
- (size_t)sizeof (struct ifaddrlist));
- if (ifaddrlist == NULL) {
- (void) snprintf(errbuf, ERRBUFSIZE, "calloc: %s",
- strerror(errno));
- (void) close(fd);
- return (-1);
- }
-
- ibuf = calloc((size_t)lifn.lifn_count, (size_t)sizeof (struct lifreq));
- if (ibuf == NULL) {
- (void) snprintf(errbuf, ERRBUFSIZE, "calloc: %s",
- strerror(errno));
- free(ifaddrlist);
- (void) close(fd);
- return (-1);
- }
-
- /* pull out the interface list from the kernel */
- lifc.lifc_family = family;
- lifc.lifc_len = (int)(lifn.lifn_count * sizeof (struct lifreq));
- lifc.lifc_buf = (caddr_t)ibuf;
- lifc.lifc_flags = lifc_flags;
-
- if (ioctl(fd, SIOCGLIFCONF, (char *)&lifc) < 0 ||
- lifc.lifc_len < sizeof (struct lifreq)) {
- (void) snprintf(errbuf, ERRBUFSIZE, "SIOCGLIFCONF: %s",
- strerror(errno));
- free(ifaddrlist);
- free(ibuf);
- (void) close(fd);
- return (-1);
- }
-
- lifrp = ibuf;
- /*LINTED*/
- lifend = (struct lifreq *)((char *)ibuf + lifc.lifc_len);
-
- al = ifaddrlist;
- count = 0;
-
- /* let's populate the interface entries in the ifaddrlist */
- for (; lifrp < lifend; lifrp++) {
- /*
- * Need a template to preserve address info that is
- * used below to locate the next entry. (Otherwise,
- * SIOCGLIFFLAGS stomps over it because the requests
- * are returned in a union.)
- */
- (void) strncpy(lifr.lifr_name, lifrp->lifr_name,
- sizeof (lifr.lifr_name));
- if (ioctl(fd, SIOCGLIFFLAGS, (char *)&lifr) < 0) {
- if (errno == ENXIO) {
- continue;
- }
- (void) snprintf(errbuf, ERRBUFSIZE,
- "SIOCGLIFFLAGS: %.*s: %s",
- (int)sizeof (lifr.lifr_name), lifr.lifr_name,
- strerror(errno));
- free(ifaddrlist);
- free(ibuf);
- (void) close(fd);
- return (-1);
- }
-
- al->flags = lifr.lifr_flags;
-
- /* get the interface address */
- (void) strncpy(device, lifr.lifr_name, sizeof (device));
- device[sizeof (device) - 1] = '\0';
- if (ioctl(fd, SIOCGLIFADDR, (char *)&lifr) < 0) {
- (void) snprintf(errbuf, ERRBUFSIZE,
- "SIOCGLIFADDR: %s: %s", device, strerror(errno));
- free(ifaddrlist);
- free(ibuf);
- (void) close(fd);
- return (-1);
- }
-
- if (family == AF_INET) {
- sin = (struct sockaddr_in *)&lifr.lifr_addr;
- al->addr.addr = sin->sin_addr;
- } else {
- sin6 = (struct sockaddr_in6 *)&lifr.lifr_addr;
- al->addr.addr6 = sin6->sin6_addr;
- }
-
- (void) strncpy(al->device, device, sizeof (device));
-
- /* get the interface index */
- if (ioctl(fd, SIOCGLIFINDEX, (char *)&lifr) < 0) {
- (void) snprintf(errbuf, ERRBUFSIZE,
- "SIOCGLIFADDR: %s: %s", device, strerror(errno));
- free(ifaddrlist);
- free(ibuf);
- (void) close(fd);
- return (-1);
- }
-
- al->index = lifr.lifr_index;
-
- ++al;
- ++count;
- }
-
- free(ibuf);
- (void) close(fd);
-
- *ipaddrp = ifaddrlist;
-
- return (count);
-}
diff --git a/usr/src/lib/libinetutil/Makefile.com b/usr/src/lib/libinetutil/Makefile.com
index 0606c1dcff..d9e592c2df 100644
--- a/usr/src/lib/libinetutil/Makefile.com
+++ b/usr/src/lib/libinetutil/Makefile.com
@@ -20,7 +20,7 @@
# CDDL HEADER END
#
#
-# Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+# Copyright 2006 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
# ident "%Z%%M% %I% %E% SMI"
@@ -28,7 +28,7 @@
LIBRARY = libinetutil.a
VERS = .1
-OBJECTS = octet.o inetutil4.o ifspec.o eh.o tq.o
+OBJECTS = octet.o inetutil4.o ifspec.o ifaddrlist.o eh.o tq.o
include ../../Makefile.lib
@@ -38,7 +38,8 @@ include ../../Makefile.rootfs
LIBS = $(DYNLIB) $(LINTLIB)
SRCS = $(COMDIR)/octet.c $(SRCDIR)/inetutil4.c \
- $(SRCDIR)/ifspec.c $(SRCDIR)/eh.c $(SRCDIR)/tq.c
+ $(SRCDIR)/ifspec.c $(SRCDIR)/eh.c $(SRCDIR)/tq.c \
+ $(SRCDIR)/ifaddrlist.c
$(LINTLIB):= SRCS = $(SRCDIR)/$(LINTSRC)
LDLIBS += -lsocket -lc
diff --git a/usr/src/lib/libinetutil/common/ifaddrlist.c b/usr/src/lib/libinetutil/common/ifaddrlist.c
new file mode 100644
index 0000000000..383dc2afb0
--- /dev/null
+++ b/usr/src/lib/libinetutil/common/ifaddrlist.c
@@ -0,0 +1,192 @@
+/*
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
+ * Use is subject to license terms.
+ */
+
+/*
+ * Copyright (c) 1997
+ * The Regents of the University of California. 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 Computer Systems
+ * Engineering Group at Lawrence Berkeley Laboratory.
+ * 4. Neither the name of the University nor of the Laboratory 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
+ * 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
+ * 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)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT
+ * LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY
+ * OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED OF THE POSSIBILITY OF
+ * SUCH DAMAGE.
+ *
+ * @(#) $Header: ifaddrlist.c,v 1.2 97/04/22 13:31:05 leres Exp $ (LBL)
+ */
+
+#pragma ident "%Z%%M% %I% %E% SMI"
+
+#include <alloca.h>
+#include <errno.h>
+#include <libinetutil.h>
+#include <stdio.h>
+#include <stdlib.h>
+#include <string.h>
+#include <unistd.h>
+#include <sys/socket.h>
+#include <sys/sockio.h>
+
+/*
+ * See <libinetutil.h> for a description of the programming interface.
+ */
+int
+ifaddrlist(struct ifaddrlist **ipaddrp, int family, char *errbuf)
+{
+ struct ifaddrlist *ifaddrlist, *al;
+ struct sockaddr_in *sin;
+ struct sockaddr_in6 *sin6;
+ struct lifconf lifc;
+ struct lifnum lifn;
+ struct lifreq *lifrp;
+ int i, count, nlifr;
+ int fd;
+ const char *iocstr;
+
+ if (family != AF_INET && family != AF_INET6) {
+ (void) strlcpy(errbuf, "invalid address family", ERRBUFSIZE);
+ return (-1);
+ }
+
+ fd = socket(family, SOCK_DGRAM, 0);
+ if (fd == -1) {
+ (void) snprintf(errbuf, ERRBUFSIZE, "socket: %s",
+ strerror(errno));
+ return (-1);
+ }
+
+ /*
+ * Get the number of network interfaces of type `family'.
+ */
+ lifn.lifn_family = family;
+ lifn.lifn_flags = 0;
+again:
+ if (ioctl(fd, SIOCGLIFNUM, &lifn) == -1) {
+ (void) snprintf(errbuf, ERRBUFSIZE, "SIOCGLIFNUM: %s",
+ strerror(errno));
+ (void) close(fd);
+ return (-1);
+ }
+
+ /*
+ * Pad the interface count to detect when additional interfaces have
+ * been configured between SIOCGLIFNUM and SIOCGLIFCONF.
+ */
+ lifn.lifn_count += 4;
+
+ lifc.lifc_family = family;
+ lifc.lifc_len = lifn.lifn_count * sizeof (struct lifreq);
+ lifc.lifc_buf = alloca(lifc.lifc_len);
+ lifc.lifc_flags = 0;
+
+ if (ioctl(fd, SIOCGLIFCONF, &lifc) == -1) {
+ (void) snprintf(errbuf, ERRBUFSIZE, "SIOCGLIFCONF: %s",
+ strerror(errno));
+ (void) close(fd);
+ return (-1);
+ }
+
+ /*
+ * If every lifr_req slot is taken, then additional interfaces must
+ * have been plumbed between the SIOCGLIFNUM and the SIOCGLIFCONF.
+ * Recalculate to make sure we didn't miss any interfaces.
+ */
+ nlifr = lifc.lifc_len / sizeof (struct lifreq);
+ if (nlifr >= lifn.lifn_count)
+ goto again;
+
+ /*
+ * Allocate the address list to return.
+ */
+ ifaddrlist = calloc(nlifr, sizeof (struct ifaddrlist));
+ if (ifaddrlist == NULL) {
+ (void) snprintf(errbuf, ERRBUFSIZE, "calloc: %s",
+ strerror(errno));
+ (void) close(fd);
+ return (-1);
+ }
+
+ /*
+ * Populate the address list by querying each underlying interface.
+ * If a query ioctl returns ENXIO, then the interface must have been
+ * removed after the SIOCGLIFCONF completed -- so we just ignore it.
+ */
+ al = ifaddrlist;
+ count = 0;
+ for (lifrp = lifc.lifc_req, i = 0; i < nlifr; i++, lifrp++) {
+ (void) strlcpy(al->device, lifrp->lifr_name, LIFNAMSIZ);
+
+ if (ioctl(fd, SIOCGLIFFLAGS, lifrp) == -1) {
+ if (errno == ENXIO)
+ continue;
+ iocstr = "SIOCGLIFFLAGS";
+ goto fail;
+ }
+ al->flags = lifrp->lifr_flags;
+
+ if (ioctl(fd, SIOCGLIFINDEX, lifrp) == -1) {
+ if (errno == ENXIO)
+ continue;
+ iocstr = "SIOCGLIFINDEX";
+ goto fail;
+ }
+ al->index = lifrp->lifr_index;
+
+ if (ioctl(fd, SIOCGLIFADDR, lifrp) == -1) {
+ if (errno == ENXIO)
+ continue;
+ iocstr = "SIOCGLIFADDR";
+ goto fail;
+ }
+
+ if (family == AF_INET) {
+ sin = (struct sockaddr_in *)&lifrp->lifr_addr;
+ al->addr.addr = sin->sin_addr;
+ } else {
+ sin6 = (struct sockaddr_in6 *)&lifrp->lifr_addr;
+ al->addr.addr6 = sin6->sin6_addr;
+ }
+ al++;
+ count++;
+ }
+
+ (void) close(fd);
+ if (count == 0) {
+ free(ifaddrlist);
+ *ipaddrp = NULL;
+ return (0);
+ }
+
+ *ipaddrp = ifaddrlist;
+ return (count);
+fail:
+ (void) snprintf(errbuf, ERRBUFSIZE, "%s: %s: %s", iocstr, al->device,
+ strerror(errno));
+
+ free(ifaddrlist);
+ (void) close(fd);
+ return (-1);
+}
diff --git a/usr/src/lib/libinetutil/common/libinetutil.h b/usr/src/lib/libinetutil/common/libinetutil.h
index 0213a23aa2..b21d54f56c 100644
--- a/usr/src/lib/libinetutil/common/libinetutil.h
+++ b/usr/src/lib/libinetutil/common/libinetutil.h
@@ -19,8 +19,9 @@
*
* CDDL HEADER END
*/
+
/*
- * Copyright 2004 Sun Microsystems, Inc. All rights reserved.
+ * Copyright 2006 Sun Microsystems, Inc. All rights reserved.
* Use is subject to license terms.
*/
@@ -30,7 +31,7 @@
#pragma ident "%Z%%M% %I% %E% SMI"
/*
- * Contains SMI-private API for general internet functionality
+ * Contains SMI-private API for general Internet functionality
*/
#ifdef __cplusplus
@@ -60,6 +61,39 @@ extern boolean_t ifparse_ifspec(const char *, ifspec_t *);
extern void get_netmask4(const struct in_addr *, struct in_addr *);
/*
+ * Extended version of the classic BSD ifaddrlist() interface:
+ *
+ * int ifaddrlist(struct ifaddrlist **addrlistp, int af, char *errbuf);
+ *
+ * * addrlistp: Upon success, ifaddrlist() sets *addrlistp to a
+ * dynamically-allocated array of addresses.
+ *
+ * * af: Either AF_INET to obtain IPv4 addresses, or AF_INET6 to
+ * obtain IPv6 addresses.
+ *
+ * * errbuf: A caller-supplied buffer of ERRBUFSIZE. Upon failure,
+ * provides the reason for the failure.
+ *
+ * Upon success, ifaddrlist() returns the number of addresses in the array
+ * pointed to by `addrlistp'. If the count is 0, then `addrlistp' is NULL.
+ */
+union any_in_addr {
+ struct in6_addr addr6;
+ struct in_addr addr;
+};
+
+struct ifaddrlist {
+ int index; /* interface index */
+ union any_in_addr addr; /* interface address */
+ char device[LIFNAMSIZ + 1]; /* interface name */
+ uint64_t flags; /* interface flags */
+};
+
+#define ERRBUFSIZE 128 /* expected size of third argument */
+
+extern int ifaddrlist(struct ifaddrlist **, int, char *);
+
+/*
* Timer queues
*
* timer queues are a facility for managing timeouts in unix. in the
diff --git a/usr/src/lib/libinetutil/spec/inetutil.spec b/usr/src/lib/libinetutil/spec/inetutil.spec
index 33f4a27aff..25741fd0ef 100644
--- a/usr/src/lib/libinetutil/spec/inetutil.spec
+++ b/usr/src/lib/libinetutil/spec/inetutil.spec
@@ -1,5 +1,5 @@
#
-# Copyright 2005 Sun Microsystems, Inc. All rights reserved.
+# Copyright 2006 Sun Microsystems, Inc. All rights reserved.
# Use is subject to license terms.
#
# CDDL HEADER START
@@ -52,6 +52,12 @@ declaration void get_netmask4(const struct in_addr *np, struct in_addr *sp)
version SUNWprivate_1.1
end
+function ifaddrlist
+include <libinetutil.h>
+declaration int ifaddrlist(struct ifaddrlist **, int, char *);
+version SUNWprivate_1.1
+end
+
function ifparse_ifspec
include <libinetutil.h>
declaration boolean_t ifparse_ifspec(const char *ifname, ifspec_t *ifsp)