#!/bin/sh

# Shell script to collect network data.
# Copyright (C) 2001-2004 Open Challenge B.V.
# Copyright (C) 2004 OpenEyeT Professional Services.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2, or (at your option)
# any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; see the file COPYING.
# If not, write to the Free Software Foundation,
# 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
#
# Contact information: www.OpenEyeT.nl/scc/index.html 

# This is a system module of scc, to call it separately in the
# proper environment, use: scc-collect -i -e <module_name>

# SCC-release:	1.6.26
# file-version:	$Revision: 1.36 $
 
. ${SCC_BIN}/scc_modules/scc_utils

if [ -x /usr/bin/what -a -f /usr/conf/lib/liblan.a ]
then
	what /usr/conf/lib/liblan.a					|
	sed -e 's@^@fix:network:Core-lan /usr/conf/lib/liblan.a::@'
fi

lines=$(grep -c [g]ated ${PROC_FILE})
if [ ${lines} -ge 1 ]
then
	echo "fix:network:gated::status:	active"
else
	echo "fix:network:gated::status:	inactive"
fi
scc_check_file /etc/gated.conf "fix:network:gated::/etc/gated.conf:	" "#"

for file in	/etc/bootptab			\
		/etc/defaultdomain		\
		/etc/defaultrouter		\
		/etc/dhclient.conf		\
		/etc/dhcpd.conf			\
		/etc/dhcptab			\
		/etc/dhcpd.interfaces		\
		/etc/ethers			\
		/etc/gateways			\
		/etc/hosts			\
		/etc/host.conf			\
		/etc/hosts.equiv		\
		/etc/ifaccess.conf		\
		/etc/ifaliases			\
		/etc/ifp.conf			\
		/etc/ifp6.conf			\
		/etc/ipnat.conf			\
		/etc/ipsec.conf			\
		/etc/mrouted.conf		\
		/etc/myname			\
		/etc/mygate			\
		/etc/netconfig			\
		/etc/netgroup			\
		/etc/netmasks			\
		/etc/nettlgen.conf		\
		/etc/network/interfaces		\
		/etc/network/options		\
		/etc/networks			\
		/etc/nsswitch.conf		\
		/etc/nscd.conf			\
		/etc/protocols			\
		/etc/rbootd.conf		\
		/etc/route.conf			\
		/etc/routes			\
		/etc/rpc			\
		/etc/rpld.conf			\
		/etc/rsh.allow			\
		/etc/sysctl.cfg			\
		/etc/svc.conf			\
		/etc/telnet.conf		\
		/var/adm/inetd.sec
do
	scc_check_file "${file}" "fix:network:file:${file}::" "#"

	if [ ${IS_NIS_MASTER} -eq 1 -a "${NIS_DATA_DIR}" != "/etc" ]
	then
		nis_file="${NIS_DATA_DIR}/$(basename ${file})"
		scc_check_file "${nis_file}" "fix:network:file:${nis_file}::" "#"
	fi
done

# Border Gateway Protocol Daemon
bgpd_conf=$(sed -n -e 's/.*bgpd .*-f *//p' ${PROC_FILE})
bgpd_conf=${bgpd_conf%% *}
bgpd_conf=${bgpd_conf:-/etc/bgpd.conf}		# Default config file.
scc_check_file ${bgpd_conf} "fix:network:file:${bgpd_conf}::" "#"

if [ -f /etc/notrouter ]
then
	echo "fix:network:file:/etc/notrouter::1"
fi

if [ ! -h /etc/hosts ]
then
	scc_check_file /etc/inet/hosts "fix:network:file:/etc/inet/hosts::" "#"
fi

sun_snmp_file=""
if [ "${OS_NAME}" = "SunOS" ]
then
	dir=$(sed -n -e 's/.*snmpdx .*-c *//p' ${PROC_FILE})
	dir=${dir%% *}
	dir=${dir:-/etc/snmp/conf}
	sun_snmp_file=${dir}/snmpd.conf

	for f in mibiisa.reg mibiisa.rsrc snmpdx.reg snmpdx.rsrc snmpdx.acl
	do
		scc_check_file "${dir}/${f}" "fix:network:file:${dir}/${f}::" "#"
	done
fi

# Avoid the clear-text community-names to appear in the snapshots.
rm -f ${TMP1_FILE}
for file in     /etc/snmpd.conf ${sun_snmp_file}	\
		/etc/snmp/snmpd.conf			\
                /etc/SnmpAgent.d/snmpd.conf
