3 # $Id: make-manuf,v 1.4 2002/03/14 21:22:11 guy 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 # LWP is part of the standard Perl module libwww
17 eval "require LWP::UserAgent;";
19 die "LWP isn't installed. It is part of the standard Perl\n" .
20 " module libwww. Bailing.\n";
23 $template = "manuf.tmpl";
26 $ieee_url = "http://standards.ieee.org/regauth/oui/oui.txt";
27 $cb_url = "http://www.cavebear.com/CaveBear/Ethernet/Ethernet.txt";
29 $hp = "[0-9a-fA-F]{2}";
30 $oui_re = "$hp:$hp:$hp";
32 $ieee_re = "$hp-$hp-$hp";
40 $agent = LWP::UserAgent->new;
42 print "Fetching $cb_url.\n";
43 $request = HTTP::Request->new(GET => $cb_url);
44 $result = $agent->request($request);
46 if (!$result->is_success) {
47 die ("Error fetching $cb_url: " . $result->status_line . "\n");
49 $cb_list = $result->content;
51 print "Fetching $ieee_url.\n";
52 $request = HTTP::Request->new(GET => $ieee_url);
53 $result = $agent->request($request);
55 if (!$result->is_success) {
56 die ("Error fetching $ieee_url: " . $result->status_line . "\n");
58 $ieee_list = $result->content;
60 open (TMPL, "< $template") ||
61 die "Couldn't open template file for reading ($template)\n";
63 open (OUT, "> $outfile") ||
64 die "Couldn't open output file for writing ($outfile)\n";
66 # Write out the header and populate the OUI list with our entries.
67 while ($line = <TMPL>) {
69 if ($line !~ /^$oui_re\s+\S/ && $inheader) {
71 } elsif (($oui, $manuf) = ($line =~ /^($oui_re)\s+(\S.*)$/)) {
73 # Ensure OUI is all upper-case
75 $oui_list{$oui} = $manuf;
80 foreach $line (split(/\n/, $cb_list)) {
81 if (($oui, $manuf) = ($line =~ /^($cb_re)\s+(\S.*)$/)) {
82 ($h1, $h2, $h3) = ($oui =~ /($hp)($hp)($hp)/); # The CaveBear bytes have no separators
84 # Ensure OUI is all upper-case
86 if (exists $oui_list{$oui}) {
87 printf "$oui - Skipping CaveBear \"$manuf\" in favor of \"$oui_list{$oui}\"\n";
90 $oui_list{$oui} = $manuf;
96 foreach $line (split(/\n/, $ieee_list)) {
97 if (($oui, $manuf) = ($line =~ /^($ieee_re)\s+\(hex\)\s+(\S.*)$/)) {
98 $oui =~ tr /-/:/; # The IEEE bytes are separated by dashes.
99 # Ensure OUI is all upper-case
101 if (exists $oui_list{$oui}) {
102 printf "$oui - Skipping IEEE \"$manuf\" in favor of \"$oui_list{$oui}\"\n";
105 $oui_list{$oui} = $manuf;
111 foreach $oui (sort(keys %oui_list)) {
112 print(OUT "$oui\t$oui_list{$oui}\n");
115 $total_added = $tmpl_added + $cb_added + $ieee_added;
117 Original entries : $tmpl_added
118 CaveBear added : $cb_added
119 IEEE added : $ieee_added
122 CaveBear skipped : $cb_skipped
123 IEEE skipped : $ieee_skipped