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
18 eval "require LWP::UserAgent;";
20 die "LWP isn't installed. It is part of the standard Perl\n" .
21 " module libwww. Bailing.\n";
23 $agent = LWP::UserAgent->new;
25 $template = "manuf.tmpl";
26 $wkatmpl = "wka.tmpl";
29 $ieee_url = "http://standards.ieee.org/regauth/oui/oui_public.txt";
30 $cb_url = "http://www.cavebear.com/CaveBear/Ethernet/Ethernet.txt";
32 $hp = "[0-9a-fA-F]{2}";
33 $oui_re = "$hp:$hp:$hp";
35 $ieee_re = "$hp-$hp-$hp";
45 my $origmanuf = shift;
46 my $manuf = " " . $origmanuf . " ";
47 # Remove any punctuation
49 # & isn't needed when Standalone
51 # Remove any "the", "inc", "plc" ...
52 $manuf =~ s/\s(the|inc|incorporated|plc||systems|corp|corporation|a\/s|ab|ag|kg|gmbh|co|company|limited|ltd)(?= )//gi;
53 # Convert to consistent case
54 $manuf =~ s/(\w+)/\u\L$1/g;
57 # Truncate all names to a reasonable length, say 10 characters.
58 $manuf = substr($manuf, 0, 10);
60 if ($manuf =~ /\Q$origmanuf\E/i) {
63 return sprintf("%-22s # %s", $manuf, $origmanuf);
67 # Write out the header and populate the OUI list with our entries.
69 open (TMPL, "< $template") ||
70 die "Couldn't open template file for reading ($template)\n";
72 while ($line = <TMPL>) {
74 if ($line !~ /^$oui_re\s+\S/ && $inheader) {
76 } elsif (($oui, $manuf) = ($line =~ /^($oui_re)\s+(\S.*)$/)) {
78 # Ensure OUI is all upper-case
80 # $oui_list{$oui} = &shorten($manuf);
81 $oui_list{$oui} = $manuf;
86 # Add IEEE entries for OUIs not yet known.
88 print "Fetching $ieee_url.\n";
89 $request = HTTP::Request->new(GET => $ieee_url);
90 $result = $agent->request($request);
92 if (!$result->is_success) {
93 die ("Error fetching $ieee_url: " . $result->status_line . "\n");
95 $ieee_list = $result->content;
97 foreach $line (split(/\n/, $ieee_list)) {
98 if (($oui, $manuf) = ($line =~ /^($ieee_re)\s+\(hex\)\s+(\S.*)$/)) {
99 $oui =~ tr /-/:/; # The IEEE bytes are separated by dashes.
100 # Ensure OUI is all upper-case
102 if (exists $oui_list{$oui}) {
103 printf "$oui - Skipping IEEE \"$manuf\" in favor of \"$oui_list{$oui}\"\n";
106 $oui_list{$oui} = &shorten($manuf);
112 # Add CaveBear entries for OUIs not yet known.
114 print "Fetching $cb_url.\n";
115 $request = HTTP::Request->new(GET => $cb_url);
116 $result = $agent->request($request);
118 if (!$result->is_success) {
119 die ("Error fetching $cb_url: " . $result->status_line . "\n");
121 $cb_list = $result->content;
123 foreach $line (split(/\n/, $cb_list)) {
124 if (($oui, $manuf) = ($line =~ /^($cb_re)\s+(\S.*)$/)) {
125 ($h1, $h2, $h3) = ($oui =~ /($hp)($hp)($hp)/); # The CaveBear bytes have no separators
126 $oui = "$h1:$h2:$h3";
127 # Ensure OUI is all upper-case
129 if (exists $oui_list{$oui}) {
130 # printf "$oui - Skipping CaveBear \"$manuf\" in favor of \"$oui_list{$oui}\"\n";
133 printf "$oui - adding \"$manuf\" from CaveBear\n";
134 $oui_list{$oui} = &shorten($manuf);
142 open (OUT, "> $outfile") ||
143 die "Couldn't open output file for writing ($outfile)\n";
145 print(OUT "# This file was generated by running ./make-manuf.\n");
146 print(OUT "# Don't change it directly, change manuf.tmpl and wka.tmpl instead.\n#\n");
147 print(OUT "$header");
149 foreach $oui (sort(keys %oui_list)) {
150 print(OUT "$oui\t$oui_list{$oui}\n");
153 # Write out a blank line separating the OUIs from the well-known
154 # addresses, and then read the well-known address template file
155 # and write it to the manuf file.
157 open (WKATMPL, "< $wkatmpl") ||
158 die "Couldn't open well-known address template file for reading ($wkatmpl)\n";
160 # XXX - it'd be nice to get this from the Cavebear file, but inferring
161 # the address mask from entries in that file involves some work.
164 while ($line = <WKATMPL>) {
166 print(OUT "$line\n");
169 $total_added = $tmpl_added + $cb_added + $ieee_added;
171 Original entries : $tmpl_added
172 IEEE added : $ieee_added
173 CaveBear added : $cb_added
176 IEEE skipped : $ieee_skipped
177 CaveBear skipped : $cb_skipped