3 # $Id: make-manuf,v 1.2 2000/11/29 04:11:48 gram Exp $
5 # Make-manuf - Creates a file containing ethernet OUIs and their
6 # company IDs. It merges the databases at
7 # http://standards.ieee.org/regauth/oui/index.shtml and
8 # http://www.cavebear.com/CaveBear/Ethernet/
9 # with entries in our template file.
11 # The script reads the comments at the top of "manuf.tmpl" and writes
12 # them to "manuf". It then joins the manufacturer listing in "manuf.tmpl"
13 # with the listing in "oui.txt", with the entries in "manuf.tmpl" taking
16 eval "require LWP::UserAgent;";
18 die "LWP isn't installed. Bailing.\n";
21 $template = "manuf.tmpl";
24 $ieee_url = "http://standards.ieee.org/regauth/oui/oui.txt";
25 $cb_url = "http://www.cavebear.com/CaveBear/Ethernet/Ethernet.txt";
27 $hp = "[0-9a-fA-F]{2}";
28 $oui_re = "$hp:$hp:$hp";
30 $ieee_re = "$hp-$hp-$hp";
38 $agent = LWP::UserAgent->new;
40 print "Fetching $cb_url.\n";
41 $request = HTTP::Request->new(GET => $cb_url);
42 $result = $agent->request($request);
44 if (!$result->is_success) {
45 die ("Error fetching $cb_url: " . $result->status_line . "\n");
47 $cb_list = $result->content;
49 print "Fetching $ieee_url.\n";
50 $request = HTTP::Request->new(GET => $ieee_url);
51 $result = $agent->request($request);
53 if (!$result->is_success) {
54 die ("Error fetching $ieee_url: " . $result->status_line . "\n");
56 $ieee_list = $result->content;
58 open (TMPL, "< $template") ||
59 die "Couldn't open template file for reading ($template)\n";
61 open (OUT, "> $outfile") ||
62 die "Couldn't open template file for writing ($template)\n";
64 # Write out the header and populate the OUI list with our entries.
65 while ($line = <TMPL>) {
67 if ($line !~ /^$oui_re\s+\S/ && $inheader) {
69 } elsif (($oui, $manuf) = ($line =~ /^($oui_re)\s+(\S.*)$/)) {
71 # Ensure OUI is all upper-case
73 $oui_list{$oui} = $manuf;
78 foreach $line (split(/\n/, $cb_list)) {
79 if (($oui, $manuf) = ($line =~ /^($cb_re)\s+(\S.*)$/)) {
80 ($h1, $h2, $h3) = ($oui =~ /($hp)($hp)($hp)/); # The CaveBear bytes have no separators
82 # Ensure OUI is all upper-case
84 if (exists $oui_list{$oui}) {
85 printf "$oui - Skipping CaveBear \"$manuf\" in favor of \"$oui_list{$oui}\"\n";
88 $oui_list{$oui} = $manuf;
94 foreach $line (split(/\n/, $ieee_list)) {
95 if (($oui, $manuf) = ($line =~ /^($ieee_re)\s+\(hex\)\s+(\S.*)$/)) {
96 $oui =~ tr /-/:/; # The IEEE bytes are separated by dashes.
97 # Ensure OUI is all upper-case
99 if (exists $oui_list{$oui}) {
100 printf "$oui - Skipping IEEE \"$manuf\" in favor of \"$oui_list{$oui}\"\n";
103 $oui_list{$oui} = $manuf;
109 foreach $oui (sort(keys %oui_list)) {
110 print(OUT "$oui\t$oui_list{$oui}\n");
113 $total_added = $tmpl_added + $cb_added + $ieee_added;
115 Original entries : $tmpl_added
116 CaveBear added : $cb_added
117 IEEE added : $ieee_added
120 CaveBear skipped : $cb_skipped
121 IEEE skipped : $ieee_skipped