2 # create the services 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.
25 my $svc_file = "services";
27 my $min_size = 2000000; # Size was 2654612 on 2011-08-31
28 my @exclude_pats = qw(
33 my $iana_port_url = "http://www.iana.org/assignments/service-names-port-numbers/service-names-port-numbers.txt";
35 # As of August 2011, the page linked from http://www.iana.org/protocols/
36 # is XML. Perhaps we should parse that instead.
37 $in = $iana_port_url unless(defined $in);
41 if($in =~ m/^http:/i) {
42 eval "require LWP::UserAgent;";
43 die "LWP isn't installed. It is part of the standard Perl module libwww." if $@;
45 my $agent = LWP::UserAgent->new;
47 $agent->agent("Wireshark make-services.pl");
49 warn "starting to fetch $in ...\n";
51 my $request = HTTP::Request->new(GET => $in);
56 (undef,undef,undef,undef,undef,undef,undef,$min_size,undef,$mtime,undef,undef,undef) = stat($svc_file);
57 $request->if_modified_since( $mtime );
60 my $result = $agent->request($request);
62 if ($result->code eq 200) {
63 warn "done fetching $in\n";
64 my @in_lines = split /\n/, $result->content;
69 foreach $line (@in_lines) {
73 if ($line =~ /^(\S+)\s+(\d+)\s+(tcp|udp|sctp|dccp)\s+(\S.*)/) {
74 $line = "$1 $2/$3 # $4";
76 foreach $pat (@exclude_pats) {
84 $body .= "# Excluded by $PROGRAM_NAME\n";
90 $line =~ s/^\s+|\s+$//g;
92 $body .= $prefix . $line . "\n";
94 } elsif ($result->code eq 304) {
95 warn "$svc_file was up-to-date\n";
98 die "request for $in failed with result code:" . $result->code;
107 if (length($body) < $min_size * 0.9) {
108 die "$in doesn't have enough data\n";
111 open OUT, "> $svc_file";
113 print OUT <<"_HEADER";
114 # This is a local copy of the IANA port-numbers file.
116 # Wireshark uses it to resolve port numbers into human readable
117 # service names, e.g. TCP port 80 -> http.
119 # It is subject to copyright and being used with IANA's permission:
120 # http://www.wireshark.org/lists/wireshark-dev/200708/msg00160.html
122 # The original file can be found at: