tests: add regression tests for Follow TCP Stream
[metze/wireshark/wip.git] / tools / make-sminmpec.pl
1 #!/usr/bin/perl -w
2 # create the enterprises 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 # SPDX-License-Identifier: GPL-2.0-or-later
10
11 use strict;
12 use File::Spec;
13
14 my ($vol, $script_dir) = File::Spec->splitpath( __FILE__ );
15 my $root_dir = File::Spec->catpath($vol, $script_dir, "..");
16 chdir($root_dir) || die("Can't find $root_dir");
17
18 my $in = shift;
19
20 $in = "http://www.iana.org/assignments/enterprise-numbers" unless(defined $in);
21
22 my @in_lines;
23 my $revision = '2014-04-27';
24
25 my $min_entries = 100;
26 my $smi_total = 0;
27
28 if($in =~ m/^http:/i) {
29         eval "require LWP::UserAgent;";
30         die "LWP isn't installed. It is part of the standard Perl module libwww." if $@;
31
32         my $agent    = LWP::UserAgent->new;
33         $agent->env_proxy;
34         $agent->agent("Wireshark make-sminmpec.pl/$revision");
35
36         warn "starting to fetch $in ...\n";
37
38         my $request  = HTTP::Request->new(GET => $in);
39
40         my $result   = $agent->request($request);
41
42         if ($result->code eq 200) {
43                 warn "done fetching $in\n";
44                 @in_lines = split /\n/, $result->content;
45         } else {
46                 die "request for $in failed with result code:" . $result->code;
47         }
48 } else {
49   open IN, "< $in";
50   @in_lines = <IN>;
51   close IN;
52 }
53
54 my $body = '';
55 my $code;
56 my $name;
57 my $last_updated = "(last updated ???)";
58 my $end_of_document = 0;
59
60 for(@in_lines) {
61         chomp;
62
63         if (/^(\d+)/) {
64                 $code = sprintf("%d", $1);
65         } elsif (/^   ?(\S.*)/ ) { # up to three spaces because of formatting errors in the source
66                 $name = $1;
67                 next if (/^\s*\(?\s*unassigned/i);
68                 $name =~ s/\s+$//;
69                 $name =~ s/ \((formerly .*)\)/\t# $1/;
70                 $body .= "\n$code\t$name";
71         } elsif (/\(last updated/i) {
72                 $last_updated = $_;
73         } elsif (/^ *End of Document/) {
74                 $end_of_document = 1;
75         }
76 }
77
78 die "\"End of Document\" not found. Truncated source file?" unless ($end_of_document);
79
80 open OUT, "> enterprises.tsv";
81
82 print OUT <<"_SMINMPEC";
83 #
84 # generated from http://www.iana.org/assignments/enterprise-numbers
85 # run "tools/make-sminmpec.pl [infile]" to regenerate
86 #
87 # The format used here is: <NUMERICAL_ID><SPACE><NAME>
88 # Where SPACE can be any sequence of spaces and tabs.
89 #
90 # $last_updated
91 $body
92 _SMINMPEC
93
94 close OUT;