Witness: enum witness_notifyResponse_type
[wireshark-wip.git] / tools / make-services.pl
blob91d5e26b8ae09fd9c0cb24b5b6e1fe6168377330
1 #!/usr/bin/perl -w
2 # create the services file from
3 # http://www.iana.org/assignments/enterprise-numbers
5 # $Id$
7 # Wireshark - Network traffic analyzer
8 # By Gerald Combs <gerald@wireshark.org>
9 # Copyright 2004 Gerald Combs
11 # This program is free software; you can redistribute it and/or
12 # modify it under the terms of the GNU General Public License
13 # as published by the Free Software Foundation; either version 2
14 # of the License, or (at your option) any later version.
16 # This program is distributed in the hope that it will be useful,
17 # but WITHOUT ANY WARRANTY; without even the implied warranty of
18 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 # GNU General Public License for more details.
21 # You should have received a copy of the GNU General Public License
22 # along with this program; if not, write to the Free Software
23 # Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
24 use strict;
25 use English;
27 my $svc_file = "services";
28 my $in = shift;
29 my $min_size = 2000000; # Size was 2654612 on 2011-08-31
30 my @exclude_pats = qw(
31 ^spr-itunes
32 ^spl-itunes
33 ^shilp
35 my $iana_port_url = "http://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.txt";
37 # As of August 2011, the page linked from http://www.iana.org/protocols/
38 # is XML. Perhaps we should parse that instead.
39 $in = $iana_port_url unless(defined $in);
41 my $revision = '$Revision$';
42 if ($revision !~ /[0-9]/ ) { $revision = "unknown"; }
44 my $body = "";
46 if($in =~ m/^http:/i) {
47 eval "require LWP::UserAgent;";
48 die "LWP isn't installed. It is part of the standard Perl module libwww." if $@;
50 my $agent = LWP::UserAgent->new;
51 $agent->env_proxy;
52 $agent->agent("Wireshark make-services.pl/$revision");
54 warn "starting to fetch $in ...\n";
56 my $request = HTTP::Request->new(GET => $in);
59 if (-f $svc_file) {
60 my $mtime;
61 (undef,undef,undef,undef,undef,undef,undef,$min_size,undef,$mtime,undef,undef,undef) = stat($svc_file);
62 $request->if_modified_since( $mtime );
65 my $result = $agent->request($request);
67 if ($result->code eq 200) {
68 warn "done fetching $in\n";
69 my @in_lines = split /\n/, $result->content;
70 my $prefix = "";
71 my $exclude_match;
72 my $line;
73 my $pat;
74 foreach $line (@in_lines) {
75 $prefix = "# ";
76 $exclude_match = 0;
78 if ($line =~ /^(\S+)\s+(\d+)\s+(tcp|udp|sctp|dccp)\s+(\S.*)/) {
79 $line = "$1 $2/$3 # $4";
81 foreach $pat (@exclude_pats) {
82 if ($line =~ $pat) {
83 $exclude_match = 1;
84 last;
88 if ($exclude_match) {
89 $body .= "# Excluded by $PROGRAM_NAME\n";
90 } else {
91 $prefix = "";
95 $line =~ s/^\s+|\s+$//g;
97 $body .= $prefix . $line . "\n";
99 } elsif ($result->code eq 304) {
100 warn "$svc_file was up-to-date\n";
101 exit 0;
102 } else {
103 die "request for $in failed with result code:" . $result->code;
106 } else {
107 open IN, "< $in";
108 $body = <IN>;
109 close IN;
112 if (length($body) < $min_size * 0.9) {
113 die "$in doesn't have enough data\n";
116 open OUT, "> $svc_file";
118 print OUT <<"_HEADER";
119 # This is a local copy of the IANA port-numbers file.
121 # \$Id\$
123 # Wireshark uses it to resolve port numbers into human readable
124 # service names, e.g. TCP port 80 -> http.
126 # It is subject to copyright and being used with IANA's permission:
127 # http://www.wireshark.org/lists/wireshark-dev/200708/msg00160.html
129 # The original file can be found at:
130 # $iana_port_url
132 $body
133 _HEADER
135 close OUT;