summaryrefslogtreecommitdiff
path: root/contrib/mac/createoui
blob: eaf4dbfac0eb0a808d9b2c4864e94d474bc033a3 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
#! /bin/sh

# $PostgreSQL: pgsql/contrib/mac/createoui,v 1.3 2006/03/11 04:38:30 momjian Exp $

# Utility to create manufacturer's oui table
# OUI is "Organizationally Unique Identifier" assigned by IEEE.
# There are currently three duplicate listings, so we can not enforce
# uniqueness in the OUI field.
# - thomas 2000-08-21

args=
update=0

while [ $# -gt 0 ]
do
    case "$1" in
    --update)
        update=1
        ;;
    --noupdate)
        update=0
        ;;
    --help)
        echo "Usage: $0 --[no]update dbname"
        exit
        ;;
    *)
        args="$args $1"
        ;;
    esac
    shift
done

psql -e $args <<EOF
-- Table containing OUI portions of MAC address and manufacturer's name
create table macoui (
  addr macaddr not null,
  name text not null
);

-- Create an index to help lookups
create index macoui_idx on macoui (addr);

-- Function to return manufacturer's name given MAC address
create function manuf (macaddr)
	returns text as '
		select name from macoui m where trunc(\$1) = m.addr;
' language SQL;
EOF

if [ $update -gt 0 ]; then
    updateoui $args
fi

exit