do
        if [ ! -f ${file} -o -h ${file} ]
        then
                continue
        fi

	prefix="fix:network:file:${file}::"
	# Communitynames are sensitive information, therefore we crypt them.
	sed	-e '/^#/d'			\
		-e 's/[ 	]*#.*//'	\
		-e '/^[ 	]*$/d' ${file}			|
	while read key data
	do
		case "${key}" in
		trap-community)	echo "${prefix}${key}	${data}";;
		*community*)	if [ -n "${data}" ]
				then
					echo "${prefix}${key}	$(echo "${key} ${data}" | scc_crypt )"
				else
					echo "${prefix}${key}	# No access"
				fi;;
		*)		echo "${prefix}${key}	${data}";;
		esac
	done
done

scc_check_file /etc/services "fix:network:file:/etc/services::" "#"		|
sort -k 2n
if [ ${IS_NIS_MASTER} -eq 1 -a "${NIS_DATA_DIR}" != "/etc" ]
then
	scc_check_file "${NIS_DATA_DIR}/services" "fix:network:file:${NIS_DATA_DIR}/services::" "#"
fi

for file in	/etc/ftp-banner			\
		/etc/ftpaccess			\
		/etc/ftpchroot			\
		/etc/ftpconversions		\
		/etc/ftpgroups			\
		/etc/ftpchroot			\
		/etc/ftphosts			\
		/etc/ftpusers			\
		/etc/ftpwelcome			\
		/etc/ftpd/ftpusers		\
		/etc/proftpd.conf		\
		/etc/ftpd.conf			\
		/etc/vsftpd.conf		\
		/etc/iptos			\
		/usr/local/etc/proftpd.conf
do
	scc_check_file "${file}" "fix:network:ftp:${file}::" "#"
done

# In case the default config file for vsftpd is not used:
{
	sed -n -e '/.*server_args.*-f[ 	]*//p' /etc/xinetd.d/vsftp* 2>/dev/null
	sed -n -e '/.*vsftpd.*vsftpd[ 	]*.*-f[ 	]*//p' /etc/inetd.conf 2>/dev/null
}					|
while read file remainder
do
	scc_check_file "${file}" "fix:network:ftp:${file}::" "#"
done

# Record ports that are listened on. Select only the ports that are
# present in the file /etc/services.
sed	-e '/^[ 	]*$/d'	\
	-e '/^#/d'		\
	-e 's@/.*@@'		\
		/etc/services 2>/dev/null	|
awk '{ if ( NF == 2 ) print }' >${TMP1_FILE}

netstat -an 2>/dev/null				|
awk '/^tcp.*LISTEN *$/	{ i=4; work=1 }
	/^ .*LISTEN *$/	{ i=1; work=1 }
	{
		if ( ! work )
		{
			next;
		}
		cnt=split( $i, parts, ":" );
		if ( cnt == 2 )
		{
			print parts[ 2 ];
		}
		else
		{
			cnt=split( $i, parts, "." );
			print parts[ 2 ];
		}
		work=0;
	}'				|
sort -u					|
awk '{
	if ( NF == 2 )
	{
		service[ $2 ] = $1;
	}
	else
	{
		if ( length( service[ $1 ] ) > 0 )
		{
			print "fix", service[ $1 ], $1;
		}
		else
		{
			print "var", $1, $1
		}
	}
}' ${TMP1_FILE} -			|
sort -k 3n				|
sed	-e 's/^fix /fix:network:ports::/'	\
	-e 's/^var /var:network:ports::/'

rm -f ${TMP1_FILE}

if [ -x /sbin/mii-tool ]
then
	/sbin/mii-tool -v 2>/dev/null		|
	sed -e 's/^/fix:network:media independant interface status::/'
fi

if [ -x /usr/bin/ipcs ]
then
	# The output of ipcs changes frequently. Treat it as variable.

	extra_options=""
	if [ "${OS_NAME}" = "HP-UX" -o "${OS_NAME}" = "SunOS" ]
	then
		extra_options="-a"
	fi

	ipcs -m ${extra_options}			|
	sed	-e '/^ *$/d'		\
		-e 's/^/var:network:ipcs::shared-memory:	/'

	ipcs -q ${extra_options}			|
	sed	-e '/^ *$/d'		\
		-e 's/^/var:network:ipcs::message-queue:	/'

	ipcs -s ${extra_options}			|
	sed	-e '/^ *$/d'		\
		-e 's/^/var:network:ipcs::semaphores:		/'
fi

nslookup $(hostname) 2>/dev/null			|
sed	-e '/^[ 	]*$/d'			\
	-e '/authoritative answer/d'		\
	-e 's/^/fix:network:DNS::nslookup:	/'

