2 # create the sminmpec.c file from
3 # http://www.iana.org/assignments/enterprise-numbers
5 # Wireshark - Network traffic analyzer
6 # By Gerald Combs <gerald@wireshark.org>
7 # Copyright 2004 Gerald Combs
9 # This program is free software; you can redistribute it and/or
10 # modify it under the terms of the GNU General Public License
11 # as published by the Free Software Foundation; either version 2
12 # of the License, or (at your option) any later version.
14 # This program is distributed in the hope that it will be useful,
15 # but WITHOUT ANY WARRANTY; without even the implied warranty of
16 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 # GNU General Public License for more details.
19 # You should have received a copy of the GNU General Public License
20 # along with this program; if not, write to the Free Software
21 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
26 my ($vol, $script_dir, $file) = File::Spec->splitpath( __FILE__ );
27 my $epan_dir = File::Spec->catpath($vol, $script_dir, '../epan');
28 chdir($epan_dir) || die("Can't find $epan_dir");
32 $in = "http://www.iana.org/assignments/enterprise-numbers" unless(defined $in);
35 my $revision = '2014-04-27';
37 my $min_entries = 100;
40 if($in =~ m/^http:/i) {
41 eval "require LWP::UserAgent;";
42 die "LWP isn't installed. It is part of the standard Perl module libwww." if $@;
44 my $agent = LWP::UserAgent->new;
46 $agent->agent("Wireshark make-sminmpec.pl/$revision");
48 warn "starting to fetch $in ...\n";
50 my $request = HTTP::Request->new(GET => $in);
52 my $result = $agent->request($request);
54 if ($result->code eq 200) {
55 warn "done fetching $in\n";
56 @in_lines = split /\n/, $result->content;
57 open ENFILE, "> enterprise-numbers";
65 } elsif ($result->code eq 304) {
66 warn "enterprise-numbers was up-to-date\n";
67 open IN, "< enterprise-numbers";
71 die "request for $in failed with result code:" . $result->code;
83 my $prev_code = -1; ## Assumption: First code in enterprise file is 0;
85 sub escape_non_ascii {
86 my $val = unpack 'C', $_[0];
87 return sprintf '\0%.3o',$val;
95 s/([\x80-\xFF])/escape_non_ascii($1)/ge;
98 $code = sprintf("%5d", $1);
101 if ($code < $prev_code) {
102 print STDERR ("Input 'Codes' not sorted in ascending order (or duplicate codes)): $prev_code $code\n");
105 while ($code > ($prev_code+1)) {
106 $prev_code = sprintf("%5d", $prev_code+1);
107 $body .= " { $prev_code, sminmpec_unknown }, /* (Added by Wireshark) */\n";
110 $body .= " { $code, \"$name\" },\n";
115 # If this happens check what IANA is serving.
116 # XXX We already overwrote enterprise-numbers above.
117 if ($smi_total < $smi_total) { die "Too few SMI entries ($smi_total)\n"; }
119 open OUT, "> sminmpec.c";
121 print OUT <<"_SMINMPEC";
123 * THIS FILE IS AUTOGENERATED, DO NOT EDIT
124 * generated from http://www.iana.org/assignments/enterprise-numbers
125 * run "tools/make-sminmpec.pl <infile> <outfile>" to regenerate
127 * Note 1: "Gaps" in the iana enterprise-numbers list have been "filled in"
128 * with "(Unknown)" as the name so that direct (indexed) access to
129 * the list is possible.
131 * Note 2: We should probably parse "enterprise-numbers" at program start
132 * instead of generating this file.
138 #include <epan/value_string.h>
139 #include <epan/sminmpec.h>
141 static const gchar sminmpec_unknown[] = "(Unknown)";
143 const value_string sminmpec_values[] = {
147 #define array_length(x) (sizeof x / sizeof x[0])
149 value_string_ext sminmpec_values_ext = VALUE_STRING_EXT_INIT(sminmpec_values);