nexmon – Blame information for rev 1
?pathlinks?
Rev | Author | Line No. | Line |
---|---|---|---|
1 | office | 1 | #!/usr/bin/perl -w |
2 | # create the sminmpec.c file from |
||
3 | # http://www.iana.org/assignments/enterprise-numbers |
||
4 | # |
||
5 | # Wireshark - Network traffic analyzer |
||
6 | # By Gerald Combs <gerald@wireshark.org> |
||
7 | # Copyright 2004 Gerald Combs |
||
8 | # |
||
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. |
||
13 | # |
||
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. |
||
18 | # |
||
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. |
||
22 | |||
23 | use strict; |
||
24 | use File::Spec; |
||
25 | |||
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"); |
||
29 | |||
30 | my $in = shift; |
||
31 | |||
32 | $in = "http://www.iana.org/assignments/enterprise-numbers" unless(defined $in); |
||
33 | |||
34 | my @in_lines; |
||
35 | my $revision = '2014-04-27'; |
||
36 | |||
37 | my $min_entries = 100; |
||
38 | my $smi_total = 0; |
||
39 | |||
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 $@; |
||
43 | |||
44 | my $agent = LWP::UserAgent->new; |
||
45 | $agent->env_proxy; |
||
46 | $agent->agent("Wireshark make-sminmpec.pl/$revision"); |
||
47 | |||
48 | warn "starting to fetch $in ...\n"; |
||
49 | |||
50 | my $request = HTTP::Request->new(GET => $in); |
||
51 | |||
52 | my $result = $agent->request($request); |
||
53 | |||
54 | if ($result->code eq 200) { |
||
55 | warn "done fetching $in\n"; |
||
56 | @in_lines = split /\n/, $result->content; |
||
57 | open ENFILE, "> enterprise-numbers"; |
||
58 | |||
59 | for (@in_lines) { |
||
60 | chomp; |
||
61 | print ENFILE "$_\n"; |
||
62 | } |
||
63 | |||
64 | close ENFILE; |
||
65 | } elsif ($result->code eq 304) { |
||
66 | warn "enterprise-numbers was up-to-date\n"; |
||
67 | open IN, "< enterprise-numbers"; |
||
68 | @in_lines = <IN>; |
||
69 | close IN; |
||
70 | } else { |
||
71 | die "request for $in failed with result code:" . $result->code; |
||
72 | } |
||
73 | |||
74 | } else { |
||
75 | open IN, "< $in"; |
||
76 | @in_lines = <IN>; |
||
77 | close IN; |
||
78 | } |
||
79 | |||
80 | |||
81 | my $body = ''; |
||
82 | my $code; |
||
83 | my $prev_code = -1; ## Assumption: First code in enterprise file is 0; |
||
84 | |||
85 | sub escape_non_ascii { |
||
86 | my $val = unpack 'C', $_[0]; |
||
87 | return sprintf '\0%.3o',$val; |
||
88 | } |
||
89 | |||
90 | |||
91 | for(@in_lines) { |
||
92 | s/[\000-\037]//g; |
||
93 | s/\\/\\\\/g; |
||
94 | s/"/\\"/g; |
||
95 | s/([\x80-\xFF])/escape_non_ascii($1)/ge; |
||
96 | |||
97 | if (/^(\d+)/) { |
||
98 | $code = sprintf("%5d", $1); |
||
99 | } if (/^ (\S.*)/ ) { |
||
100 | my $name = $1; |
||
101 | if ($code < $prev_code) { |
||
102 | print STDERR ("Input 'Codes' not sorted in ascending order (or duplicate codes)): $prev_code $code\n"); |
||
103 | exit 1; |
||
104 | } |
||
105 | while ($code > ($prev_code+1)) { |
||
106 | $prev_code = sprintf("%5d", $prev_code+1); |
||
107 | $body .= " { $prev_code, sminmpec_unknown }, /* (Added by Wireshark) */\n"; |
||
108 | } |
||
109 | $prev_code = $code; |
||
110 | $body .= " { $code, \"$name\" },\n"; |
||
111 | $smi_total++; |
||
112 | } |
||
113 | } |
||
114 | |||
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"; } |
||
118 | |||
119 | open OUT, "> sminmpec.c"; |
||
120 | |||
121 | print OUT <<"_SMINMPEC"; |
||
122 | /* |
||
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 |
||
126 | * |
||
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. |
||
130 | * |
||
131 | * Note 2: We should probably parse "enterprise-numbers" at program start |
||
132 | * instead of generating this file. |
||
133 | */ |
||
134 | #include "config.h" |
||
135 | |||
136 | #include <glib.h> |
||
137 | |||
138 | #include <epan/value_string.h> |
||
139 | #include <epan/sminmpec.h> |
||
140 | |||
141 | static const gchar sminmpec_unknown[] = "(Unknown)"; |
||
142 | |||
143 | const value_string sminmpec_values[] = { |
||
144 | $body { 0, NULL} |
||
145 | }; |
||
146 | |||
147 | #define array_length(x) (sizeof x / sizeof x[0]) |
||
148 | |||
149 | value_string_ext sminmpec_values_ext = VALUE_STRING_EXT_INIT(sminmpec_values); |
||
150 | |||
151 | _SMINMPEC |
||
152 | |||
153 | close OUT; |