#!/bin/sh -eu

. "${0%/*}"/functions

iface=
mac=
case "${1-}" in
	mac=*) mac="${1#mac=}" ;;
	*) iface="${1-}" ;;
esac

find "/sys/class/net/$iface/" -mindepth 1 -maxdepth 1 -printf '%h/%l\n' |
while read path; do
	if [ -n "$mac" ]; then
		if [ -f "$path/address" ]; then
			read net_mac < "$path/address"
			[ -z "${net_mac##$mac}" ] ||
				continue
		else
			continue
		fi
	fi
	process_device "$path/device"
done | sort -u
