#!/bin/sh
# @(#) $Id: massagevendor,v 1.3 2004/01/28 19:32:24 leres Exp $ (LBL)
#
# - Massage:
#
#	http://standards.ieee.org/regauth/oui/oui.txt
#
#   into ethercodes.dat format.
#
# - Deal with duplicates in oui.txt (concatenate company names)
#
(sed -n \
    -e 's/^\([0-9A-F][0-9A-F]\)-\([0-9A-F][0-9A-F]\)-\([0-9A-F][0-9A-F]\)  *(hex)[ 	]*\(..*\)/\1\2\3	\4/p' \
    $* | \
    awk '
BEGIN {
	x["0"] = "0"
	x["1"] = "1"
	x["2"] = "2"
	x["3"] = "3"
	x["4"] = "4"
	x["5"] = "5"
	x["6"] = "6"
	x["7"] = "7"
	x["8"] = "8"
	x["9"] = "9"
	x["A"] = "a"
	x["B"] = "b"
	x["C"] = "c"
	x["D"] = "d"
	x["E"] = "e"
	x["F"] = "f"

}

{
	s = ""
	for (i = 1; i <= 6; ++i) {
		t = substr($0, i, 1)
		s = s x[t]
	}
	s = s substr($0, 7)
	print s
	next
}
'  | \
    sed -n \
    -e 's/^\([0-9A-Za-z][0-9A-Za-z]\)\([0-9A-Za-z][0-9A-Za-z]\)\([0-9A-Za-z][0-9A-Za-z]\)[ 	]\(.*\)$/\1:\2:\3	\4/' \
    -e 's/^0//' -e 's/:0\([0-9A-Za-z]\)/:\1/g' -e p | \
    sort | \
    awk '
# combine company info for duplciate vendor codes

BEGIN {
	str = ""
	lastv = ""
}

{
	v = $1
	if (v == lastv) {
		i = index($0, "	")
		# XXX probably can'\''t happen
		if (i <= 0)
			i = 0
		str = str " *also* " substr($0, i + 1)
	} else {
		if (str != "")
			print str
		str = $0
	}
	lastv = v

}

END {
	if (str != "")
		print str
}
'  ) | \
    awk '
# Only print the first ethernet address seen

{
	e = $1
	if (seen[e])
		next
	seen[e] = 1
	print
}
'  | \
    sort
