1#!/bin/sh
2
3IBPATH=${IBPATH:-@IBSCRIPTPATH@}
4
5function usage() {
6	echo Usage: `basename $0` "[-h] [<topology-file> | -C ca_name" \
7	    "-P ca_port -t(imeout) timeout_ms]"
8	exit -1
9}
10
11topofile=""
12ca_info=""
13
14while [ "$1" ]; do
15	case $1 in
16	-h)
17		usage
18		;;
19	-P | -C | -t | -timeout)
20		case $2 in
21		-*)
22			usage
23			;;
24		esac
25		if [ x$2 = x ] ; then
26			usage
27		fi
28		ca_info="$ca_info $1 $2"
29		shift
30		;;
31	-*)
32		usage
33		;;
34	*)
35		if [ "$topofile" ]; then
36			usage
37		fi
38		topofile="$1"
39		;;
40	esac
41	shift
42done
43
44if [ "$topofile" ]; then
45	netcmd="cat $topofile"
46else
47	netcmd="$IBPATH/ibnetdiscover $ca_info"
48fi
49
50text="`eval $netcmd`"
51rv=$?
52echo "$text" | awk '
53/^Rt/	{print $1 "\t: 0x" substr($3, 4, 16) " ports " $2 " "\
54		substr($0, match($0, "#[ \t]*")+RLENGTH)}
55/^ib/	{print $0; next}
56/ibpanic:/	{print $0}
57/ibwarn:/	{print $0}
58/iberror:/	{print $0}
59'
60exit $rv
61