Re: mac.c - Mailing list pgsql-hackers

From Thomas Lockhart
Subject Re: mac.c
Date
Msg-id 39A032C3.24AEF14F@alumni.caltech.edu
Whole thread Raw
In response to mac.c  (Larry Rosenman <ler@lerctr.org>)
Responses Re: mac.c
List pgsql-hackers
> Does anyone want to do the coding we've talked about?

OK, here is what I have so far, based on the work of Larry, Alex, and
others:

o Two new functions, trunc(macaddr) and text(macaddr), where the former
returns the mac address with the low (non-manufacturer) fields zeroed
out, and the latter converts to a text string. The text conversion is
nice because capabilities such as LIKE can be used transparently :) Will
need to add macaddr(text) for symmetry.

o Two utilities for contrib/mac, createoui and updateoui. The former
creates a table "macoui" with the fields oui and manufacturer. The
latter populates it with the contents of the file oui.txt, fetched from
the IEEE web site and processed by a slightly modified version of
Larry's awk script.

o An sql definition file, manuf.sql, which defines a function
manuf(macaddr) along the lines Alex had suggested. It returns a text
string of the manufacturer's name, or NULL if none is matched. You can
use COALESCE() to return something other than NULL if you want.

Should we have updateoui use wget to fetch oui.txt from the IEEE web
site? Or perhaps better we could have that in a separate utility?

Comments?
                  - Thomas

Some examples are

myst> ./createoui
myst> ./updateoui

lockhart=# select trunc(macaddr '00:01:a0:aa:bb:cc');      trunc
-------------------00:01:a0:00:00:00
(1 row)

lockhart=# select manuf('01:02:03:00:00:00');manuf
-------

(1 row)

lockhart=# select manuf('00:01:a0:00:00:00');        manuf
------------------------Infinilink Corporation
(1 row)

lockhart=# select manuf('00:01:A0:00:00:00');        manuf
------------------------Infinilink Corporation
(1 row)

lockhart=# select manuf('00:01:A0:00:00:01');        manuf
------------------------Infinilink Corporation
(1 row)

lockhart=# select coalesce(manuf('01:02:03:00:00:00'), 'nada');case
------nada
(1 row)

lockhart=# select * from macoui where oui like '00:aa%';       oui        |         manufacturer          
-------------------+-------------------------------00:aa:00:00:00:00 | INTEL CORPORATION00:aa:01:00:00:00 | INTEL
CORPORATION00:aa:02:00:00:00| INTEL CORPORATION00:aa:3c:00:00:00 | OLIVETTI TELECOM SPA (OLTECO)
 
(4 rows)

lockhart=# select * from macoui where oui like '00:AA%';oui | manufacturer 
-----+--------------
(0 rows)

lockhart=# select * from macoui where oui ilike '00:AA%';       oui        |         manufacturer          
-------------------+-------------------------------00:aa:00:00:00:00 | INTEL CORPORATION00:aa:01:00:00:00 | INTEL
CORPORATION00:aa:02:00:00:00| INTEL CORPORATION00:aa:3c:00:00:00 | OLIVETTI TELECOM SPA (OLTECO)
 
(4 rows)


pgsql-hackers by date:

Previous
From: Tom Lane
Date:
Subject: Re: CREATE/DROP SCHEMA considered harmful
Next
From: Tiago Antão
Date:
Subject: A GNU-Prolog/PostgreSQL interface