-#!/usr/bin/perl
+#!/usr/bin/perl -w
# create the sminmpec.c file from
# http://www.iana.org/assignments/enterprise-numbers
#
-# $Id $
+# $Id$
#
-# Ethereal - Network traffic analyzer
-# By Gerald Combs <gerald@ethereal.com>
+# Wireshark - Network traffic analyzer
+# By Gerald Combs <gerald@wireshark.org>
# Copyright 2004 Gerald Combs
#
# This program is free software; you can redistribute it and/or
use strict;
my $in = shift;
-my $out = shift;
-open IN, "< $in";
-open OUT, "> $out";
+$in = "http://www.iana.org/assignments/enterprise-numbers" unless(defined $in);
+
+my @in_lines;
+
+if($in =~ m/^http:/i) {
+ eval "require LWP::UserAgent;";
+ die "LWP isn't installed. It is part of the standard Perl module libwww." if $@;
+
+ my $agent = LWP::UserAgent->new;
+
+ warn "starting to fetch $in ...\n";
+
+ my $request = HTTP::Request->new(GET => $in);
+
+
+ if (-f "enterprise-numbers") {
+ my $mtime;
+ (undef,undef,undef,undef,undef,undef,undef,undef,undef,$mtime,undef,undef,undef) = stat("enterprise-numbers");
+ $request->if_modified_since( $mtime );
+ }
+
+ my $result = $agent->request($request);
+
+ if ($result->code eq 200) {
+ warn "done fetching $in\n";
+ @in_lines = split /\n/, $result->content;
+ open ENFILE, "> enterprise-numbers";
+
+ for (@in_lines) {
+ chomp;
+ print ENFILE "$_\n";
+ }
+
+ close ENFILE;
+ } elsif ($result->code eq 304) {
+ warn "enterprise-numbers was up-to-date\n";
+ open IN, "< enterprise-numbers";
+ @in_lines = <IN>;
+ close IN;
+ } else {
+ die "request for $in failed with result code:" . $result->code;
+ }
+
+} else {
+ open IN, "< $in";
+ @in_lines = <IN>;
+ close IN;
+}
+
+
+open OUT, "> sminmpec.c";
my $body = '';
my $code;
return sprintf '\0%.3o',$val;
}
-while(<IN>) {
+for(@in_lines) {
s/[\000-\037]//g;
s/\\/\\\\/g;
s/"/\\"/g;
}
}
-close IN;
-
print OUT <<"_SMINMPEC";
-/* THIS FILE IS AUTOGENERATED, DO NOT EDIT */
-/* generated from http://www.iana.org/assignments/enterprise-numbers */
+/*
+ * THIS FILE IS AUTOGENERATED, DO NOT EDIT
+ * generated from http://www.iana.org/assignments/enterprise-numbers
+ * run "epan/make-sminmspec <infile> <outfile>" to regenerate
+ */
#ifdef HAVE_CONFIG_H
# include "config.h"
#endif