# Maarten de Boer and Nico van Royen provided some NIS-background.
is_slave_server=0
is_client=0
if [ ${IS_NIS_MASTER} -eq 0 ]
then
	is_slave_server="$(grep -l ypserv ${PROC_FILE} >/dev/null 2>/dev/null; echo $(( 1 - $? )) )"
	if [ "${is_slave_server}" -eq 0 ]
	then
		is_client="$(grep -l ypbind ${PROC_FILE} >/dev/null 2>/dev/null; echo $(( 1 - $? )) )"
	fi
else
	echo "fix:network:NIS:general::data-directory:		${NIS_DATA_DIR}"
fi

NIS_DOMAIN="$(domainname 2>/dev/null)"
NIS_MASTER=""
if [ ${is_client} -eq 1 -o ${is_slave_server} -eq 1 ]
then
	NIS_MASTER="$(ypwhich 2>/dev/null)"
fi
echo "fix:network:NIS:general::domain:		${NIS_DOMAIN}"
echo "fix:network:NIS:general::binding:		${NIS_MASTER}"

echo "fix:network:NIS:general::is-master-server:	${IS_NIS_MASTER}"
echo "fix:network:NIS:general::is-slave-server:		${is_slave_server}"
echo "fix:network:NIS:general::is-client:		${is_client}"

scc_check_file "/var/yp/binding/${NIS_DOMAIN}/ypservers" "fix:network:NIS:binding ${NIS_DOMAIN} ypservers::" "#"
scc_check_file /etc/yp.conf "fix:network:NIS:binding /etc/yp.conf::" "#"
scc_check_file /var/yp/securenets "fix:network:NIS:/var/yp/securenets::" "#"

if [ -f /etc/publickey ]
then
	# Ignore comment and blank lines. Also erase the private key.
	sed	-e '/^#/d'		\
		-e '/^[ 	]*$/d'	\
		-e 's/:.*//'		\
		-e 's@^@fix:network:NIS:/etc/publickey::@' /etc/publickey
fi

if [ -x /usr/bin/ypwhich ]
then
	ypwhich -x 2>/dev/null		|
	sed -e 's/^/var:network:NIS:nicknames::/'

	if [ ${is_client} -gt 0 -o ${is_slave_server} -gt 0 ]
	then
		ypwhich -m 2>/dev/null		|
		sed -e 's/^/var:network:NIS:maps::/'
	fi
fi

config=""
key=""
if [ -f /etc/rc.config.d/netdaemons ]
then
	. /etc/rc.config.d/netdaemons
	if [ "${XNTPD_ARGS}" != "" ]
	then
		config=$(echo "${XNTPD_ARGS}" | sed -e 's/.*-c[ ]*//' -e 's/ .*//')
		key=$(echo "${XNTPD_ARGS}" | sed -e 's/.*-k[ ]*//' -e 's/ .*//')
	fi
else
	config="$(sed -n -e 's/.*xntpd.* -c[ ]*//p' ${PROC_FILE})"
	config="${config% *}"
fi
if [ ! -f "${config}" ]
then
	if [ -f /etc/ntp.conf ]
	then
		config=/etc/ntp.conf
	elif [ -f /etc/inet/ntp.conf ]
	then
		config=/etc/inet/ntp.conf
	else
		config=""
	fi
fi
if [ "${config}" != "" ]
then
	scc_check_file "${config}" "fix:network:ntp:${config}::" "#"

	if [ ! -f "${key}" ]
	then
		key=$(awk '/^keys/ { print $2 }' ${config})
	fi

	if [ "${key}" ]
	then
		scc_check_file "${key}" "fix:network:ntp:${key}::" "#"
	fi
fi
if [ -x /usr/sbin/ntpq ]
then
	ntpq -p 2>/dev/null			|
	sed -e 's/^/var:network:ntp:ntpq::/'
fi

# When you change these labels, also change them in the named user-module!
named_class="fix:network:named"
scc_keep_named_config="network:named:config"
scc_keep_named_count="network:named:count"

named_conf="$(awk '/bin\/[n]amed/	{
				dir="";
				file="";
				# Look for the options specifying the directory and file.
				for ( i = 1; i <= NF; i++ )
				{
					if ( $i ~ "^-t$" )
					{
						i++;
						dir = $i;
					}
					if ( $i ~ "^-[bc]$" )
					{
						i++;
						file = $i;
					}
				}
				if ( file ~ "^/" )	# absolute path?
				{
					path = file;
				}
				else
				{
					path = sprintf( "%s/%s", dir, file );
				}

				if ( length( path ) > 1 )
				{
					print path;
				}
			}' ${PROC_FILE})"

if [ "${named_conf}" ]
then
	echo "${named_class}:general::status:	active"

	cnt=1		# We obtained fresh data from a running named.
