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
19 use open ':encoding(utf8)';
21 eval "require LWP::UserAgent;";
23 die "LWP isn't installed. It is part of the standard Perl\n" .
24 " module libwww. Bailing.\n";
26 $agent = LWP::UserAgent->new;
28 $template = "manuf.tmpl";
29 $wkatmpl = "wka.tmpl";
32 $oui_url = "http://standards.ieee.org/regauth/oui/oui.txt";
33 $iab_url = "http://standards.ieee.org/regauth/oui/iab.txt";
34 $cb_url = "http://www.cavebear.com/CaveBear/Ethernet/Ethernet.txt";
36 $hp = "[0-9a-fA-F]{2}";
37 $oui_re = "$hp:$hp:$hp";
39 $ieee_re = "$hp-$hp-$hp";
51 my $origmanuf = shift;
52 my $manuf = " " . $origmanuf . " ";
53 # Remove any punctuation
54 $manuf =~ tr/',.()/ /;
55 # & isn't needed when Standalone
57 # Remove any "the", "inc", "plc" ...
58 $manuf =~ s/\s(the|inc|incorporated|plc||systems|corp|corporation|s\/a|a\/s|ab|ag|kg|gmbh|co|company|limited|ltd)(?= )//gi;
59 # Convert to consistent case
60 $manuf =~ s/(\w+)/\u\L$1/g;
63 # Truncate all names to a reasonable length, say 10 characters.
64 $manuf = substr($manuf, 0, 10);
66 if ($manuf =~ /\Q$origmanuf\E/i) {
69 return sprintf("%-22s # %s", $manuf, $origmanuf);
76 print "Fetching $url.\n";
77 $request = HTTP::Request->new(GET => $url);
78 $result = $agent->request($request);
80 if (!$result->is_success) {
81 die ("Error fetching $url: " . $result->status_line . "\n");
83 return decode("iso-8859-1", $result->content);
86 # Write out the header and populate the OUI list with our entries.
88 open (TMPL, "< $template") ||
89 die "Couldn't open template file for reading ($template)\n";
91 while ($line = <TMPL>) {
93 if ($line !~ /^$oui_re\s+\S/ && $inheader) {
95 } elsif (($oui, $manuf) = ($line =~ /^($oui_re)\s+(\S.*)$/)) {
97 # Ensure OUI is all upper-case
99 # $oui_list{$oui} = &shorten($manuf);
100 $oui_list{$oui} = $manuf;
105 # Add IEEE entries for IABs
107 $ieee_list = fetch($iab_url);
109 foreach $line (split(/\n/, $ieee_list)) {
110 # determine the OUI used for IAB (currently only 00-50-C2)
111 if (($iab_tmp, $manuf) = ($line =~ /^($ieee_re)\s+\(hex\)\s+(\S.*)$/)) {
112 $iab_base = $iab_tmp;
114 # determine next two bytes
115 if (($iab4, $iab5, $manuf) = ($line =~ /^($hp)($hp)$hp-$hp$hp$hp\s+\(base\s16\)\s+(\S.*)$/)) {
116 $iab = "$iab_base:$iab4:$iab5:00/36";
117 $iab =~ tr /-/:/; # The IEEE bytes are separated by dashes.
118 # Ensure IAB is all upper-case
120 if (exists $oui_list{$iab}) {
121 printf "$iab - Skipping IEEE \"$manuf\" in favor of \"$oui_list{$iab}\"\n";
124 $oui_list{$iab} = &shorten($manuf);
130 # Add IEEE entries for OUIs not yet known.
132 $ieee_list = fetch($oui_url);
134 foreach $line (split(/\n/, $ieee_list)) {
135 if (($oui, $manuf) = ($line =~ /^($ieee_re)\s+\(hex\)\s+(\S.*)$/)) {
136 $oui =~ tr /-/:/; # The IEEE bytes are separated by dashes.
137 # Ensure OUI is all upper-case
139 if (exists $oui_list{$oui}) {
140 printf "$oui - Skipping IEEE \"$manuf\" in favor of \"$oui_list{$oui}\"\n";
143 $oui_list{$oui} = &shorten($manuf);
149 # Add CaveBear entries for OUIs not yet known.
151 $cb_list = fetch($cb_url);
153 foreach $line (split(/\n/, $cb_list)) {
154 if (($oui, $manuf) = ($line =~ /^($cb_re)\s+(\S.*)$/)) {
155 ($h1, $h2, $h3) = ($oui =~ /($hp)($hp)($hp)/); # The CaveBear bytes have no separators
156 $oui = "$h1:$h2:$h3";
157 # Ensure OUI is all upper-case
159 if (exists $oui_list{$oui}) {
160 # printf "$oui - Skipping CaveBear \"$manuf\" in favor of \"$oui_list{$oui}\"\n";
163 printf "$oui - adding \"$manuf\" from CaveBear\n";
164 $oui_list{$oui} = &shorten($manuf);
172 open (OUT, "> $outfile") ||
173 die "Couldn't open output file for writing ($outfile)\n";
175 print(OUT "# This file was generated by running ./make-manuf.\n");
176 print(OUT "# Don't change it directly, change manuf.tmpl and wka.tmpl instead.\n#\n");
177 print(OUT "$header");
179 foreach $oui (sort(keys %oui_list)) {
180 print(OUT "$oui\t$oui_list{$oui}\n");
183 # Write out a blank line separating the OUIs from the well-known
184 # addresses, and then read the well-known address template file
185 # and write it to the manuf file.
187 open (WKATMPL, "< $wkatmpl") ||
188 die "Couldn't open well-known address template file for reading ($wkatmpl)\n";
190 # XXX - it'd be nice to get this from the Cavebear file, but inferring
191 # the address mask from entries in that file involves some work.
194 while ($line = <WKATMPL>) {
196 print(OUT "$line\n");
199 $total_added = $tmpl_added + $cb_added + $oui_added + $iab_added;
201 Original entries : $tmpl_added
202 IEEE OUI added : $oui_added
203 IEEE IAB added : $iab_added
204 CaveBear added : $cb_added
207 IEEE OUI skipped : $oui_skipped
208 IEEE IAB skipped : $iab_skipped
209 CaveBear skipped : $cb_skipped