Add makefiles
[obnox/wireshark/wip.git] / make-manuf
index 26f128cc7ba46177f4ab11028b37c92cfe759877..9a68636023a52b5b51cd9e9211fa1de84adf25f2 100755 (executable)
@@ -1,6 +1,6 @@
 #!/usr/bin/perl -w
 #
-# $Id: make-manuf,v 1.3 2001/10/07 22:19:14 guy Exp $
+# $Id$
 #
 # Make-manuf - Creates a file containing ethernet OUIs and their
 # company IDs.  It merges the databases at
 # precedence.
 
 # LWP is part of the standard Perl module libwww 
+
 eval "require LWP::UserAgent;";
 if( $@ ) {
   die "LWP isn't installed. It is part of the standard Perl\n" .
        " module libwww.  Bailing.\n";
 }
+$agent    = LWP::UserAgent->new;
 
 $template = "manuf.tmpl";
+$wkatmpl  = "wka.tmpl";
 $outfile  = "manuf";
 $inheader = 1;
-$ieee_url = "http://standards.ieee.org/regauth/oui/oui.txt";
+$ieee_url = "http://standards.ieee.org/regauth/oui/oui_public.txt";
 $cb_url   = "http://www.cavebear.com/CaveBear/Ethernet/Ethernet.txt";
 %oui_list = ();
 $hp       = "[0-9a-fA-F]{2}";
@@ -37,61 +40,59 @@ $cb_skipped   = 0;
 $ieee_added   = 0;
 $ieee_skipped = 0;
 
