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|holding|spa)(?= )//gi;
59 # Convert to consistent case
60 $manuf =~ s/(\w+)/\u\L$1/g;
63 # Truncate all names to a reasonable length, say, 8 characters.
64 # If the string contains UTF-8, this may be substantially more than 8 bytes.
65 $manuf = substr($manuf, 0, 8);
67 if ($manuf =~ /\Q$origmanuf\E/i) {
70 return sprintf("%-22s # %s", $manuf, $origmanuf);
77 print "Fetching $url.\n";
78 $request = HTTP::Request->new(GET => $url);
79 $result = $agent->request($request);
81 if (!$result->is_success) {
82 die ("Error fetching $url: " . $result->status_line . "\n");
84 return decode("iso-8859-1", $result->content);
87 # Write out the header and populate the OUI list with our entries.
89 open (TMPL, "< $template") ||
90 die "Couldn't open template file for reading ($template)\n";
92 while ($line = <TMPL>) {
94 if ($line !~ /^$oui_re\s+\S/ && $inheader) {
96 } elsif (($oui, $manuf) = ($line =~ /^($oui_re)\s+(\S.*)$/)) {
98 # Ensure OUI is all upper-case
100 # $oui_list{$oui} = &shorten($manuf);
101 $oui_list{$oui} = $manuf;
106 # Add IEEE entries for IABs
108 $ieee_list = fetch($iab_url);
110 foreach $line (split(/\n/, $ieee_list)) {
111 # determine the OUI used for IAB (currently only 00-50-C2)
112 if (($iab_tmp, $manuf) = ($line =~ /^($ieee_re)\s+\(hex\)\s+(\S.*)$/)) {
113 $iab_base = $iab_tmp;
115 # determine next two bytes
116 if (($iab4, $iab5, $manuf) = ($line =~ /^($hp)($hp)$hp-$hp$hp$hp\s+\(base\s16\)\s+(\S.*)$/)) {
117 $iab = "$iab_base:$iab4:$iab5:00/36";
118 $iab =~ tr /-/:/; # The IEEE bytes are separated by dashes.
119 # Ensure IAB is all upper-case
121 if (exists $oui_list{$iab}) {
122 printf "$iab - Skipping IEEE \"$manuf\" in favor of \"$oui_list{$iab}\"\n";
125 $oui_list{$iab} = &shorten($manuf);
131 # Add IEEE entries for OUIs not yet known.
133 $ieee_list = fetch($oui_url);
135 foreach $line (split(/\n/, $ieee_list)) {
136 if (($oui, $manuf) = ($line =~ /^($ieee_re)\s+\(hex\)\s+(\S.*)$/)) {
137 $oui =~ tr /-/:/; # The IEEE bytes are separated by dashes.
138 # Ensure OUI is all upper-case
140 if (exists $oui_list{$oui}) {
141 printf "$oui - Skipping IEEE \"$manuf\" in favor of \"$oui_list{$oui}\"\n";
144 $oui_list{$oui} = &shorten($manuf);
150 # Add CaveBear entries for OUIs not yet known.
152 $cb_list = fetch($cb_url);
154 foreach $line (split(/\n/, $cb_list)) {
155 if (($oui, $manuf) = ($line =~ /^($cb_re)\s+(\S.*)$/)) {
156 ($h1, $h2, $h3) = ($oui =~ /($hp)($hp)($hp)/); # The CaveBear bytes have no separators
157 $oui = "$h1:$h2:$h3";
158 # Ensure OUI is all upper-case
160 if (exists $oui_list{$oui}) {
161 # printf "$oui - Skipping CaveBear \"$manuf\" in favor of \"$oui_list{$oui}\"\n";
164 printf "$oui - adding \"$manuf\" from CaveBear\n";
165 $oui_list{$oui} = &shorten($manuf);
173 open (OUT, "> $outfile") ||
174 die "Couldn't open output file for writing ($outfile)\n";
176 print(OUT "# This file was generated by running ./make-manuf.\n");
177 print(OUT "# Don't change it directly, change manuf.tmpl and wka.tmpl instead.\n#\n");
178 print(OUT "$header");
180 foreach $oui (sort(keys %oui_list)) {
181 print(OUT "$oui\t$oui_list{$oui}\n");
184 # Write out a blank line separating the OUIs from the well-known
185 # addresses, and then read the well-known address template file
186 # and write it to the manuf file.
188 open (WKATMPL, "< $wkatmpl") ||
189 die "Couldn't open well-known address template file for reading ($wkatmpl)\n";
191 # XXX - it'd be nice to get this from the Cavebear file, but inferring
192 # the address mask from entries in that file involves some work.
195 while ($line = <WKATMPL>) {
197 print(OUT "$line\n");
200 $total_added = $tmpl_added + $cb_added + $oui_added + $iab_added;
202 Original entries : $tmpl_added
203 IEEE OUI added : $oui_added
204 IEEE IAB added : $iab_added
205 CaveBear added : $cb_added
208 IEEE OUI skipped : $oui_skipped
209 IEEE IAB skipped : $iab_skipped
210 CaveBear skipped : $cb_skipped