else
	echo "${named_class}:general::status:	inactive"

	cnt=$(sed -n -e "s/^${scc_keep_named_count}://p" ${SCC_KEEP_CONFIG})
	cnt=$(( ${cnt:-0} + 1 ))		# Add 1 to the "age"
	if [ ${cnt} -lt 5 -a ${cnt} -gt 1 ]	# Not too old and present?
	then
		named_conf="$(sed -n -e "s/^${scc_keep_named_config}://p" ${SCC_KEEP_CONFIG})"
	fi
fi

named_exe=$(which named 2>/dev/null)
if [ -x "${named_exe}" ]
then
	what "${named_exe}"		|
	grep "named"			|
	sed -e "s/^/${named_class}:general::version:	/"
fi

if [ ! -f "${named_conf}" ]
then
	named_conf=/var/named/named.conf
	if [ ! -f "${named_conf}" ]
	then
		named_conf=/etc/named.conf
	fi
fi

if [ "${named_conf}" -a ${cnt} -lt 5 ]
then
	# Keep for the next run and for the named user-module.
	echo "${scc_keep_named_config}:${named_conf}"	>>${SCC_KEEP_NEW}
	echo "${scc_keep_named_count}:${cnt}"		>>${SCC_KEEP_NEW}
fi

scc_check_file "${named_conf}" "${named_class}:config ${named_conf}::" "#"
# To collect the detailled DNS-data, activate the named user-module by using the -e option of scc.

if [ -f /etc/resolv.conf ]
then
	awk '/^#/	{
				next;
			 }
		/^[ 	]*$/	{
				next;
			 }
			{
				printf( "fix:network:file:/etc/resolv.conf::%04d:	%s\n",\
					( 1 + i++ ), $0 );
			}' /etc/resolv.conf
fi

if [ -x /usr/sbin/inetadm ]
then
	# Output of inetadm:
	#enabled   online         svc:/network/fs/tcp6:default
	/usr/sbin/inetadm 2>/dev/null			|
	awk '/svc:/ { print $3 }'			|
	sort						|
	while read entry
	do
		label=${entry#svc:/}
		/usr/sbin/inetadm -l "${entry}" 2>/dev/null	|
		sed	-e "s@^@${label}:	@"	\
			-e "s@:@::@"			\
			-e "s@/@:@"				|
		sed -e "s/^/fix:network:inetadm:/"
	done
fi

if [ -f /etc/inetd.conf ]
then
	# During removal and (re)installation of software, services are
	# removed from this file and added at the end. To avoid reporting,
	# we sort the file. Special consideration with continuation lines.
	sed	-e '/^#/d'		\
		-e '/^[ 	]*$/d' /etc/inetd.conf		|
	awk '{
			if ( length( prev_service ) > 0 )
			{
				printf( "%s_%08d ", prev_service, counter );
				counter++;
			}
			print;
		}
	/\\$/	{
			if ( length( prev_service ) == 0 )
			{
				prev_service = $1;
			}
			next;
		}
		{
			prev_service = "";
			counter = 0;
		}'						|
	sort 							|
	sed	-e 's/^[a-zA-Z][a-zA-Z]*_[0-9][0-9][0-9][0-9][0-9][0-9][0-9][0-9] //'	\
		-e 's@^@fix:network:file:/etc/inetd.conf::@'
fi

if [ -f /etc/xinetd.conf ]
then
	scc_check_file /etc/xinetd.conf "fix:network:file:/etc/xinetd.conf::" "#"

	dir=$(sed -n -e 's/^includedir  *//p' /etc/xinetd.conf)
	if [ -z "${dir}" ]
	then
		dir=/etc/xinetd.d
	fi
	for f in ${dir}/*
	do
		scc_check_file "${f}" "fix:network:file:xinetd:${f}::" "#"
	done
fi

if [ -x /sbin/gabconfig ]
then
	class="fix:network:GAB"

	gabconfig -v 2>/dev/null	|
	sed -e "s/^/${class}::version   : /"

	gabconfig -e 2>/dev/null	|
	sed -e "s/^/${class}::kernel tunables   : /"

	gabconfig -l 2>/dev/null	|
	sed -e "s/^/${class}::driver config     : /"

	gabconfig -a 2>/dev/null	|
	sed -e "s/^/${class}::port membership   : /"
fi

if [ -x /usr/sbin/lanscan ]
then
	/usr/sbin/lanscan -v					|
	sed -e 's/^/fix:network:lan:lanscan::/'

	# Catch the differences between 10.20 and 11.x
	/usr/sbin/lanscan								|
	awk '/NameUnit/			{ i=7; next }
		/NamePPA/		{ i=6; next }
		/^[0-9].* ETHER /	{ sub( "^[^0-9]*", "", $i ); print $5, $i }'	|
	sort										|
	while read lan nmid remainder
	do
		ifconfig ${lan} 2>&1						|
		sed	-e "s/ifconfig: no such interface/not configured/"	\
			-e "s/^/fix:network:lan:${lan}::ifconfig:	/"

		# Show all the IP-addresses of the interface.
		# Remove the statistics.
		netstat -in -I ${lan} 2>/dev/null					|
		sed	-e 's/Ipkts.*//'				\
			-e 's/  *[- 0-9]*$//'				\
			-e "s/^/fix:network:lan:${lan}::netstat:	/"

		lanadmin -g ${nmid} 2>/dev/null >${TMP1_FILE}
		if [ $? -ne 0 ]
		then
			lanadmin -ams ${nmid}				|
			sed -e "s/^/fix:network:lan:${lan}::lanadmin:	/"
		else
			label="network:lan:${lan}::lanadmin:	"
			awk	'/^PPA/		{ print f $0; }
				/^Description/	{ print f $0; }
				/^Type/		{ print f $0; }
				/^MTU/		{ print f $0; }
				/^Speed/	{ print f $0; }
				/^Station/	{ print f $0; }
				/Status/	{ print v $0; }'	\
					f="fix:${label}"		\
					v="var:${label}"		\
					${TMP1_FILE}
		fi
		rm -f ${TMP1_FILE}
	done
