#! /bin/bash

# default libexecdir used to bootstrap scripts
libexecdir=${GLOBUS_LOCATION}/libexec

# load GRIS common code and initialization
. ${libexecdir}/grid-hostinfo-net-common

#########################################################################

probe_resource_net ()
{
    ${GLOBUS_SH_NETSTAT-netstat} -in | \
    {
	i=0
	read header
	while read iface mtu netaddr ipaddr rest
	do
	    case "$netaddr" in
		*.*.*.*)
		    # do nothing
		    :
		    ;;
		*.*.*)
		    # add missing zero
		    netaddr="${netaddr}.0"
		    ;;
		*.*)
		    # add missing zeros
		    netaddr="${netaddr}.0.0"
		    ;;
		*)
		    # add missing zeros
		    netaddr="${netaddr}.0.0.0"
		    ;;
	    esac

	    eval "_net_${i}_name=${iface}"
	    eval "_net_${i}_mtu=${mtu}"
	    eval "_net_${i}_netaddr=\"${netaddr}\""
	    eval "_net_${i}_ipaddr=\"${ipaddr}\""
	    case "$ipaddr" in
		none) : ;;
		*) i=`$EXPR $i + 1` ; ;;
	    esac
	done
	_net_count=$i

	# run this in initialized subshell environment
	emit_resource_net_descriptions
    }
}

#############
# do the work
probe_resource_net
