#!/bin/sh -e

##########################################################################
#   Script description:
#       Show netmask of first non-loopback interface
#       
#   History:
#   Date        Name        Modification
#   2021-01-03  J Bacon     Begin
##########################################################################

usage()
{
    printf "Usage: $0 hex|octet\n"
    exit 1
}


##########################################################################
#   Main
##########################################################################

if [ $# != 1 ]; then
    usage
fi
format=$1

case $(auto-ostype) in
FreeBSD)
    hex_netmask=$(ifconfig | awk '$1 == "inet" && $2 !~ "127.0.0" { print $4 }' | head -n 1)
    if [ $format = octet ]; then
	auto-hex-to-octet $hex_netmask
    else
	echo $hex_netmask
    fi
    ;;

*)
    auto-unsupported-os $0
    exit 1
    ;;

esac