elif [ -d /etc/sysconfig/network-scripts ]
then
	# Linux: RedHat
	for f in /etc/sysconfig/network-scripts/ifcfg-*
	do
		if [ ! -f "${f}" ]
		then
			break;
		fi

		ifc=$(echo ${f} | sed -e 's/.*-//')
		scc_check_file "${f}" "fix:network:lan:${ifc}::network-script:	" "#"

		# Ignore the statistics
		ifconfig ${ifc} 2>/dev/null		|
		sed -e '/^ *RX packets:/,$ d'		|
		sed -e "s/^/fix:network:lan:${ifc}::ifconfig:	/"

		if [ -x /sbin/sysctl ]
		then
			/sbin/sysctl -a 2>/dev/null	|
			grep "^net\..*\.${ifc}\."	|
			sort				|
			sed -e "s/^/fix:network:lan:${ifc}::sysctl:	/"
		fi
	done
elif [ "${OS_NAME}" = "SunOS" -o "${OS_NAME}" = "OpenBSD" ]
then
	{
		# When zones are used on Solaris10, additional "interfaces" appear.
		# Tag these interfaces variable to avoid changes in the logbook.
		if [ -x /usr/sbin/zoneadm ]
		then
			ifconfig -a		|
			awk	'/^[^ 	]/		{ ifc=$1; next }
				/^[ 	]*zone /	{ print "zone " ifc }'
		fi

		# Adjust the output, add the interface name to the classification.
		# Data of PPP-connections is tagged variable.
		ifconfig -a
	}				|
	awk	'/^zone/	{ var[ $2 ] = 1; next }
		/^[^ 	]/	{
					prefix="fix";
					for ( x in var )
					{
						if ( x == $1 )
						{
							prefix="var";
						}
					}
					ifc = $1;		# qfe1: or qfe1:1: for vitual interfaces
					sub( ":$", "", ifc );
					gsub( ":", "_", ifc );	# qfe1: or qfe1_1:
					if ( ifc ~ "ppp" )
					{
						prefix="var";
					}
				}
				{ print prefix ":network:lan:" ifc "::" $0; }'

	all_types=""
	ifconfig -a				|
	sed	-e '/^[ 	]/d'    \
		-e 's/:[ 	].*//'		|
	while read ifc
	do
		# Avoid class conflicts for qfe1 and qfe1:1 (virtual interface).
		label="${ifc}"
		if [ "${ifc}" != "${ifc%:*}" ]
		then
			label="${ifc%:*}_${ifc#*:}"
		fi
		scc_check_file "/etc/hostname.${ifc}" "fix:network:lan:${label}::/etc/hostname.${ifc}:	" "#"
		
		if [ "${label}" != "${ifc}" ]
		then
			continue	# Do not collect additional parameters for virtual interfaces
		fi

		# Extract additional parameters from the interface.
		if_type=${ifc%%[0-9]*}
		if_instance=${ifc##*[a-z]}
		ndd /dev/${if_type} "?" 2>/dev/null	|
		sed	-e '/^?/d'	\
			-e '/write only/d'		|
		sort >${TMP1_FILE}

		# Check the amount of data in this file, some drivers, like "le", do
		# not support requesting settings with ndd.
		if [ $(wc -l <${TMP1_FILE}) -gt 1 ]
		then
			# Select the proper instance.
			ndd -set /dev/${if_type} instance ${if_instance}

			case "${if_type}" in
			*ppp*)	prefix="var";;
			*)	prefix="fix";;
			esac
			while read parm remainder
			do
				ndd -get /dev/${if_type} ${parm}	|
				sed -e "s/^/${prefix}:network:lan:${ifc}::${parm}:	/"
			done <${TMP1_FILE}

		fi
		rm -f ${TMP1_FILE}

		# Collect all interface types that are in use.
		all_types="${all_types} ${if_type}"
	done

	# Check the system-wide default settings for each type of interface.
	echo "${all_types}"			|
	tr " " "\012"				|
	sort -u					|
	while read if_type
	do
		if [ "${if_type}" ]
		then
			config_file="/kernel/drv/${if_type}.conf"
			scc_check_file "${config_file}" "fix:network:lan:${config_file}::" "#"
		fi
	done