-$agent    = LWP::UserAgent->new;
-
-print "Fetching $cb_url.\n";
-$request  = HTTP::Request->new(GET => $cb_url);
-$result   = $agent->request($request);
-
-if (!$result->is_success) {
-  die ("Error fetching $cb_url: " . $result->status_line . "\n");
+sub shorten
+{
+  my $origmanuf = shift; 
+  my $manuf = " " . $origmanuf . " ";
+  # Remove any punctuation
+  $manuf =~ tr/',.()/    /;
+  # & isn't needed when Standalone
+  $manuf =~ s/ \& / /g;
+  # Remove any "the", "inc", "plc" ...
+  $manuf =~ s/\s(the|inc|incorporated|plc||systems|corp|corporation|s\/a|a\/s|ab|ag|kg|gmbh|co|company|limited|ltd)(?= )//gi;
+  # Convert to consistent case
+  $manuf =~ s/(\w+)/\u\L$1/g;
+  # Remove all spaces
+  $manuf =~ s/\s+//g;
+  # Truncate all names to a reasonable length, say 10 characters.
+  $manuf = substr($manuf, 0, 10);
+
+  if ($manuf =~ /\Q$origmanuf\E/i) {
+    return $manuf;
+  } else {
+    return sprintf("%-22s # %s", $manuf, $origmanuf);
+  }
 }
-$cb_list = $result->content;
-
-print "Fetching $ieee_url.\n";
-$request  = HTTP::Request->new(GET => $ieee_url);
-$result   = $agent->request($request);
 
-if (!$result->is_success) {
-  die ("Error fetching $ieee_url: " . $result->status_line . "\n");
-}
-$ieee_list = $result->content;
+# Write out the header and populate the OUI list with our entries.
 
 open (TMPL, "< $template") || 
   die "Couldn't open template file for reading ($template)\n";
 
-open (OUT, "> $outfile") ||
-  die "Couldn't open template file for writing ($template)\n";
-
-# Write out the header and populate the OUI list with our entries.
 while ($line = <TMPL>) {
   chomp($line);
   if ($line !~ /^$oui_re\s+\S/ && $inheader) {
-    print(OUT "$line\n");
+    $header .= "$line\n";
   } elsif (($oui, $manuf) = ($line =~ /^($oui_re)\s+(\S.*)$/)) {
     $inheader = 0;
     # Ensure OUI is all upper-case
     $oui =~ tr/a-f/A-F/;
+    # $oui_list{$oui} = &shorten($manuf);
     $oui_list{$oui} = $manuf;
     $tmpl_added++;
   }
 }
 
-foreach $line (split(/\n/, $cb_list)) {
-  if (($oui, $manuf) = ($line =~ /^($cb_re)\s+(\S.*)$/)) {
-    ($h1, $h2, $h3) = ($oui =~ /($hp)($hp)($hp)/);  # The CaveBear bytes have no separators
-    $oui = "$h1:$h2:$h3";
-    # Ensure OUI is all upper-case
-    $oui =~ tr/a-f/A-F/;
-    if (exists $oui_list{$oui}) {
-      printf "$oui - Skipping CaveBear \"$manuf\" in favor of \"$oui_list{$oui}\"\n";
-      $cb_skipped++;
-    } else {
-      $oui_list{$oui} = $manuf;
-      $cb_added++;
-    }
-  }
+# Add IEEE entries for OUIs not yet known.
+
+print "Fetching $ieee_url.\n";
+$request  = HTTP::Request->new(GET => $ieee_url);
+$result   = $agent->request($request);
+
+if (!$result->is_success) {
+  die ("Error fetching $ieee_url: " . $result->status_line . "\n");
 }
+$ieee_list = $result->content;
 
 foreach $line (split(/\n/, $ieee_list)) {
   if (($oui, $manuf) = ($line =~ /^($ieee_re)\s+\(hex\)\s+(\S.*)$/)) {
@@ -102,23 +103,76 @@ foreach $line (split(/\n/, $ieee_list)) {
       printf "$oui - Skipping IEEE \"$manuf\" in favor of \"$oui_list{$oui}\"\n";
       $ieee_skipped++;
     } else {
-      $oui_list{$oui} = $manuf;
+      $oui_list{$oui} = &shorten($manuf);
       $ieee_added++;
     }
   }
 }
 
+# Add CaveBear entries for OUIs not yet known.
+
+print "Fetching $cb_url.\n";
+$request  = HTTP::Request->new(GET => $cb_url);
+$result   = $agent->request($request);
+
+if (!$result->is_success) {
+  die ("Error fetching $cb_url: " . $result->status_line . "\n");
+}
+$cb_list = $result->content;
+
+foreach $line (split(/\n/, $cb_list)) {
+  if (($oui, $manuf) = ($line =~ /^($cb_re)\s+(\S.*)$/)) {
+    ($h1, $h2, $h3) = ($oui =~ /($hp)($hp)($hp)/);  # The CaveBear bytes have no separators
+    $oui = "$h1:$h2:$h3";
+    # Ensure OUI is all upper-case
+    $oui =~ tr/a-f/A-F/;
+    if (exists $oui_list{$oui}) {
+      # printf "$oui - Skipping CaveBear \"$manuf\" in favor of \"$oui_list{$oui}\"\n";
+      $cb_skipped++;
+    } else {
+      printf "$oui - adding \"$manuf\" from CaveBear\n";
+      $oui_list{$oui} = &shorten($manuf);
+      $cb_added++;
+    }
+  }
+}
+
+# Write output file
+
+open (OUT, "> $outfile") ||
+  die "Couldn't open output file for writing ($outfile)\n";
+
+print(OUT "# This file was generated by running ./make-manuf.\n");
+print(OUT "# Don't change it directly, change manuf.tmpl and wka.tmpl instead.\n#\n");
+print(OUT "$header");
+
 foreach $oui (sort(keys %oui_list)) {
   print(OUT "$oui\t$oui_list{$oui}\n");
 }
 
+# Write out a blank line separating the OUIs from the well-known
+# addresses, and then read the well-known address template file
+# and write it to the manuf file.
+
+open (WKATMPL, "< $wkatmpl") || 
+  die "Couldn't open well-known address template file for reading ($wkatmpl)\n";
+
+# XXX - it'd be nice to get this from the Cavebear file, but inferring
+# the address mask from entries in that file involves some work.
+#
+print(OUT "\n");
+while ($line = <WKATMPL>) {
+  chomp($line);
+  print(OUT "$line\n");
+}
+
 $total_added = $tmpl_added + $cb_added + $ieee_added;
 print <<"Fin"
 Original entries : $tmpl_added
-CaveBear added   : $cb_added
 IEEE added       : $ieee_added
+CaveBear added   : $cb_added
 Total            : $total_added
 
-CaveBear skipped : $cb_skipped
 IEEE skipped     : $ieee_skipped
+CaveBear skipped : $cb_skipped
 Fin