Reduce the CinemaScope-like proportions of the preferences dialog by
[obnox/wireshark/wip.git] / make-manuf
1 #!/usr/bin/perl -w
2 #
3 # $Id: make-manuf,v 1.3 2001/10/07 22:19:14 guy Exp $
4 #
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.
10 #
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
14 # precedence.
15
16 # LWP is part of the standard Perl module libwww 
17 eval "require LWP::UserAgent;";
18 if( $@ ) {
19   die "LWP isn't installed. It is part of the standard Perl\n" .
20         " module libwww.  Bailing.\n";
21 }
22
23 $template = "manuf.tmpl";
24 $outfile  = "manuf";
25 $inheader = 1;
26 $ieee_url = "http://standards.ieee.org/regauth/oui/oui.txt";
27 $cb_url   = "http://www.cavebear.com/CaveBear/Ethernet/Ethernet.txt";
28 %oui_list = ();
29 $hp       = "[0-9a-fA-F]{2}";
30 $oui_re   = "$hp:$hp:$hp";
31 $cb_re    = "$hp$hp$hp";
32 $ieee_re  = "$hp-$hp-$hp";
33
34 $tmpl_added   = 0;
35 $cb_added     = 0;
36 $cb_skipped   = 0;
37 $ieee_added   = 0;
38 $ieee_skipped = 0;
39
40 $agent    = LWP::UserAgent->new;
41
42 print "Fetching $cb_url.\n";
43 $request  = HTTP::Request->new(GET => $cb_url);
44 $result   = $agent->request($request);
45
46 if (!$result->is_success) {
47   die ("Error fetching $cb_url: " . $result->status_line . "\n");
48 }
49 $cb_list = $result->content;
50
51 print "Fetching $ieee_url.\n";
52 $request  = HTTP::Request->new(GET => $ieee_url);
53 $result   = $agent->request($request);
54
55 if (!$result->is_success) {
56   die ("Error fetching $ieee_url: " . $result->status_line . "\n");
57 }
58 $ieee_list = $result->content;
59
60 open (TMPL, "< $template") || 
61   die "Couldn't open template file for reading ($template)\n";
62
63 open (OUT, "> $outfile") ||
64   die "Couldn't open template file for writing ($template)\n";
65
66 # Write out the header and populate the OUI list with our entries.
67 while ($line = <TMPL>) {
68   chomp($line);
69   if ($line !~ /^$oui_re\s+\S/ && $inheader) {
70     print(OUT "$line\n");
71   } elsif (($oui, $manuf) = ($line =~ /^($oui_re)\s+(\S.*)$/)) {
72     $inheader = 0;
73     # Ensure OUI is all upper-case
74     $oui =~ tr/a-f/A-F/;
75     $oui_list{$oui} = $manuf;
76     $tmpl_added++;
77   }
78 }
79
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
83     $oui = "$h1:$h2:$h3";
84     # Ensure OUI is all upper-case
85     $oui =~ tr/a-f/A-F/;
86     if (exists $oui_list{$oui}) {
87       printf "$oui - Skipping CaveBear \"$manuf\" in favor of \"$oui_list{$oui}\"\n";
88       $cb_skipped++;
89     } else {
90       $oui_list{$oui} = $manuf;
91       $cb_added++;
92     }
93   }
94 }
95
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
100     $oui =~ tr/a-f/A-F/;
101     if (exists $oui_list{$oui}) {
102       printf "$oui - Skipping IEEE \"$manuf\" in favor of \"$oui_list{$oui}\"\n";
103       $ieee_skipped++;
104     } else {
105       $oui_list{$oui} = $manuf;
106       $ieee_added++;
107     }
108   }
109 }
110
111 foreach $oui (sort(keys %oui_list)) {
112   print(OUT "$oui\t$oui_list{$oui}\n");
113 }
114
115 $total_added = $tmpl_added + $cb_added + $ieee_added;
116 print <<"Fin"
117 Original entries : $tmpl_added
118 CaveBear added   : $cb_added
119 IEEE added       : $ieee_added
120 Total            : $total_added
121
122 CaveBear skipped : $cb_skipped
123 IEEE skipped     : $ieee_skipped
124 Fin