elif [ "${OS_NAME}" = "AIX" ]
then
	# Contributed by Doug Probst.
	ifconfig -l		|
	while read ifc remainder
	do
		ifconfig ${ifc}			|
		sed -e "s/^/fix:network:lan:${ifc}::/"
	done
else
	# Adjust the output, add the interface name to the classification.
	# Data of PPP-connections is tagged variable.
	# Ignore for Debian the RX/TX counters and the collisions.
		#eth0      Link encap:Ethernet  HWaddr 00:00:F8:10:49:CA
		#          inet addr:192.233.54.140  Bcast:192.233.54.255  Mask:255.255.255.128
		#          UP BROADCAST RUNNING MULTICAST  MTU:1500  Metric:1
		#          RX packets:3106025 errors:0 dropped:0 overruns:0 frame:0
		#          TX packets:3849963 errors:0 dropped:0 overruns:0 carrier:0
		#          collisions:25937 txqueuelen:100
		#          RX bytes:3437928343 (3.2 GiB)  TX bytes:3413435887 (3.1 GiB)
		#          Interrupt:15 Base address:0x4000
	ifconfig -a 2>/dev/null			|
	sed	-e '/ [RT]X [bp]/d'	\
		-e '/collisions/d'		|
	awk '/^[^ 	]/	{
					ifc = $1;		# eth0 or eth0:1 for vitual interfaces
					sub( ":$", "", ifc );
					gsub( ":", "_", ifc );
					prefix="fix";
					if ( ifc ~ "ppp" )
					{
						prefix="var";
					}
				}
				{ print prefix ":network:lan:" ifc "::" $0; }'

	ifconfig -a 2>/dev/null			|
	sed	-e '/^[ 	]/d'	\
		-e 's/:.*//'			|
	sort -u					|
	while read ifc
	do
		sed -e "s@^@fix:network:lan:${ifc}::/etc/ifconfig.${ifc}:	@" "/etc/ifconfig.${ifc}" 2>/dev/null
	done

	if [ -d /etc/sysconfig/network ]
	then
		for f in /etc/sysconfig/network/ifcfg-*
		do
			ifc=${f##*/}
			ifc=${ifc#*-}
			scc_check_file "${f}" "fix:network:lan:${ifc}::ifcfg-${ifc}:	" "#"
		done
	fi
fi

if [ -d /etc/net ]
then
	for d in ticlts ticots ticotsord
	do
		for f in hosts services
		do
			scc_check_file "/etc/net/${d}/${f}" "fix:network:loopback:/etc/net/${d}/${f}::" "#"
		done
	done
fi

rpcinfo -p 2>/dev/null		|
awk '/^ *[0-9][0-9]*/ {
		# Ignore the ports without name
		if ( NF <= 4 )
		{
			next
		}
	}
	{
		print $1, $2, $3, $5;
	}'			|
sort -n				|
sed -e 's/^/fix:network:rpcinfo::/'

if [ -x /sbin/sysctl ]
then
	echo "/^net\\.ip.*\\.ip_\\./d"		>${TMP1_FILE}
	echo "/^net\\.ip.*\\.ip_\\./d"		>>${TMP1_FILE}
	echo "/^net\\.inet\\.tcp\\.pcbcount/d"	>>${TMP1_FILE}
	echo "/^net\\.isr\\./d"			>>${TMP1_FILE}
	echo "/ip_always_defrag/d"		>>${TMP1_FILE}
	echo "/hostcache.count/d"		>>${TMP1_FILE}
	echo "/ip_conntrack_count/d"		>>${TMP1_FILE}	# Indicated by Anthony Caetano

	if [ -f /proc/net/dev ]
	then
		# Determine the interfaces and build an sed-script that removes all the
		# interface specific output of sysctl. These settings are recorded by ndd.
		awk -F: '{
				if ( NF > 1 )
				{
					sub( "  *", "", $1 )
					printf( "/^net\\..*\\.%s\\./d\n", $1 )
				}
			}' /proc/net/dev >>${TMP1_FILE}
	fi

	/sbin/sysctl -a 2>/dev/null			|
	sed -f ${TMP1_FILE}				|
	sed -n -e "s/^net\./fix:network:sysctl::net./p"	|
	sort
