#!/usr/local/bin/cbsd
#v11.1.12
MYARG=""
MYOPTARG="desc all skip phyonly"
MYDESC="Return for visible storage"
# really - this is wrapper for miscdir/nics-list
ADDHELP="desc=1 - show description and status too\n\
all=1 show all nics, no filtering for special interfaces\n\"
skip='lo xxx' - skip ifaces in list\n\
phyonly= - show only physical ifaces\n"

phyonly=0

. ${subrdir}/nc.subr

. ${cbsdinit}

. ${system}

TOOLS_ARG=""

[ "${desc}" = "1" ] && TOOLS_ARG="${TOOLS_ARG} -d"
[ "${all}" = "1" ] && TOOLS_ARG="${TOOLS_ARG} -a"
[ -n "${skip}" ] && TOOLS_ARG="${TOOLS_ARG} -s ${skip}"

${miscdir}/nics-list ${TOOLS_ARG} |while read _line; do

	case ${phyonly} in
		0)
			if [ "${desc}" = "1" ]; then
				echo ${_line}
			else
				echo ${_line}
			fi
			;;
		1)
			if [ "${desc}" = "1" ]; then
				strpos --str="${_line}" --search=":"
				pos=$?
				[ ${pos} -eq 0 ] && continue
				prefix=$( substr --pos=0 --len=${pos} --str="${_line}" )
				is_phys=$( ${toolsdir}/nic_info --quiet --nic=${prefix} --phys )
				[ "${is_phys}" = "1" ] && echo ${_line}
			else
				is_phys=$( ${toolsdir}/nic_info --quiet --nic=${_line} --phys )
				[ "${is_phys}" = "1" ] && echo ${_line}
			fi
			;;
	esac

done