fi
rm -f ${TMP1_FILE}

if [ -x /usr/contrib/bin/nettune ]
then
	/usr/contrib/bin/nettune -l 2>/dev/null		|
	sed -e 's/^/fix:network:nettune::/'
fi

if [ -x /usr/bin/ndd -o -x /usr/sbin/ndd ]
then
	for d in arp icmp icmp6 ip ip6 tcp tcp6 udp udp6
	do
		if [ ! -r /dev/${d} ]
		then
			continue
		fi

		ndd -get /dev/${d} "?"				|
		sed	-e "/write only/d"		\
			-e "/arp_cache_report/d"	\
			-e "s/[ (].*//"			\
			-e "/status/d"			\
			-e "/stats$/d"			\
			-e "/hash/d"			\
			-e "/ip_always_defrag/d"	\
			-e "/pullups$/d"		\
			-e "/^?/d"				|
		while read parm remainder
		do
			case "${parm}" in
			*ppp*)	prefix="var";;
			*)	prefix="fix";;
			esac
			ndd -get /dev/${d} ${parm} 2>&1	|
			sed -e "s/^/${prefix}:network:ndd:${d}::${parm}:	/"
		done

	done
fi

if [ -d /proc/sys/net/ipv4 ]
then
	(
	cd /proc/sys/net/ipv4

	for p in icmp ip tcp
	do
		for f in ${p}*
		do
			name="${f##*/}"		# basename
			# Avoid the overhead of the function scc_check_file.
			sed -e "s/^/fix:network:${p}::${name}:	/" "${f}" 2>/dev/null	|
			sed -e '/ip_always_defrag/d'
		done
	done

	# We prefer sysctl to obtain the following data.
	if [ -d conf -a ! -x /sbin/sysctl ]
	then
		cd conf
		for if in */*
		do
			interface="${if%/*}"	# dirname
			name="${if##*/}"	# basename
			# Avoid the overhead of the function scc_check_file.
			sed -e "s/^/fix:network:/proc/sys/net/ipv4:${interface}::${name}:	/" "${if}" 2>/dev/null
		done
	fi
	)
fi

if [ "${OS_NAME}" = "SunOS" ]
then
	netstat -rv 2>/dev/null				|
	awk '/^---/	{ next }
		{
			# Dynamic routes are treated as variable, not fixed config items
			p="fix";
			if ( NF == 10 )
			{
				if ( ( $8 ~ "D" ) || ( $4 ~ "ppp" ) )
				{
					p="var";
				}
				printf( "%s:network:netstat-route::%s:%s:%s:%s:%s:%s\n",\
					p, $1, $2, $3, $4, $5, $8 );
			}
			else if ( NF == 9 )
			{
				if ( $7 ~ "D" )
				{
					p="var";
				}
				printf( "%s:network:netstat-route::%s:%s:%s:%s:%s\n",\
					p, $1, $2, $3, $4, $7 );
			}
			else if ( NF > 0 )
			{
				print "fix:network:netstat-route::" $0;
			}
		}'
elif [ "${OS_NAME}" = "HP-UX" ]
then
	netstat -rv 2>/dev/null				|
	awk '/^Routing tables/	{
					print;
					next;
				}
		/^[ 	]/	{
					if ( NF == 1 )
					{
						# Netmask does not fit: continuation 
						# line with only netmask.
						printf( "%s ", $0 );
						offset++;
						next;
					}

					if ( offset == 1 )
					{
						# Destination was on previous line
						print $1, $2, $(NF-1), $NF;
					}
					else
					{
						# Destination and netmask were on
						# previous line(s)
						print $1, $(NF-1), $NF;
					}
					next;
				}
				{
					if ( NF < 3 )
					{
						# Destination and/or netmask do not
						# fit into the column. Remainder follows
						# on next line.
						printf( "%s ", $0 );
						offset=NF;
					}
					else
					{
						print $1, $2, $3, $(NF-1), $NF;
					}
				}'		|
	awk '{
		p="fix";
		if ( $3 ~ "D" )
		{
			p="var";
		}
		printf( "%s:network:netstat-route::%s:%s:%s:%s\n", p, $1, $2, $3, $4 );
	}'
elif [ "${OS_NAME}" = "FreeBSD" -o "${OS_NAME}" = "NetBSD" -o "${OS_NAME}" = "OpenBSD" ]
then
	netstat -rl 2>/dev/null			|
	awk	'{
			if ( NF < 6 )
			{
				print "fix:network:netstat-route::" $0;
			}
			else
			{
				p="fix";
				if ( $3 ~ "D" || $3 ~ "M" )
				{
					p="var"
				}
				printf( "%s:network:netstat-route::%s:%s:%s:%s:%s\n", p, $1, $2, $3, $6, $7 );
			}
		}'
elif [ "${OS_NAME}" = "OSF1" ]
then
	netstat -rv 2>&1		|
	awk '{
		p="fix";
		if ( NF < 8 )
		{
			print "fix:network:netstat-route::" $0;
		}
		else
		{
			if ( $3 ~ "D" )
			{
				p="var";
			}
			printf( "%s:network:netstat-route::%s:%s:%s:%s:%s\n",\
				p, $1, $2, $3, $6, $7 );
		}
	}'
elif [ "${OS_NAME}" = "AIX" ]
then
	# Contributed by Doug Probst.
	netstat -nr 2> /dev/null | 
	awk	'{
			if ( NF < 8 )
			{
				print "fix:network:netstat-route::" $0;
			}
			else
			{ 
				p="fix";
				if ( $3 ~ "D" )
				{
					p="var";
				}
				printf( "%s:network:netstat-route::%s:%s:%s:%s:%s:%s:%s:%s\n",\
					p, $1, $2, $3, $6, $7, $8, $9, $10 );
			} 
		}'
else
	# Linux: tested on RH 6.2
	netstat -rv 2>/dev/null			|
	awk '{
		p="fix";
		if ( NF < 6 )
		{
			print "fix:network:netstat-route::" $0;
		}
		else
		{
			if ( $4 ~ "D" )
			{
				p="var";
			}
			printf( "%s:network:netstat-route::%s:%s:%s:%s:%s:%s\n",\
				p, $1, $2, $3, $4, $(NF-1), $NF );
		}
	}'
fi				|
tr "A-Z" "a-z"

ls /dev/x25* 2>/dev/null | grep x25 >/dev/null 2>&1
if [ -d /etc/x25 -a $? -eq 0 ]
then
	if [ -f /etc/rc.config.d/acc ]
	then
		. /etc/rc.config.d/acc

		if [ "${START_ZCOM}" = 1 ]
		then
			echo "fix:network:x25-mux:config::status:	active"

			# The variabele ${X25INIT_FILE} contains the name of the file that
			# contains the names of the configuration-files with the names of the
			# device files. Obvious.
			init_file=$(echo ${X25INIT_FILE})
			file=$(awk '/-c/ { print $3 }' ${init_file})
			dev=$(awk '/^device/ { print $2 }' ${file})
			rm -f ${TMP1_FILE}
			for d in ${dev}
			do
				if [ -n "${d}" ]
				then
					if [ ! -f ${TMP1_FILE} ]
					then
						/usr/sbin/x25stat -d ${dev} -c 2>&1		|
						sed	-e '/Programatic Access Name/d'			\
							-e '/^ *$/d'					\
							-e '/Packet type.*TX.*RX/,/-* X.25 CONFIG -*/d'	\
							-e 's/^/fix:network:x25-mux:config::/'
						touch ${TMP1_FILE}
					fi

					/usr/sbin/x25stat -d ${dev} -c 2>&1		|
					sed -n	-e '/Programatic Access Name/p'		|
					sed	-e 's/.*: //'			\
						-e "s/^/fix:network:x25-mux:${d}::access:	/"
				fi
			done
		else
			echo "fix:network:x25-mux:config::status:	inactive"
		fi
	else
		/usr/sbin/x25stat -c 2>&1	|
		sed -e 's/^/fix:network:x25:data::/'

		/usr/sbin/x25stat -a 2>&1	|
		sed -e 's/^/fix:network:x25:ipmap::/'
	fi
fi

if [ -f /etc/snet_info ]
then
	scc_check_file /etc/snet_info "fix:network:x25:/etc/snet_info::" "#"

	(
		cfg="$(grep "^X25CONFIGFILES=" /etc/snet_info | tail -1)"
		eval "${cfg}"			# set X25CONFIGFILES
		X25CONFIGFILES=${X25CONFIGFILES:=/etc/opt/SUNWconn/x25}

		for f in	${X25CONFIGFILES}/ipconf	\
				${X25CONFIGFILES}/netconf	\
				${X25CONFIGFILES}/config/link_config_0*.cfg
		do
			scc_check_file "${f}" "fix:network:x25:${f##*/}::" "#"
		done
	)
fi

exit 0
