#!/usr/bin/perl

#  $Id: ripe2rpsl 1.4 Thu, 23 Apr 1998 19:52:07 -0700 wlee $
#  Copyright (c) 1994 by the University of Southern California
#  All rights reserved.
#
#  Permission to use, copy, modify, and distribute this software and its
#  documentation in source and binary forms for lawful non-commercial
#  purposes and without fee is hereby granted, provided that the above
#  copyright notice appear in all copies and that both the copyright
#  notice and this permission notice appear in supporting documentation,
#  and that any documentation, advertising materials, and other materials
#  related to such distribution and use acknowledge that the software was
#  developed by the University of Southern California, Information
#  Sciences Institute. The name of the USC may not be used to endorse or
#  promote products derived from this software without specific prior
#  written permission.
#
#  THE UNIVERSITY OF SOUTHERN CALIFORNIA DOES NOT MAKE ANY
#  REPRESENTATIONS ABOUT THE SUITABILITY OF THIS SOFTWARE FOR ANY
#  PURPOSE.  THIS SOFTWARE IS PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR
#  IMPLIED WARRANTIES, INCLUDING, WITHOUT LIMITATION, THE IMPLIED
#  WARRANTIES OF MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE,
#  TITLE, AND NON-INFRINGEMENT.
#
#  IN NO EVENT SHALL USC, OR ANY OTHER CONTRIBUTOR BE LIABLE FOR ANY
#  SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES, WHETHER IN CONTRACT, TORT,
#  OR OTHER FORM OF ACTION, ARISING OUT OF OR IN CONNECTION WITH, THE USE
#  OR PERFORMANCE OF THIS SOFTWARE.
#
#  Questions concerning this software should be directed to 
#  ratoolset@isi.edu.
#
#  Author(s): Cengiz Alaettinoglu <cengiz@isi.edu>
#  Author(s): David Kessens <davidk@isi.edu>

# 1. convert ripe line continuations to rpsl style
#      A note on ripe 181: A line can be continued to the next line 
#      by repeating everything upto the policy expression.
#      E.g.
#      as-in: AS1 1 ANY AND NOT
#      as-in: AS1 1 AS1
#     
#      is equivalant to
#      as-in: AS1 1 ANY AND NOT AS1
# 2.

#
# changes:
#
# bugs: - extra newline added by beatifier
#       - mnt-by for anybody
#       - *em: nobody@nowhere.net bad hack

#
# start included stuff from the RPSL RIPE database for conversions and fixes
# of RIPE181 -> RPSL

#
# from Makefile

$AF_INET=2;

#
# modified and simplified logmessage routine 

sub logmessage {
    local($log, @strings) = @_;

    print STDERR @strings, "\n";

}


#
# hardcoded from config file

$AUTOBOX='auto-dbm@ISI.EDU';

$MAXATTRIBUTELENGTH=17;

#
# foreach (keys %OBJATSQ) {
#   print "\"", $_, "\"","\, ", "\"",$OBJATSQ{$_},"\"",",\n";
# }

%OBJATSQ=(
"cm", "cm de au tc ac rm ny mb ch so",
"ro", "ro ad ph fx em tb ac tc nh rm rl ny mb ch so",
"mt", "mt de ac tc dt mn at rm ny mb ch so",
"dn", "dn de ac tc zc ns sd di rm ny mb ml ch so",
"as", "as de ms mr rm tc ac ny mb ch so",
"li", "li de tx ac ah rm ny mb ch so",
"il", "il de ts tk tp tm te ti to rm ny mb ch so",
"rs", "rs de ms mr rm tc ac ny mb ch so",
"rt", "rt de or ho wd mo ia ab ec cl av rm ny mb ch so",
"dc", "dc de ac td rp pl en rm ny mb ch so pr",
"in", "in na de cy ac tc rz st rm ny mb ml ch so",
"ir", "ir az la if pe ac tc rm ny mb ch so",
"is", "is or de lo cy pf ap tl ct rm rl ny mb ch so",
"am", "am de al gd tc ac rm ny mb ch so",
"pn", "pn ad ph fx em nh rm rl ny mb ch so",
"an", "an aa de mo ip ep df av ac tc rm ny mb ch so",
"i6", "i6 na de cy ac tc rz rm ny mb ml ch so"
);

%ATTR=(
       #
       # some non standard Merit stuff ...
       "ne", "ne",
       "np", "np",
       "cp", "cp",
       "ri", "ri",
       "rx", "rx",
       #
       # all other attributes ...
"rp-attribute", "rp",
"mnt-lower", "ml",
"change", "ch",
"ipv6-site", "is",
"local-as", "la",
"prefix", "pf",
"typedef", "td",
"export-comps", "ec",
"descr", "de",
"inet-tunnel", "il",
"author", "ah",
"application", "ap",
"e-mail", "em",
"warning", "uw",
"inet6num", "i6",
"encapsulation", "en",
"location", "lo",
"ri", "ri",
"zc", "zc",
"rl", "rl",
"rm", "rm",
"ro", "ro",
"rp", "rp",
"rs", "rs",
"default", "df",
"rt", "rt",
"ru", "ru",
"origin", "or",
"rx", "rx",
"changed", "ch",
"ch", "ch",
"zone-c", "zc",
"rz", "rz",
"cl", "cl",
"cm", "cm",
"as-macro", "am",
"comm-list", "cl",
"dictionary", "dc",
"sd", "sd",
"ct", "ct",
"tunnel-sink", "tk",
"member-of", "mo",
"cy", "cy",
"localas", "la",
"so", "so",
"st", "st",
"dc", "dc",
"authority", "au",
"de", "de",
"network", "in",
"df", "df",
"la", "la",
"di", "di",
"auth-num", "an",
"dn", "dn",
"mntner", "mt",
"rev-srv", "rz",
"remarks", "rm",
"li", "li",
"tb", "tb",
"tc", "tc",
"td", "td",
"dt", "dt",
"te", "te",
"notify", "ny",
"lo", "lo",
"holes", "ho",
"ti", "ti",
"tk", "tk",
"tl", "tl",
"tm", "tm",
"to", "to",
"tp", "tp",
"community", "cm",
"ts", "ts",
"ec", "ec",
"rs-in", "ri",
"mnt-nfy", "mn",
"tunnel-encap", "te",
"rs-out", "ru",
"alias", "az",
"tx", "tx",
"mb", "mb",
"em", "em",
"en", "en",
"tunnel-protocol", "tp",
"ep", "ex",
"netnum", "in",
"deleted", "ud",
"person", "pn",
"mnt-by", "mb",
"ud", "ud",
"ml", "ml",
"ue", "ue",
"mn", "mn",
"mo", "mo",
"mr", "mr",
"ms", "ms",
"mt", "mt",
"uo", "uo",
"status", "st",
"text", "tx",
"address", "ad",
"aggr-by", "ab",
"fax-no", "fx",
"members", "ms",
"uw", "uw",
"peer", "pe",
"route", "rt",
"na", "na",
"limerick", "li",
"protocol", "pl",
"dom-net", "di",
"inet-rtr", "ir",
"nh", "nh",
"withdrawn", "wd",
"tunnel-in", "ti",
"interas-in", "it",
"phone", "ph",
"trouble", "tb",
"fx", "fx",
"nic-hdl", "nh",
"override", "uo",
"inetnum", "in",
"ns", "ns",
"remark", "rm",
"aut-num", "an",
"ny", "ny",
"netname", "na",
"gd", "ny",
"guardian", "ny",
"contact", "ct",
"as-set", "as",
"source", "so",
"advisory", "av",
"role", "ro",
"delete", "ud",
"country", "cy",
"asname", "aa",
"domain", "dn",
"as-out", "ao",
"upd-to", "dt",
"wd", "wd",
"tunnel-out", "to",
"private", "pr",
"import", "ip",
"interas-out", "io",
"inject-at", "ia",
"i6", "i6",
"or", "or",
"export", "ep",
"nserver", "ns",
"mbrs-by-ref", "mr",
"email", "em",
"route-set", "rs",
"error", "ue",
"auth", "at",
"url", "rl",
"tunnel-source", "ts",
"rev-svr", "rz",
"pe", "pe",
"pf", "pf",
"sub-dom", "sd",
"ho", "ho",
"as-in", "ai",
"ph", "ph",
"admin-c", "ac",
"pl", "pl",
"*error*", "ue",
"pn", "pn",
"fax", "fx",
"pr", "pr",
"aa", "aa",
"as-name", "aa",
"ab", "ab",
"ac", "ac",
"ad", "ad",
"ae", "ae",
"ah", "ah",
"ai", "ai",
"ia", "ia",
"ifaddr", "if",
"as-exclude", "ae",
"al", "al",
"am", "am",
"an", "an",
"if", "if",
"ao", "ao",
"ap", "ap",
"tech-c", "tc",
"as", "as",
"at", "at",
"il", "il",
"tunnel", "tl",
"au", "au",
"av", "av",
"in", "in",
"authorised", "ua",
"tunnel-mcast-tree", "tm",
"io", "io",
"ip", "im",
"az", "az",
"ir", "ir",
"is", "is",
"as-list", "al",
"it", "it"
);

%ATTL=(
"ms", "members",
"mt", "mntner",
"uo", "override",
"uw", "WARNING",
"na", "netname",
"nh", "nic-hdl",
"ri", "rs-in",
"zc", "zone-c",
"rl", "url",
"fx", "fax-no",
"rm", "remarks",
"ro", "role",
"ns", "nserver",
"rp", "rp-attribute",
"rs", "route-set",
"rt", "route",
"ru", "rs-out",
"ny", "notify",
"rx", "rs-out",
"ch", "changed",
"rz", "rev-srv",
"cl", "comm-list",
"cm", "community",
"sd", "sub-dom",
"ct", "contact",
"wd", "withdrawn",
"cy", "country",
"i6", "inet6num",
"or", "origin",
"so", "source",
"st", "status",
"dc", "dictionary",
"de", "descr",
"df", "default",
"di", "dom-net",
"la", "local-as",
"dn", "domain",
"li", "limerick",
"pe", "peer",
"tb", "trouble",
"pf", "prefix",
"tc", "tech-c",
"ho", "holes",
"td", "typedef",
"dt", "upd-to",
"ph", "phone",
"te", "tunnel-encap",
"lo", "location",
"pl", "protocol",
"ti", "tunnel-in",
"pn", "person",
"tk", "tunnel-sink",
"tl", "tunnel",
"tm", "tunnel-mcast-tree",
"aa", "as-name",
"pr", "private",
"to", "tunnel-out",
"ab", "aggr-by",
"tp", "tunnel-protocol",
"ac", "admin-c",
"ad", "address",
"ae", "as-exclude",
"ts", "tunnel-source",
"ec", "export-comps",
"ah", "author",
"ai", "as-in",
"ia", "inject-at",
"tx", "text",
"al", "as-list",
"am", "as-macro",
"an", "aut-num",
"if", "ifaddr",
"mb", "mnt-by",
"ao", "as-out",
"ap", "application",
"em", "e-mail",
"en", "encapsulation",
"as", "as-set",
"at", "auth",
"ep", "export",
"il", "inet-tunnel",
"au", "authority",
"av", "advisory",
"in", "inetnum",
"io", "interas-out",
"ud", "delete",
"ip", "import",
"ml", "mnt-lower",
"ue", "*ERROR*",
"az", "alias",
"ir", "inet-rtr",
"mn", "mnt-nfy",
"is", "ipv6-site",
"mo", "member-of",
"it", "interas-in",
"mr", "mbrs-by-ref"
);

#
#	The file '/home/davidk/db/src/src/defines.pl' is included here
#


#	$RCSfile: defines.pl,v $
#	$Revision: 1.4 $
#	$Author: wlee $
#	$Date: Thu, 23 Apr 1998 19:52:07 -0700 $

#$DEBUG=1;
$DEBUG=0;

$HELPREQUESTED=0;
$STOPUPDATING=0;
%RPSLCONVERSIONSOURCES=();

$OK		=	1;
$NOK		=	0;
$EOF		=	99;

$LOCK_SH = 1;
$LOCK_EX = 2;
$LOCK_NB = 4;
$LOCK_UN = 8;

# Return codes for when trying to modify the database
# with explanatory messages. These are used deep down in the code
# just before or during updates, like dbadd.pl and updatecheck.pl.

$E_EXIST	 =	2;
$E_NOT_FOUND	 =	3;
$E_MULT_MATCH	 =	4;
$E_MISMATCH	 =	5;
$E_NOOP		 =	6;
$E_OLDER	 =	7;
$E_GUARDED	 =	8;
$E_AUTHFAIL      =      9;
$E_HIER_AUTHFAIL =     10;
$E_GENERAL       =     11;
$E_NOAUTOUPDATE  =     12;
$E_NOTNEW        =     13;
$E_STILLREFERENCED =   14;
$E_NOT_ORIGINAL  =     15;
$E_NO_MNTNERS_FOUND =  16;
$E_NO_TL_FOUND   =     17;
$E_NO_TL_CREATION =    18;
$E_HIER_NO_MNTNERS_FOUND = 19;

$MESSAGE[$E_EXIST]	           = "entry already exists";
$MESSAGE[$E_NOT_FOUND]	           = "entry not found";
$MESSAGE[$E_MULT_MATCH]	           = "don\'t know which object to update,\nmore matches found in the database";
$MESSAGE[$E_MISMATCH]	           = "mismatch between update and original";
$MESSAGE[$E_NOOP]	           = "update results in NOOP";
$MESSAGE[$E_OLDER]	           = "update is older than original";
$MESSAGE[$E_AUTHFAIL]              = "authorisation failed, request forwarded to maintainer";
$MESSAGE[$E_HIER_AUTHFAIL]         = "hierarchical authorisation failed, request forwarded to maintainer\nof object direct above the to be updated object in the hierarchy";
$MESSAGE[$E_GENERAL]               = "";
$MESSAGE[$E_NOTNEW]                = "object already exists";
$MESSAGE[$E_STILLREFERENCED]       = "cannot delete object that is still referenced\nby other objects in one of the databases";
$MESSAGE[$E_NOT_ORIGINAL]          = "cannot delete original RIPE181 object through special RPSL update path";
$MESSAGE[$E_NO_MNTNERS_FOUND]      = "no maintainers found for to be updated object";
$MESSAGE[$E_NO_TL_FOUND]           = "hierarchical authorisation failed,\nno object higher in hierarchy found";
$MESSAGE[$E_NO_TL_CREATION]        = "hierarchical authorisation failed,\ncannot create automatically top level objects\nplease contact <\$HUMAILBOX>";
$MESSAGE[$E_HIER_NO_MNTNERS_FOUND] = "hierarchical authorisation failed,\ncould not find a maintainer for higher level object";

#
# Return codes for syntax checking the objects
#
# we could better have used one unified model for return codes
# but for the mean time we at least keep some aliases to
# avoid even more trouble

$O_OK		=	$OK;
$O_ERROR	=	$NOK;
$O_WARNING	=	22;

$O_INVALIDIP     =24;
$O_INVALIDPREFIX =25;
$O_INVALIDRANGE  =26;
$O_SYNTAXERROR   =27;

$O_NOTFOUND=28;
$O_COULDNOTOPEN=29; 


$MESSAGE[$O_OK]		=	"object OK";
$MESSAGE[$O_ERROR]	=	"object has errors";
$MESSAGE[$O_WARNING]	=	"object has warnings";

# Return codes for authorisation

$A_OK		=	1;	# Authorisation worked
$A_BAD		= 	0;      # Authorisation failed
$A_ERR  	=      -1;      # Authorisation Error condition

# protocol codes - not implemented
#
# $_AU_OK	= 100;		# Authorization OK
# $_AU_BAD	= 110;		# Authorization BAD
# $_AU_ERR	= 120;		# Authoization ERROR (cannot open file etc)
#
# $_I_GENERAL	= 200;		# General information
# $_I_DUNNO	= 210;		# "I don't know what you mean" message
# $_I_WAIT	= 220;		# Waiting for input ...
# $_I_RECVD	= 230;		# Have received something, will start
#				# processing now
#
# $_A_OK	= 300;		# Addition OK
# $_A_UNKNOWN	= 310;		# Addition general failures
# $_A_PERM	= 320;		# Addition permission denied
#
# $_D_OK	= 400;		# Deletion OK
# $_D_UNKNOWN	= 410;		# Deletion general failures
# $_D_PERM	= 420;		# Deletion permission denied
# $_D_NFOUND	= 430;		# Object not found for deletion
#
# $_M_OK	= 500;		# Modify OK
# $_M_UNKNNOWN	= 510;		# Modify general failures
# $_M_PERM	= 520;		# Modify permission denied
# $_M_NFOUND	= 530;		# Object not found for modification
#
# $_AM_OK	= 600;		# Add_or_modify OK
# $_AM_UNKNOWN	= 610;		# Add_or_modify general failures
# $_AM_PERM	= 620;		# Add_or_modify permission denied

#
# possible actions for an entry

$ADDACTION="ADD";
$DELETEACTION="DEL";
$CHANGEACTION="CHANGE";

#
# updatecheck, printstat, maintainer, dbadd & dbdel binary options

$NEWOPTION=1;
$DELETEOPTION=2;
$MODIFYOPTION=4;
$OVERRIDEOPTION=8;
$NOCHECKSOPTION=16;
$OKOPTION=32;
$NOOPOPTION=64;
$FAILEDOPTION=128;
$BACKWARDCOMPATIBILITYOPTION=256;
$ASSIGNEDNICOPTION=512;
$USENORMALMAINTAINERATTR=1024;
$RPSLCONVERSIONOPTION=2048;

#
# donetdbm (binary) options

$CLASSLESSOPTION=1;
$CLEANOPTION=2;
$CONVERT2RPSLOPTION=4;
$KEEPRPSLOPTION=8;

#
# db(cl)open options

$DBOPENWRITEOPTION=1;
$DBOPENCLASSLESSONLYOPTION=2;

#
# dbmatch & lookupandprint (binary) options

$INTERSECTIONOPTION=1;
$ALLLESSSPECIFICOPTION=2;
$MORESPECIFICOPTION=4;
$ALLMORESPECIFICOPTION=8;
$NONRECURSIVEOPTION=16;
$FASTOPTION=32;
$NOSYNTACTICSUGAR=64;
$EXACTMATCHOPTION=128;
$EXACTMATCHIPOPTION=256;
$NONEXTERNALRECURSIVEOPTION=512;
$UNIQUEKEYSEARCHOPTION=1024;
$EXPANDOPTION=2048;
$SINGLEOPTION=4096;

#
# The version of the inputformat we default to

$UPDATEVERSION=1;

#
# Supported update versions

@UPDATEVERSIONS=($UPDATEVERSION);

#
# The file extension for the current serial number files 

$CURRENTEXTENSION=".CURRENTSERIAL";

#
# The file extension for the oldest available serial number files 

$OLDESTEXTENSION=".OLDESTSERIAL";

#
# used for fast computations in range2prefix

$ONEDIVLOG2=1/log(2);

#
# very tiny value for rounding of real values in range2prefix

$TINYLOGVALUE=(32-(log(2**32-1)*$ONEDIVLOG2))/100;

#
# constant used for syntactic sugar matching

$ENCMP_MATCH='\S+\s+\S+\s+\S+';

#
# some options as defined in the config file and that
# are used inside the code itself

$REALTIMEMIRRORAUTHORIZATION="REALTIMEMIRRORAUTHORIZATION";
$NETWORKUPDATEAUTHORIZATION="NETWORKUPDATEAUTHORIZATION";

#
# the maximal number of country attributes on a line

$MAXCOUNTRIES=7;

#
# The maximal length of a key measured in characters that is *not* indexed

$SMALLESTKEY=1;

#
# maximal number of initials for NIC handles

$MAXLENGTHINITIALS=4;

#
# which characters are valid for an attribute 
# Note: the * is for the error attribute!

$VALIDATTRCHAR='\w\-\*';

#
# valid domain name regular expression

$DOMAINNAME='[a-zA-Z\d]+([\.\-][a-zA-Z\d]+)*'; 

#
# valid source attribute regular expression

$SOURCENAME='([A-Z\d]+[A-Z\d\-]*[A-Z][A-Z\d\-]*[A-Z\d]|[A-Z]{2,2})';

#
# the prefix that is used for auto nichandle assignments

$AUTONICPREFIX="AUTO-";
$AUTONICPREFIXREGULAR='AUTO\-';

#
# some common titles - only use lower case

$TITLES='(m[rs]s?|drs?|ir|ing|sign|herr|hr|frau|prof\S*)\.? +';

#
# regular expression for splitting up file names in path & name component

$SPLITFILENAME='^\s*(\S+\/)?([^\/\s]+)\s*$';

#
# ip regular expressions

#
# generic

$VALIDPREFIX='[\d\:a-f]+\/\d+';

$VALIDPREFIXKEY=$VALIDPREFIX;

#
# this one has interesting (but no fatal) problems with perl5 & grep, see whoisd

$VALIDIP4='0*([12][0-4]\d|25[0-5]|1?[1-9]?\d)(\.0*[12][0-4]\d|\.0*25[0-5]|\.0*1?[1-9]?\d){0,3}';

$VALIDFULLIP4='0*([12][0-4]\d|25[0-5]|1?[1-9]?\d)(\.0*[12][0-4]\d|\.0*25[0-5]|\.0*1?[1-9]?\d){3,3}';

$VALIDIP4PREFIXLENGTH='0*([12]?[\d]|3[012])';

$VALIDIP4PREFIX=$VALIDIP4.'\/'.$VALIDIP4PREFIXLENGTH;

$VALIDFULLIP4PREFIX=$VALIDFULLIP4.'\/'.$VALIDIP4PREFIXLENGTH;

$VALIDIP4PREFIXKEY='\d+\/\d+';

#
# for ipv6

$VALIDIP6='[\da-f]{1,4}(\:[\da-f]{1,4}){7}';

$VALIDIP6PREFIX='[\d\:a-f]+\:[\d\:a-f]+\/\d+';

$VALIDIP6PREFIXKEY=$VALIDIP6.'\/\d+';


#
# the attribute value to be used for deleted objects

$DELETEDOBJECT="XX";

#
# what is the extension for classless databases ?

$CLASSLESSEXT=".cl";


#
# what is the extension for the overflow files ?

$OVERFLOWEXTENSION=".overflow.";

#
# what is the key for finding a new overflow number

$OVERFLOWKEY="\t";

#
# what is the prefix before the offset when we find an overflow instead
# of offset values

$OVERFLOWPREFIX="\t";
$OVERFLOWPREFIXREGULAR='\t';

#
# NOTEXISTINGPREFIXESKEY 
#
# key to find the list of existing prefixes

$NOTEXISTINGPREFIXESKEY=$OVERFLOWKEY.$OVERFLOWKEY;

#
# which string do we use as 'binding' for uniquekeys

$UNIQUEKEYBINDING="\t";

#
# maximal number of entries/objects that we read & process at a time
#
# entries/objects are stored in a list of this length

$MAXLISTLENGTH=2500;

#
# which dbm packages can be used

%VALIDDBMPACKAGES=(
                   "", "",
                   "DEFAULT", "",
                   "DB", "DB_File",
                   "GDBM", "GDBM_File",
                  );

#
# this value determines the maximal length of a string 
# during processing
#
# usually we are talking about prefix keys:
#
# example: 536870912/8
#
# that is components are about 10 bytes long
# and the maximal string length is thus 10*$MAXSTRINGCOMPONENTS
#
# the more components we allow, the longer in memory copies take
# the less components we allow, the more disk accesses we need

$MAXSTRINGCOMPONENTS=300;

#
# line continuation length suffix

$CONTINUATIONSUFFIX=" connectlength";

#
# binding value for offset and size of object
#
# This one should ***always*** be equal to '.'
#
# This allows us to do (easy & fast) sorting of offsets although
# the size of the object is connected as a suffix !!!!
#
# Example: 3.100 (object at offset 3 & size is 100)

$SIZESUFFIXBINDING=".";
$SIZESUFFIXBINDINGREGULAR='\.';                 

#
# allowed routing protocols plus aliases for IPv6

%IPV6PROTOCOLS=(
"idrpv6", "IDRPv6", 
"bgp4+", "BGP4+", 
"ripv6", "RIPng", 
"ripng", "RIPng",
"static", "STATIC"
);

#
# Masks for IP addresses

@masks = (0x0,
          0x80000000, 0xc0000000, 0xe0000000, 0xf0000000,
	  0xf8000000, 0xfc000000, 0xfe000000, 0xff000000,
	  0xff800000, 0xffc00000, 0xffe00000, 0xfff00000,
	  0xfff80000, 0xfffc0000, 0xfffe0000, 0xffff0000,
	  0xffff8000, 0xffffc000, 0xffffe000, 0xfffff000,
	  0xfffff800, 0xfffffc00, 0xfffffe00, 0xffffff00,
	  0xffffff80, 0xffffffc0, 0xffffffe0, 0xfffffff0,
	  0xfffffff8, 0xfffffffc, 0xfffffffe, 0xffffffff );

%ipv6zeroes= ( "0", 4, 
               "1", 0,
               "2", 1,
               "3", 0,
               "4", 2,
               "5", 0,
               "6", 1,
               "7", 0,
               "8", 3,
               "9", 0,
               "a", 1,
               "b", 0,
               "c", 2,
               "d", 0,
               "e", 1,
               "f", 0
              );
             
#
# three arrays contain: 
#
# hexadecimal masks with ^0x1
# hexadecimal masks with ^0x3
# hexadecimal masks with ^0x7             
              
%ipv6masks1= ("0", "0",
              "1", "0",
              "2", "2",
              "3", "2",
              "4", "4",
              "5", "4",
              "6", "6",
              "7", "6",
              "8", "8",
              "9", "9",
              "a", "a",
              "b", "a",
              "c", "c",
              "d", "c",
              "e", "e",
              "f", "e");

%ipv6masks2= ("0", "0",
              "1", "0",
              "2", "0",
              "3", "0",
              "4", "4",
              "5", "4",
              "6", "4",
              "7", "4",
              "8", "8",
              "9", "8",
              "a", "8",
              "b", "8",
              "c", "c",
              "d", "c",
              "e", "c",
              "f", "c");

%ipv6masks3= ("0", "0",
              "1", "0",
              "2", "0",
              "3", "0",
              "4", "0",
              "5", "0",
              "6", "0",
              "7", "0",
              "8", "8",
              "9", "8",
              "a", "8",
              "b", "8",
              "c", "8",
              "d", "8",
              "e", "8",
              "f", "8");

%SERVICES= ("ping", 2,
            "tcpmux", 1,
            "compressnet", 1,
            "rje", 1,
            "echo", 1,
            "discard", 1,
            "systat", 1,
            "daytime", 1,
            "qotd", 1,
            "msp", 1,
            "chargen", 1,
            "ftp-data", 1,
            "ftp", 1,
            "ssh", 1,
            "telnet", 1,
            "smtp", 1,
            "nsw-fe", 1,
            "msg-icp", 1,
            "msg-auth", 1,
            "dsp", 1,
            "time", 1,
            "rap", 1,
            "rlp", 1,
            "graphics", 1,
            "name", 1,
            "nameserver", 1,
            "nicname", 1,
            "mpm-flags", 1,
            "mpm", 1,
            "mpm-snd", 1,
            "ni-ftp", 1,
            "auditd", 1,
            "tacacs", 1,
            "re-mail-ck", 1,
            "la-maint", 1,
            "xns-time", 1,
            "domain", 1,
            "xns-ch", 1,
            "isi-gl", 1,
            "xns-auth", 1,
            "xns-mail", 1,
            "ni-mail", 1,
            "acas", 1,
            "whois", 1,
            "covia", 1,
            "tacacs-ds", 1,
            "sql", 1,
            "bootps", 1,
            "bootpc", 1,
            "tftp", 1,
            "gopher", 1,
            "netrjs-1", 1,
            "netrjs-2", 1,
            "netrjs-3", 1,
            "netrjs-4", 1,
            "deos", 1,
            "vettcp", 1,
            "finger", 1,
            "http", 1,
            "www", 1,
            "www-http", 1,
            "hosts2-ns", 1,
            "xfer", 1,
            "mit-ml-dev", 1,
            "ctf", 1,
            "mfcobol", 1,
            "kerberos", 1,
            "su-mit-tg", 1,
            "dnsix", 1,
            "mit-dov", 1,
            "npp", 1,
            "dcp", 1,
            "objcall", 1,
            "supdup", 1,
            "dixie", 1,
            "swift-rvf", 1,
            "tacnews", 1,
            "metagram", 1,
            "newacct", 1,
            "hostname", 1,
            "iso-tsap", 1,
            "gppitnp", 1,
            "acr-nema", 1,
            "cso", 1,
            "csnet-ns", 1,
            "3com-tsmux", 1,
            "rtelnet", 1,
            "snagas", 1,
            "pop2", 1,
            "pop3", 1,
            "sunrpc", 1,
            "mcidas", 1,
            "ident", 1,
            "auth", 1,
            "audionews", 1,
            "sftp", 1,
            "ansanotify", 1,
            "uucp-path", 1,
            "sqlserv", 1,
            "nntp", 1,
            "cfdptkt", 1,
            "erpc", 1,
            "smakynet", 1,
            "ntp", 1,
            "ansatrader", 1,
            "locus-map", 1,
            "unitary", 1,
            "locus-con", 1,
            "gss-xlicen", 1,
            "pwdgen", 1,
            "cisco-fna", 1,
            "cisco-tna", 1,
            "cisco-sys", 1,
            "statsrv", 1,
            "ingres-net", 1,
            "epmap", 1,
            "profile", 1,
            "netbios-ns", 1,
            "netbios-dgm", 1,
            "netbios-ssn", 1,
            "emfis-data", 1,
            "emfis-cntl", 1,
            "bl-idm", 1,
            "imap", 1,
            "news", 1,
            "uaac", 1,
            "iso-tp0", 1,
            "iso-ip", 1,
            "jargon", 1,
            "aed-512", 1,
            "sql-net", 1,
            "hems", 1,
            "bftp", 1,
            "sgmp", 1,
            "netsc-prod", 1,
            "netsc-dev", 1,
            "sqlsrv", 1,
            "knet-cmp", 1,
            "pcmail-srv", 1,
            "nss-routing", 1,
            "sgmp-traps", 1,
            "snmp", 1,
            "snmptrap", 1,
            "cmip-man", 1,
            "cmip-agent", 1,
            "smip-agent", 1,
            "xns-courier", 1,
            "s-net", 1,
            "namp", 1,
            "rsvd", 1,
            "send", 1,
            "print-srv", 1,
            "multiplex", 1,
            "cl", 1,
            "xyplex-mux", 1,
            "mailq", 1,
            "vmnet", 1,
            "genrad-mux", 1,
            "xdmcp", 1,
            "nextstep", 1,
            "bgp", 1,
            "ris", 1,
            "unify", 1,
            "audit", 1,
            "ocbinder", 1,
            "ocserver", 1,
            "remote-kis", 1,
            "kis", 1,
            "aci", 1,
            "mumps", 1,
            "qft", 1,
            "gacp", 1,
            "cacp", 1,
            "prospero", 1,
            "osu-nms", 1,
            "srmp", 1,
            "irc", 1,
            "dn6-nlm-aud", 1,
            "dn6-smm-red", 1,
            "dls", 1,
            "dls-mon", 1,
            "smux", 1,
            "src", 1,
            "at-rtmp", 1,
            "at-nbp", 1,
            "at-3", 1,
            "at-echo", 1,
            "at-5", 1,
            "at-zis", 1,
            "at-7", 1,
            "at-8", 1,
            "qmtp", 1,
            "z39", 1,
            "914c", 1,
            "anet", 1,
            "ipx", 1,
            "vmpwscs", 1,
            "softpc", 1,
            "cailic", 1,
            "dbase", 1,
            "mpp", 1,
            "uarps", 1,
            "imap3", 1,
            "fln-spx", 1,
            "rsh-spx", 1,
            "cdc", 1,
            "direct", 1,
            "sur-meas", 1,
            "dayna", 1,
            "link", 1,
            "dsp3270", 1,
            "subntbcst_tftp", 1,
            "bhfhs", 1,
            "set", 1,
            "yak-chat", 1,
            "esro-gen", 1,
            "openport", 1,
            "nsiiops", 1,
            "arcisdms", 1,
            "hdap", 1,
            "http-mgmt", 1,
            "personal-link", 1,
            "cableport-ax", 1,
            "entrusttime", 1,
            "bhmds", 1,
            "pdap", 1,
            "pawserv", 1,
            "zserv", 1,
            "fatserv", 1,
            "csi-sgwp", 1,
            "mftp", 1,
            "matip-type-a", 1,
            "matip-type-b", 1,
            "bhoetty", 1,
            "dtag-ste-sb", 1,
            "bhoedap4", 1,
            "bh611", 1,
            "bhevent", 1,
            "clearcase", 1,
            "ulistproc", 1,
            "legent-1", 1,
            "legent-2", 1,
            "hassle", 1,
            "nip", 1,
            "tnetos", 1,
            "dsetos", 1,
            "is99c", 1,
            "is99s", 1,
            "hp-collector", 1,
            "hp-managed-node", 1,
            "hp-alarm-mgr", 1,
            "arns", 1,
            "ibm-app", 1,
            "asa", 1,
            "aurp", 1,
            "unidata-ldm", 1,
            "ldap", 1,
            "uis", 1,
            "synotics-relay", 1,
            "synotics-broker", 1,
            "dis", 1,
            "embl-ndt", 1,
            "netcp", 1,
            "netware-ip", 1,
            "mptn", 1,
            "kryptolan", 1,
            "iso-tsap-c2", 1,
            "work-sol", 1,
            "ups", 1,
            "genie", 1,
            "decap", 1,
            "nced", 1,
            "ncld", 1,
            "imsp", 1,
            "timbuktu", 1,
            "prm-sm", 1,
            "prm-nm", 1,
            "decladebug", 1,
            "rmt", 1,
            "synoptics-trap", 1,
            "smsp", 1,
            "infoseek", 1,
            "bnet", 1,
            "silverplatter", 1,
            "onmux", 1,
            "hyper-g", 1,
            "ariel1", 1,
            "smpte", 1,
            "ariel2", 1,
            "ariel3", 1,
            "opc-job-start", 1,
            "opc-job-track", 1,
            "icad-el", 1,
            "smartsdp", 1,
            "svrloc", 1,
            "ocs_cmu", 1,
            "ocs_amu", 1,
            "utmpsd", 1,
            "utmpcd", 1,
            "iasd", 1,
            "nnsp", 1,
            "mobileip-agent", 1,
            "mobilip-mn", 1,
            "dna-cml", 1,
            "comscm", 1,
            "dsfgw", 1,
            "dasp", 1,
            "sgcp", 1,
            "decvms-sysmgt", 1,
            "cvc_hostd", 1,
            "https", 1,
            "snpp", 1,
            "microsoft-ds", 1,
            "ddm-rdb", 1,
            "ddm-dfm", 1,
            "ddm-byte", 1,
            "as-servermap", 1,
            "tserver", 1,
            "sfs-smp-net", 1,
            "sfs-config", 1,
            "creativeserver", 1,
            "contentserver", 1,
            "creativepartnr", 1,
            "macon-tcp", 1,
            "macon-udp", 1,
            "scohelp", 1,
            "appleqtc", 1,
            "ampr-rcmd", 1,
            "skronk", 1,
            "datasurfsrv", 1,
            "datasurfsrvsec", 1,
            "alpes", 1,
            "kpasswd", 1,
            "smtps", 1,
            "digital-vrc", 1,
            "mylex-mapd", 1,
            "photuris", 1,
            "rcp", 1,
            "scx-proxy", 1,
            "mondex", 1,
            "ljk-login", 1,
            "hybrid-pop", 1,
            "tn-tl-w1", 1,
            "tn-tl-w2", 1,
            "tcpnethaspsrv", 1,
            "tn-tl-fd1", 1,
            "ss7ns", 1,
            "spsc", 1,
            "iafserver", 1,
            "iafdbase", 1,
            "ph", 1,
            "bgs-nsi", 1,
            "ulpnet", 1,
            "integra-sme", 1,
            "powerburst", 1,
            "avian", 1,
            "saft", 1,
            "gss-http", 1,
            "nest-protocol", 1,
            "micom-pfs", 1,
            "go-login", 1,
            "ticf-1", 1,
            "ticf-2", 1,
            "pov-ray", 1,
            "intecourier", 1,
            "pim-rp-disc", 1,
            "dantz", 1,
            "siam", 1,
            "iso-ill", 1,
            "isakmp", 1,
            "stmf", 1,
            "asa-appl-proto", 1,
            "intrinsa", 1,
            "citadel", 1,
            "mailbox-lm", 1,
            "beverly", 1,
            "ohimsrv", 1,
            "crs", 1,
            "xvttp", 1,
            "snare", 1,
            "fcp", 1,
            "mynet", 1,
            "exec", 1,
            "comsat", 1,
            "biff", 1,
            "login", 1,
            "who", 1,
            "shell", 1,
            "syslog", 1,
            "printer", 1,
            "videotex", 1,
            "talk", 1,
            "ntalk", 1,
            "utime", 1,
            "efs", 1,
            "router", 1,
            "ripng", 1,
            "ulp", 1,
            "ibm-db2", 1,
            "ncp", 1,
            "timed", 1,
            "tempo", 1,
            "stx", 1,
            "custix", 1,
            "irc-serv", 1,
            "courier", 1,
            "conference", 1,
            "netnews", 1,
            "netwall", 1,
            "mm-admin", 1,
            "iiop", 1,
            "opalis-rdv", 1,
            "nmsp", 1,
            "gdomap", 1,
            "apertus-ldp", 1,
            "uucp", 1,
            "uucp-rlogin", 1,
            "commerce", 1,
            "klogin", 1,
            "kshell", 1,
            "appleqtcsrvr", 1,
            "dhcpv6-client", 1,
            "dhcpv6-server", 1,
            "afpovertcp", 1,
            "idfp", 1,
            "new-rwho", 1,
            "cybercash", 1,
            "deviceshare", 1,
            "pirp", 1,
            "rtsp", 1,
            "dsf", 1,
            "remotefs", 1,
            "openvms-sysipc", 1,
            "sdnskmp", 1,
            "teedtap", 1,
            "rmonitor", 1,
            "monitor", 1,
            "chshell", 1,
            "nntps", 1,
            "9pfs", 1,
            "whoami", 1,
            "streettalk", 1,
            "banyan-rpc", 1,
            "ms-shuttle", 1,
            "ms-rome", 1,
            "meter", 1,
            "sonar", 1,
            "banyan-vip", 1,
            "ftp-agent", 1,
            "vemmi", 1,
            "ipcd", 1,
            "vnas", 1,
            "ipdd", 1,
            "decbsrv", 1,
            "sntp-heartbeat", 1,
            "bdp", 1,
            "scc-security", 1,
            "philips-vc", 1,
            "keyserver", 1,
            "imap4-ssl", 1,
            "password-chg", 1,
            "submission", 1,
            "cal", 1,
            "eyelink", 1,
            "ipcserver", 1,
            "urm", 1,
            "nqs", 1,
            "n", 1,
            "sift-uft", 1,
            "npmp-trap", 1,
            "npmp-local", 1,
            "npmp-gui", 1,
            "hmmp-ind", 1,
            "hmmp-op", 1,
            "sshell", 1,
            "sco-inetmgr", 1,
            "sco-sysmgr", 1,
            "sco-dtmgr", 1,
            "dei-icda", 1,
            "digital-evm", 1,
            "sco-websrvrmgr", 1,
            "escp-ip", 1,
            "servstat", 1,
            "ginad", 1,
            "rlzdbase", 1,
            "ldaps", 1,
            "lanserver", 1,
            "mdqs", 1,
            "doom", 1,
            "disclose", 1,
            "sdr", 1,
            "mecomm", 1,
            "meregister", 1,
            "vacdsm-sws", 1,
            "vacdsm-app", 1,
            "vpps-qua", 1,
            "cimplex", 1,
            "acap", 1,
            "dctp", 1,
            "elcsd", 1,
            "agentx", 1,
            "entrust-kmsh", 1,
            "entrust-ash", 1,
            "netviewdm1", 1,
            "netviewdm2", 1,
            "netviewdm3", 1,
            "netgw", 1,
            "netrcs", 1,
            "flexlm", 1,
            "fujitsu-dev", 1,
            "ris-cm", 1,
            "kerberos-adm", 1,
            "rfile", 1,
            "loadav", 1,
            "kerberos-iv", 1,
            "pump", 1,
            "qrh", 1,
            "rrh", 1,
            "tell", 1,
            "nlogin", 1,
            "con", 1,
            "ns", 1,
            "rxe", 1,
            "quotad", 1,
            "cycleserv", 1,
            "omserv", 1,
            "webster", 1,
            "phonebook", 1,
            "vid", 1,
            "cadlock", 1,
            "rtip", 1,
            "cycleserv2", 1,
            "submit", 1,
            "notify", 1,
            "rpasswd", 1,
            "acmaint_dbd", 1,
            "entomb", 1,
            "acmaint_transd", 1,
            "wpages", 1,
            "wpgs", 1,
            "concert", 1,
            "mdbs_daemon", 1,
            "device", 1,
            "iclcnet-locate", 1,
            "iclcnet_svinfo", 1,
            "accessbuilder", 1,
            "omginitialrefs", 1,
            "xact-backup", 1,
            "ftps-data", 1,
            "ftps", 1,
            "nas", 1,
            "telnets", 1,
            "imaps", 1,
            "ircs", 1,
            "pop3s", 1,
            "vsinet", 1,
            "maitrd", 1,
            "busboy", 1,
            "puparp", 1,
            "garcon", 1,
            "applix", 1,
            "puprouter", 1,
            "ock", 1,
            "registered", 1,
            "the", 1,
            "used", 1,
            "users", 1,
            "ports", 1,
            "connections", 1,
            "providing", 1,
            "defined", 1,
            "its", 1,
            "community", 1,
            "to", 1,
            "udp", 1,
            "port", 1,
            "keyword", 1,
            "blackjack", 1,
            "iad1", 1,
            "iad2", 1,
            "iad3", 1,
            "neod1", 1,
            "neod2", 1,
            "nim", 1,
            "nimreg", 1,
            "instl_boots", 1,
            "instl_bootc", 1,
            "socks", 1,
            "ansoft-lm-1", 1,
            "ansoft-lm-2", 1,
            "nfsd-status", 1,
            "nfsd-keepalive", 1,
            "lmsocialserver", 1,
            "murray", 1,
            "nfa", 1,
            "mc-client", 1,
            "lupa", 1,
            "nerv", 1,
            "hermes", 1,
            "h323hostcallsc", 1,
            "bmc_patroldb", 1,
            "bmc-patroldb", 1,
            "pdps", 1,
            "vpjp", 1,
            "alta-ana-lm", 1,
            "bbn-mmc", 1,
            "bbn-mmx", 1,
            "sbook", 1,
            "editbench", 1,
            "equationbuilder", 1,
            "lotusnote", 1,
            "relief", 1,
            "rightbrain", 1,
            "intuitive", 1,
            "cuillamartin", 1,
            "pegboard", 1,
            "connlcli", 1,
            "ftsrv", 1,
            "mimer", 1,
            "linx", 1,
            "timeflies", 1,
            "ndm-requester", 1,
            "ndm-server", 1,
            "adapt-sna", 1,
            "netware-csp", 1,
            "dcs", 1,
            "screencast", 1,
            "gv-us", 1,
            "us-gv", 1,
            "fc-cli", 1,
            "fc-ser", 1,
            "chromagrafx", 1,
            "molly", 1,
            "bytex", 1,
            "ibm-pps", 1,
            "cichlid", 1,
            "elan", 1,
            "dbreporter", 1,
            "telesis-licman", 1,
            "apple-licman", 1,
            "udt_os", 1,
            "gwha", 1,
            "os-licman", 1,
            "atex_elmd", 1,
            "checksum", 1,
            "cadsi-lm", 1,
            "objective-dbc", 1,
            "iclpv-dm", 1,
            "iclpv-sc", 1,
            "iclpv-sas", 1,
            "iclpv-pm", 1,
            "iclpv-nls", 1,
            "iclpv-nlc", 1,
            "iclpv-wsm", 1,
            "dvl-activemail", 1,
            "audio-activmail", 1,
            "video-activmail", 1,
            "cadkey-licman", 1,
            "cadkey-tablet", 1,
            "goldleaf-licman", 1,
            "prm-sm-np", 1,
            "prm-nm-np", 1,
            "igi-lm", 1,
            "ibm-res", 1,
            "netlabs-lm", 1,
            "dbsa-lm", 1,
            "sophia-lm", 1,
            "here-lm", 1,
            "hiq", 1,
            "af", 1,
            "innosys", 1,
            "innosys-acl", 1,
            "ibm-mqseries", 1,
            "dbstar", 1,
            "novell-lu6", 1,
            "timbuktu-srv1", 1,
            "timbuktu-srv2", 1,
            "timbuktu-srv3", 1,
            "timbuktu-srv4", 1,
            "gandalf-lm", 1,
            "autodesk-lm", 1,
            "essbase", 1,
            "hybrid", 1,
            "zion-lm", 1,
            "sais", 1,
            "mloadd", 1,
            "informatik-lm", 1,
            "nms", 1,
            "tpdu", 1,
            "rgtp", 1,
            "blueberry-lm", 1,
            "ms-sql-s", 1,
            "ms-sql-m", 1,
            "ibm-cics", 1,
            "saism", 1,
            "tabula", 1,
            "eicon-server", 1,
            "eicon-x25", 1,
            "eicon-slp", 1,
            "cadis-1", 1,
            "cadis-2", 1,
            "ies-lm", 1,
            "marcam-lm", 1,
            "proxima-lm", 1,
            "ora-lm", 1,
            "apri-lm", 1,
            "oc-lm", 1,
            "peport", 1,
            "dwf", 1,
            "infoman", 1,
            "gtegsc-lm", 1,
            "genie-lm", 1,
            "interhdl_elmd", 1,
            "esl-lm", 1,
            "dca", 1,
            "valisys-lm", 1,
            "nrcabq-lm", 1,
            "proshare1", 1,
            "proshare2", 1,
            "ibm_wrless_lan", 1,
            "world-lm", 1,
            "nucleus", 1,
            "msl_lmd", 1,
            "pipes", 1,
            "oceansoft-lm", 1,
            "csdmbase", 1,
            "csdm", 1,
            "aal-lm", 1,
            "uaiact", 1,
            "openmath", 1,
            "telefinder", 1,
            "taligent-lm", 1,
            "clvm-cfg", 1,
            "ms-sna-server", 1,
            "ms-sna-base", 1,
            "dberegister", 1,
            "pacerforum", 1,
            "airs", 1,
            "miteksys-lm", 1,
            "afs", 1,
            "confluent", 1,
            "lansource", 1,
            "nms_topo_serv", 1,
            "localinfosrvr", 1,
            "docstor", 1,
            "dmdocbroker", 1,
            "insitu-conf", 1,
            "anynetgateway", 1,
            "stone-design-1", 1,
            "netmap_lm", 1,
            "ica", 1,
            "cvc", 1,
            "liberty-lm", 1,
            "rfx-lm", 1,
            "watcom-sql", 1,
            "fhc", 1,
            "vlsi-lm", 1,
            "saiscm", 1,
            "shivadiscovery", 1,
            "imtc-mcs", 1,
            "evb-elm", 1,
            "funkproxy", 1,
            "utcd", 1,
            "symplex", 1,
            "diagmond", 1,
            "robcad-lm", 1,
            "mvx-lm", 1,
            "3l-l1", 1,
            "wins", 1,
            "fujitsu-dtc", 1,
            "fujitsu-dtcns", 1,
            "ifor-protocol", 1,
            "vpad", 1,
            "vpac", 1,
            "vpvd", 1,
            "vpvc", 1,
            "atm-zip-office", 1,
            "ncube-lm", 1,
            "ricardo-lm", 1,
            "cichild-lm", 1,
            "ingreslock", 1,
            "orasrv", 1,
            "prospero-np", 1,
            "pdap-np", 1,
            "tlisrv", 1,
            "mciautoreg", 1,
            "coauthor", 1,
            "rap-service", 1,
            "rap-listen", 1,
            "miroconnect", 1,
            "virtual-places", 1,
            "micromuse-lm", 1,
            "ampr-info", 1,
            "ampr-inter", 1,
            "sdsc-lm", 1,
            "3ds-lm", 1,
            "intellistor-lm", 1,
            "rds", 1,
            "rds2", 1,
            "gridgen-elmd", 1,
            "simba-cs", 1,
            "aspeclmd", 1,
            "vistium-share", 1,
            "abbaccuray", 1,
            "laplink", 1,
            "axon-lm", 1,
            "shivahose", 1,
            "shivasound", 1,
            "3m-image-lm", 1,
            "hecmtl-db", 1,
            "pciarray", 1,
            "sna-cs", 1,
            "caci-lm", 1,
            "livelan", 1,
            "ashwin", 1,
            "arbortext-lm", 1,
            "xingmpeg", 1,
            "web2host", 1,
            "asci-val", 1,
            "facilityview", 1,
            "pconnectmgr", 1,
            "cadabra-lm", 1,
            "pay-per-view", 1,
            "winddlb", 1,
            "corelvideo", 1,
            "jlicelmd", 1,
            "tsspmap", 1,
            "ets", 1,
            "orbixd", 1,
            "rdb-dbs-disp", 1,
            "chip-lm", 1,
            "itscomm-ns", 1,
            "mvel-lm", 1,
            "oraclenames", 1,
            "moldflow-lm", 1,
            "hypercube-lm", 1,
            "jacobus-lm", 1,
            "ioc-sea-lm", 1,
            "tn-tl-r1", 1,
            "tn-tl-r2", 1,
            "vmf-msg-port", 1,
            "msims", 1,
            "simbaexpress", 1,
            "tn-tl-fd2", 1,
            "intv", 1,
            "ibm-abtact", 1,
            "pra_elmd", 1,
            "triquest-lm", 1,
            "vqp", 1,
            "gemini-lm", 1,
            "ncpm-pm", 1,
            "commonspace", 1,
            "mainsoft-lm", 1,
            "sixtrak", 1,
            "radio", 1,
            "radio-sm", 1,
            "radio-bc", 1,
            "orbplus-iiop", 1,
            "picknfs", 1,
            "simbaservices", 1,
            "issd", 1,
            "aas", 1,
            "inspect", 1,
            "picodbc", 1,
            "icabrowser", 1,
            "slp", 1,
            "slm-api", 1,
            "stt", 1,
            "smart-lm", 1,
            "isysg-lm", 1,
            "taurus-wh", 1,
            "ill", 1,
            "netbill-trans", 1,
            "netbill-keyrep", 1,
            "netbill-cred", 1,
            "netbill-auth", 1,
            "netbill-prod", 1,
            "nimrod-agent", 1,
            "skytelnet", 1,
            "xs-openstorage", 1,
            "faxportwinport", 1,
            "softdataphone", 1,
            "ontime", 1,
            "jaleosnd", 1,
            "udp-sr-port", 1,
            "svs-omagent", 1,
            "cncp", 1,
            "cnap", 1,
            "cnip", 1,
            "cert-initiator", 1,
            "cert-responder", 1,
            "invision", 1,
            "isis-am", 1,
            "isis-ambc", 1,
            "saiseh", 1,
            "datametrics", 1,
            "sa-msg-port", 1,
            "rsap", 1,
            "concurrent-lm", 1,
            "nkd", 1,
            "shiva_confsrvr", 1,
            "xnmp", 1,
            "alphatech-lm", 1,
            "stargatealerts", 1,
            "dec-mbadmin", 1,
            "dec-mbadmin-h", 1,
            "fujitsu-mmpdc", 1,
            "sixnetudr", 1,
            "sg-lm", 1,
            "skip-mc-gikreq", 1,
            "netview-aix-1", 1,
            "netview-aix-2", 1,
            "netview-aix-3", 1,
            "netview-aix-4", 1,
            "netview-aix-5", 1,
            "netview-aix-6", 1,
            "netview-aix-7", 1,
            "netview-aix-8", 1,
            "netview-aix-9", 1,
            "netview-aix-10", 1,
            "netview-aix-11", 1,
            "netview-aix-12", 1,
            "proshare-mc-1", 1,
            "proshare-mc-2", 1,
            "pdp", 1,
            "netcomm1", 1,
            "netcomm2", 1,
            "groupwise", 1,
            "prolink", 1,
            "darcorp-lm", 1,
            "microcom-sbp", 1,
            "sd-elmd", 1,
            "lanyon-lantern", 1,
            "ncpm-hip", 1,
            "snaresecure", 1,
            "n2nremote", 1,
            "cvmon", 1,
            "nsjtp-ctrl", 1,
            "nsjtp-data", 1,
            "firefox", 1,
            "ng-umds", 1,
            "empire-empuma", 1,
            "sstsys-lm", 1,
            "rrirtr", 1,
            "rrimwm", 1,
            "rrilwm", 1,
            "rrifmm", 1,
            "rrisat", 1,
            "rsvp-encap-1", 1,
            "rsvp-encap-2", 1,
            "mps-raft", 1,
            "l2f", 1,
            "deskshare", 1,
            "hb-engine", 1,
            "bcs-broker", 1,
            "slingshot", 1,
            "jetform", 1,
            "vdmplay", 1,
            "gat-lmd", 1,
            "centra", 1,
            "impera", 1,
            "pptconference", 1,
            "registrar", 1,
            "conferencetalk", 1,
            "sesi-lm", 1,
            "houdini-lm", 1,
            "xmsg", 1,
            "fj-hdnet", 1,
            "h323gatedisc", 1,
            "h323gatestat", 1,
            "h323hostcall", 1,
            "caicci", 1,
            "hks-lm", 1,
            "pptp", 1,
            "csbphonemaster", 1,
            "iden-ralp", 1,
            "iberiagames", 1,
            "winddx", 1,
            "telindus", 1,
            "citynl", 1,
            "roketz", 1,
            "msiccp", 1,
            "proxim", 1,
            "sipat", 1,
            "cambertx-lm", 1,
            "privatechat", 1,
            "street-stream", 1,
            "ultimad", 1,
            "gamegen1", 1,
            "webaccess", 1,
            "encore", 1,
            "cisco-net-mgmt", 1,
            "3com-nsd", 1,
            "cinegrfx-lm", 1,
            "ncpm-ft", 1,
            "remote-winsock", 1,
            "ftrapid-1", 1,
            "ftrapid-2", 1,
            "oracle-em1", 1,
            "aspen-services", 1,
            "sslp", 1,
            "swiftnet", 1,
            "lofr-lm", 1,
            "translogic-lm", 1,
            "oracle-em2", 1,
            "ms-streaming", 1,
            "capfast-lmd", 1,
            "cnhrp", 1,
            "tftp-mcast", 1,
            "spss-lm", 1,
            "www-ldap-gw", 1,
            "cft-0", 1,
            "cft-1", 1,
            "cft-2", 1,
            "cft-3", 1,
            "cft-4", 1,
            "cft-5", 1,
            "cft-6", 1,
            "cft-7", 1,
            "bmc-net-adm", 1,
            "bmc-net-svc", 1,
            "vaultbase", 1,
            "essweb-gw", 1,
            "kmscontrol", 1,
            "global-dtserv", 1,
            "199z", 1,
            "femis", 1,
            "powerguardian", 1,
            "prodigy-internet1778", 1,
            "pharmasoft", 1,
            "dpkeyserv", 1,
            "answersoft-lm", 1,
            "hp-hcip", 1,
            "fjris", 1,
            "finle-lm", 1,
            "windlm", 1,
            "funk-logger", 1,
            "funk-license", 1,
            "psmond", 1,
            "hello", 1,
            "ea1", 1,
            "ibm-dt-2", 1,
            "rsc-robot", 1,
            "cera-bcm", 1,
            "dpi-proxy", 1,
            "vocaltec-admin", 1,
            "uma", 1,
            "etp", 1,
            "netrisk", 1,
            "ansys-lm", 1,
            "msmq", 1,
            "concomp1", 1,
            "hp-hcip-gwy", 1,
            "enl", 1,
            "enl-name", 1,
            "musiconline", 1,
            "fhsp", 1,
            "oracle-vp2", 1,
            "oracle-vp1", 1,
            "jerand-lm", 1,
            "scientia-sdb", 1,
            "radius", 1,
            "radius-acct", 1,
            "tdp-suite", 1,
            "mmpft", 1,
            "etftp", 1,
            "plato-lm", 1,
            "mcagent", 1,
            "donnyworld", 1,
            "es-elmd", 1,
            "unisys-lm", 1,
            "metrics-pas", 1,
            "fjicl-tep-a", 1,
            "fjicl-tep-b", 1,
            "linkname", 1,
            "fjicl-tep-c", 1,
            "sugp", 1,
            "tpmd", 1,
            "intrastar", 1,
            "dawn", 1,
            "global-wlink", 1,
            "mtp", 1,
            "armadp", 1,
            "elm-momentum", 1,
            "facelink", 1,
            "persoft", 1,
            "noagent", 1,
            "can-nds", 1,
            "can-dch", 1,
            "can-ferret", 1,
            "noadmin", 1,
            "close-combat", 1,
            "dialogic-elmd", 1,
            "tekpls", 1,
            "hlserver", 1,
            "eye2eye", 1,
            "ismaeasdaqlive", 1,
            "ismaeasdaqtest", 1,
            "bcs-lmserver", 1,
            "dlsrap", 1,
            "foliocorp", 1,
            "licensedaemon", 1,
            "tr-rsrb-p1", 1,
            "tr-rsrb-p2", 1,
            "tr-rsrb-p3", 1,
            "mshnet", 1,
            "stun-p1", 1,
            "stun-p2", 1,
            "stun-p3", 1,
            "ipsendmsg", 1,
            "snmp-tcp-port", 1,
            "stun-port", 1,
            "perf-port", 1,
            "tr-rsrb-port", 1,
            "gdp-port", 1,
            "x25-svc-port", 1,
            "tcp-id-port", 1,
            "callbook", 1,
            "dc", 1,
            "wizard", 1,
            "globe", 1,
            "mailbox", 1,
            "emce", 1,
            "berknet", 1,
            "oracle", 1,
            "invokator", 1,
            "raid-cc", 1,
            "dectalk", 1,
            "raid-am", 1,
            "conf", 1,
            "terminaldb", 1,
            "whosockami", 1,
            "search", 1,
            "pipe_server", 1,
            "servserv", 1,
            "ttyinfo", 1,
            "raid-ac", 1,
            "raid-cd", 1,
            "troff", 1,
            "raid-sf", 1,
            "cypress", 1,
            "raid-cs", 1,
            "bootserver", 1,
            "cypress-stat", 1,
            "bootclient", 1,
            "rellpack", 1,
            "about", 1,
            "xinupageserver", 1,
            "servexec", 1,
            "xinuexpansion1", 1,
            "down", 1,
            "xinuexpansion2", 1,
            "xinuexpansion3", 1,
            "xinuexpansion4", 1,
            "ellpack", 1,
            "xribs", 1,
            "scrabble", 1,
            "shadowserver", 1,
            "submitserver", 1,
            "device2", 1,
            "blackboard", 1,
            "glogger", 1,
            "scoremgr", 1,
            "imsldoc", 1,
            "objectmanager", 1,
            "lam", 1,
            "interbase", 1,
            "isis", 1,
            "isis-bcast", 1,
            "rimsl", 1,
            "cdfunc", 1,
            "sdfunc", 1,
            "dls-monitor", 1,
            "shilp", 1,
            "nfs", 1,
            "dlsrpn", 1,
            "dlswpn", 1,
            "zephyr-srv", 1,
            "zephyr-clt", 1,
            "zephyr-hm", 1,
            "minipay", 1,
            "mc-gt-srv", 1,
            "ats", 1,
            "imtc-map", 1,
            "kali", 1,
            "unreg-ab1", 1,
            "unreg-ab2", 1,
            "inreg-ab3", 1,
            "ivs-video", 1,
            "infocrypt", 1,
            "directplay", 1,
            "sercomm-wlink", 1,
            "nani", 1,
            "optech-port1-lm", 1,
            "aviva-sna", 1,
            "imagequery", 1,
            "ivsd", 1,
            "xmquery", 1,
            "lnvpoller", 1,
            "lnvconsole", 1,
            "lnvalarm", 1,
            "lnvstatus", 1,
            "lnvmaps", 1,
            "lnvmailmon", 1,
            "nas-metering", 1,
            "dna", 1,
            "netml", 1,
            "pehelp", 1,
            "sdhelp", 1,
            "cvspserver", 1,
            "rtsserv", 1,
            "rtsclient", 1,
            "hp-3000-telnet", 1,
            "netrek", 1,
            "tqdata", 1,
            "www-dev", 1,
            "aic-np", 1,
            "aic-oncrpc", 1,
            "piccolo", 1,
            "fryeserv", 1,
            "media-agent", 1,
            "mao", 1,
            "funk-dialout", 1,
            "tdaccess", 1,
            "blockade", 1,
            "epicon", 1,
            "hbci", 1,
            "redwood-broker", 1,
            "exlm-agent", 1,
            "gw", 1,
            "ping-pong", 1,
            "trusted-web", 1,
            "pctrader", 1,
            "nsws", 1,
            "vmodem", 1,
            "rdc-wh-eos", 1,
            "seaview", 1,
            "tarantella", 1,
            "csi-lfap", 1,
            "mc-brk-srv", 1,
            "ccmail", 1,
            "altav-tunnel", 1,
            "ns-cfg-server", 1,
            "ibm-dial-out", 1,
            "msft-gc", 1,
            "msft-gc-ssl", 1,
            "verismart", 1,
            "csoft-prev", 1,
            "user-manager", 1,
            "sxmp", 1,
            "ordinox-server", 1,
            "samd", 1,
            "maxim-asics", 1,
            "awg-proxy", 1,
            "lkcmserver", 1,
            "admind", 1,
            "vs-server", 1,
            "sysopt", 1,
            "datusorb", 1,
            "net-assistant", 1,
            "4talk", 1,
            "plato", 1,
            "e-net", 1,
            "directvdata", 1,
            "oops", 1,
            "enpc", 1,
            "caps-lm", 1,
            "sah-lm", 1,
            "cart-o-rama", 1,
            "fg-fps", 1,
            "fg-gip", 1,
            "dyniplookup", 1,
            "rib-slm", 1,
            "cytel-lm", 1,
            "transview", 1,
            "pdrncs", 1,
            "bmcpatrolagent", 1,
            "bmcpatrolrnvu", 1,
            "dec-notes", 1,
            "bmap", 1,
            "mira", 1,
            "prsvp", 1,
            "vat", 1,
            "vat-control", 1,
            "d3winosfi", 1,
            "integral", 1,
            "mapper-nodemgr", 1,
            "mapper-mapethd", 1,
            "mapper-ws_ethd", 1,
            "terabase", 1,
            "netcheque", 1,
            "chimera-hwm", 1,
            "samsung-unidex", 1,
            "altserviceboot", 1,
            "pda-gate", 1,
            "acl-manager", 1,
            "nuts_dem", 1,
            "nuts_bootp", 1,
            "nifty-hmi", 1,
            "oirtgsvc", 1,
            "oidocsvc", 1,
            "oidsr", 1,
            "vrml-multi-use", 1,
            "rwhois", 1,
            "unicall", 1,
            "vinainstall", 1,
            "krb524", 1,
            "nv-video", 1,
            "upnotifyp", 1,
            "n1-fwp", 1,
            "n1-rmgmt", 1,
            "asc-slmd", 1,
            "arcryptoip", 1,
            "camp", 1,
            "ctisystemmsg", 1,
            "ctiprogramload", 1,
            "nssalertmgr", 1,
            "nssagentmgr", 1,
            "sae-urn", 1,
            "urn-x-cdchoice", 1,
            "highscore", 1,
            "rfa", 1,
            "commplex-main", 1,
            "commplex-link", 1,
            "rfe", 1,
            "claris-fmpro", 1,
            "avt-profile-1", 1,
            "avt-profile-2", 1,
            "telelpathstart", 1,
            "telelpathattack", 1,
            "zenginkyo-1", 1,
            "zenginkyo-2", 1,
            "mmcc", 1,
            "rmonitor_secure", 1,
            "atmp", 1,
            "aol", 1,
            "aol-1", 1,
            "aol-2", 1,
            "aol-3", 1,
            "padl2sim", 1,
            "hacl-hb", 1,
            "hacl-gs", 1,
            "hacl-cfg", 1,
            "hacl-probe", 1,
            "hacl-local", 1,
            "hacl-test", 1,
            "sun-mc-grp", 1,
            "sco-aip", 1,
            "cfengine", 1,
            "jprinter", 1,
            "outlaws", 1,
            "tmlogin", 1,
            "excerpt", 1,
            "excerpts", 1,
            "hpoms-ci-lstn", 1,
            "hpoms-dps-lstn", 1,
            "netsupport", 1,
            "systemics-sox", 1,
            "foresyte-clear", 1,
            "foresyte-sec", 1,
            "salient-dtasrv", 1,
            "salient-usrmgr", 1,
            "actnet", 1,
            "continuus", 1,
            "wwiotalk", 1,
            "statusd", 1,
            "ns-server", 1,
            "sns-gateway", 1,
            "sns-agent", 1,
            "mcntp", 1,
            "dj-ice", 1,
            "cylink-c", 1,
            "personal-agent", 1,
            "esmmanager", 1,
            "esmagent", 1,
            "a1-msc", 1,
            "a1-bs", 1,
            "a3-sdunode", 1,
            "a4-sdunode", 1,
            "pcanywheredata", 1,
            "pcanywherestat", 1,
            "rrac", 1,
            "dccm", 1,
            "proshareaudio", 1,
            "prosharevideo", 1,
            "prosharedata", 1,
            "prosharerequest", 1,
            "prosharenotify", 1,
            "openmail", 1,
            "openmailg", 1,
            "x500ms", 1,
            "openmailns", 1,
            "s-openmail", 1,
            "openmailpxy", 1,
            "fcopy-server", 1,
            "x11", 1,
            "softcm", 1,
            "spc", 1,
            "dtspcd", 1,
            "backup-express", 1,
            "meta-corp", 1,
            "aspentec-lm", 1,
            "watershed-lm", 1,
            "statsci1-lm", 1,
            "statsci2-lm", 1,
            "lonewolf-lm", 1,
            "montage-lm", 1,
            "tal-pod", 1,
            "crip", 1,
            "clariion-evr01", 1,
            "skip-cert-recv", 1,
            "skip-cert-send", 1,
            "lvision-lm", 1,
            "xdsxdm", 1,
            "vocaltec-gold", 1,
            "vision_server", 1,
            "vision_elmd", 1,
            "ambit-lm", 1,
            "acmsoda", 1,
            "afs3-fileserver", 1,
            "afs3-callback", 1,
            "afs3-prserver", 1,
            "afs3-vlserver", 1,
            "afs3-kaserver", 1,
            "afs3-volser", 1,
            "afs3-errors", 1,
            "afs3-bos", 1,
            "afs3-update", 1,
            "afs3-rmtsys", 1,
            "ups-onlinet", 1,
            "dpserve", 1,
            "dpserveadmin", 1,
            "lazy-ptop", 1,
            "font-service", 1,
            "virprot-lm", 1,
            "clutild", 1,
            "fodms", 1,
            "dlip", 1,
            "winqedit", 1,
            "pmdmgr", 1,
            "oveadmgr", 1,
            "ovladmgr", 1,
            "opi-sock", 1,
            "xmpv7", 1,
            "pmd", 1,
            "telops-lmd", 1,
            "pafec-lm", 1,
            "cbt", 1,
            "accu-lmgr", 1,
            "quest-vista", 1,
            "irdmi2", 1,
            "irdmi", 1,
            "pro-ed", 1,
            "npmp", 1,
            "ddi-tcp-1", 1,
            "ddi-udp-1", 1,
            "ddi-tcp-2", 1,
            "ddi-udp-2", 1,
            "ddi-tcp-3", 1,
            "ddi-udp-3", 1,
            "ddi-tcp-4", 1,
            "ddi-udp-4", 1,
            "ddi-tcp-5", 1,
            "ddi-udp-5", 1,
            "ddi-tcp-6", 1,
            "ddi-udp-6", 1,
            "ddi-tcp-7", 1,
            "ddi-udp-7", 1,
            "cslistener", 1,
            "man", 1,
            "sd", 1,
            "palace", 1,
            "distinct32", 1,
            "distinct", 1,
            "ndmp", 1,
            "tsaf", 1,
            "dsmcc-config", 1,
            "dsmcc-session", 1,
            "dsmcc-passthru", 1,
            "dsmcc-download", 1,
            "dsmcc-ccp", 1,
            "isode-dua", 1,
            "biimenu", 1,
            "r", 1,
            "webphone", 1,
            "netspeak-is", 1,
            "netspeak-cs", 1,
            "netspeak-acd", 1,
            "netspeak-cps", 1,
            "wnn6", 1,
            "vocaltec-wconf", 1,
            "vocaltec-phone", 1,
            "aws-brf", 1,
            "brf-gw", 1,
            "icl-twobase1", 1,
            "icl-twobase2", 1,
            "icl-twobase3", 1,
            "icl-twobase4", 1,
            "icl-twobase5", 1,
            "icl-twobase6", 1,
            "icl-twobase7", 1,
            "icl-twobase8", 1,
            "icl-twobase9", 1,
            "icl-twobase10", 1,
            "vocaltec-hos", 1,
            "quake", 1,
            "wnn6-ds", 1,
            "dbbrowse", 1,
            "ap", 1,
            "bacnet", 1,
           );



1;



#
#	End of included '/home/davidk/db/src/src/defines.pl' data is here
#

#
#	The file '/home/davidk/db/src/src/ripe2rpsl.pl' is included here
#



#
# $Id: ripe2rpsl 1.4 Thu, 23 Apr 1998 19:52:07 -0700 wlee $
# 
#  Copyright (c) 1994 by the University of Southern California
#  and/or the International Business Machines Corporation.
#  All rights reserved.
#
#  Permission to use, copy, modify, and distribute this software and
#  its documentation in source and binary forms for lawful
#  non-commercial purposes and without fee is hereby granted, provided
#  that the above copyright notice appear in all copies and that both
#  the copyright notice and this permission notice appear in supporting
#  documentation, and that any documentation, advertising materials,
#  and other materials related to such distribution and use acknowledge
#  that the software was developed by the University of Southern
#  California, Information Sciences Institute and/or the International
#  Business Machines Corporation.  The name of the USC or IBM may not
#  be used to endorse or promote products derived from this software
#  without specific prior written permission.
#
#  NEITHER THE UNIVERSITY OF SOUTHERN CALIFORNIA NOR INTERNATIONAL
#  BUSINESS MACHINES CORPORATION MAKES ANY REPRESENTATIONS ABOUT
#  THE SUITABILITY OF THIS SOFTWARE FOR ANY PURPOSE.  THIS SOFTWARE IS
#  PROVIDED "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES,
#  INCLUDING, WITHOUT LIMITATION, THE IMPLIED WARRANTIES OF
#  MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE, TITLE, AND 
#  NON-INFRINGEMENT.
#
#  IN NO EVENT SHALL USC, IBM, OR ANY OTHER CONTRIBUTOR BE LIABLE FOR ANY
#  SPECIAL, INDIRECT OR CONSEQUENTIAL DAMAGES, WHETHER IN CONTRACT,
#  TORT, OR OTHER FORM OF ACTION, ARISING OUT OF OR IN CONNECTION WITH,
#  THE USE OR PERFORMANCE OF THIS SOFTWARE.
#
#  Questions concerning this software should be directed to 
#  info-ra@isi.edu.
#
#  Author(s): Cengiz Alaettinoglu <cengiz@isi.edu>
#  Author(s): David Kessens <davidk@isi.edu>

sub fix_policy_attr_errors {
    local(*str)=@_;
    
# ask the follwoing exp
    $str=~ s/[^\S\r\n]+/ /g;
    $str=~ s/ *([\r\n]+) */$1/g;
    
    $str=~ s/OR\s+OR/OR/ig;
    $str=~ s/AND\s+AND/AND/ig;
    $str=~ s/AND\s+ANT/ANY AND/g;
    while ($str=~ s/\((AND|OR)\s*([^\s\)][^\)]+\))/$1 \($2/gi) {};
  
    $str=~ s/\=20//gi;
  
    $str=~ s/([^\d\.]\d+\.\d+\.\d+)(\/\d+[^\d])/$1\.0$2/g;
    $str=~ s/([^\d\.]\d+\.\d+)(\/\d+[^\d])/$1\.0\.0$2/g;
}

sub fix_filter_errors {
    local(*str)=@_;

    $str =~ s/^\d+\s+//g;
    $str =~ s/(AS\d+\s*),/$1/gi; # potentially dangerous when input is rpsl
    $str =~ s/\"//g;
    $str=~ s/(<[^>]+\*)1040\b/$1*>/g;
#    $str=~ s/(\s*)$/\>$1/ if (scalar($str=~ tr/\</\</)-scalar($str=~ tr/\>/\>/)==1);
#    $str=~ s/(\s*)$/\}$1/ if (scalar($str=~ tr/\{/\{/)-scalar($str=~ tr/\}/\}/)==1);

    local(@lines)=();

    foreach (split(/([^a-zA-Z\d\-]+)/, $str)) {
       if (/^[^a-zA-Z\d\-]+$/) {
	 push(@lines, $_);
	 next;
       }
       $_="RS-".$_ if ((/^[a-zA-Z]([a-zA-Z0-9_-]*[a-zA-Z0-9])?$/) && # a word
                       (! /^(AS\d+|AS-.*|RS-.*|AND|NOT|OR|ANY)$/i));
       push(@lines, $_);
    }

    $str=join("", @lines);

}

sub fix_email_errors() {
    local(*str)=@_;

    local(@lines)=();

    $str =~ s/<//g;
    $str =~ s/>//g;
 
    foreach (split(/(\s+)/,  $str)) {
       if (/^\s+$/) {
          if (/\n/) {
             push(@lines, "\n");
          }
          elsif (/\r/) {
             push(@lines, "\r");
          }
          else {
             push(@lines, " ");
          }
          next;
       }
       (/\@[\w\-]+$/) &&
       ((s/(com|org|net|edu|gov)$/.$1/i) ||
        (s/(com?|org|net|edu|gov)(..)$/.$1.$2/i));
       push(@lines, $_);
    }

    $str=join("", @lines);

}

sub fix_date_errors() {
    local(*str)=@_;

    local(@lines)=();

    foreach (split(/(\s+)/,  $str)) {
       if (/^\s+$/) {
          if (/\n/) {
             push(@lines, "\n");
          }
          elsif (/\r/) {
             push(@lines, "\r");
          }
          else {
             push(@lines, " ");
          }
          next;
       }
       /^\d\d\.\d\d\.\d\d$/ && s/\.//g;
       s/^(\d{6})$/19$1/g;
       push(@lines, $_);
    }

    $str=join("", @lines);

}

sub fix_mntner_errors() {
    local(*str)=@_;

    local(@lines)=();

    foreach (split(/(\s+)/,  $str)) {
       if (/^\s+$/) {
          if (/\n/) {
             push(@lines, "\n");
          }
          elsif (/\r/) {
             push(@lines, "\r");
          }
          else {
             push(@lines, " ");
          }
          next;
       }
       s/^AS\d+$/MNT-$&/i ||
       s/^AS-/MNT-AS-/i ||
       s/^RS-/MNT-RS-/i ||
       s/^\d/MNT-$&/gi;
       push(@lines, $_);
    }

    $str=join("", @lines);

}

sub uniqify_listify() {
    local(*str) = @_;
    
    local(%items)=();
    local(@lines)=();
    local($i)=0;

    foreach (grep( $_ && ((++$items{$_})==1), split(/[\s,]/, $str))) {
       if ($i % 5) {
          push(@lines, ", ", $_);
       }
       else {
          if (@lines) {
             push(@lines, ",\r", $_);
          }
          else {
             push(@lines, $_);
          }
          $i=0;
       }
       $i++;
    }
    $str=join("", @lines);
    

}


sub ripe2rpsl {
    local(*entry, $type)=@_; 

    local($str, $line, @lines, $lastline, $thisline, $peeras, $pref, $rest);
    local($br, $peerbr);

    #
    # delete as-exclude/advisory attributes

    delete($entry{"ae"});
    delete($entry{"av"});
    #
    # the following is all kind of Merit crap: 
    delete($entry{"ne"});
    delete($entry{"np"});
    delete($entry{"cp"});
    delete($entry{"ri"});
    delete($entry{"rs"});

    #
    # remove garbage values
    foreach ("em", "fx", "ny", "ph") {
       $entry{$_}=~ s/(^|\n)(\<?(NONE(\s+yet)?|no\s+fax|no\s+\-?e\-?mail)\>?|nobody\@nowhere\.net)\s*($|\n)/\n/i;
       $entry{$_}=~ s/\n+$/\n/g;
       $entry{$_}=~ s/^\n//;
       $entry{$_}=~ s/\n$//;
    }

    #
    # remove line continuation information
    foreach (keys %entry) {
       delete($entry{$_}) if (/$CONTINUATIONSUFFIX$/o);
    }

    # 
    # if the following attributes are missing insert them
    $entry{"aa"}="UNSPECIFIED"         if (($type eq "an") && ($entry{"aa"}=~ /^\s*$/));
    $entry{"em"}="nobody\@nowhere.net" if (($type eq "pn") && ($entry{"em"}=~ /^\s*$/));
    $entry{"ad"}="no address"          if (($type eq "pn") && ($entry{"ad"}=~ /^\s*$/));
    $entry{"mb"}="MNT-ANYBODY"         if                     ($entry{"mb"}=~ /^\s*$/) ;

    #  
    # the following attributes are now single valued
    $entry{"wd"} =~ s/^.*/$&/ if $entry{"wd"};
    $entry{"mb"} =~ tr/\n/ /  if $entry{"mb"};
    $entry{"ml"} =~ tr/\n/ /  if $entry{"ml"};
    $entry{"al"} =~ tr/\n/ /  if $entry{"al"};
    $entry{"cl"} =~ tr/\n/ /  if $entry{"cl"};
    $entry{"ho"} =~ tr/\n/ /  if $entry{"ho"};

    #
    # MCI contained comments at many wrong places ...
    # also thismakes sure to get rid of '# EOF' at end of files.

    if ($entry{"so"}=~ /^(\w+)/) {
       $entry{"so"}=$1;
    }

    #
    # fix st
    if ($entry{"st"}) {
       $entry{"st"}=~ s/(\s)D(\s*)$/$1ALLOCATED UNSPECIFIED$2/i;
       $entry{"st"}=~ s/(\s)[^D](\s*)$/$1ASSIGNED PI$2/i;
    }

    #
    # fix ch
    if ($entry{"ch"}) {

       $str=$entry{"ch"};

       $str=~ s/,(\s*\d)/$1/g;
       &fix_email_errors(*str);
       &fix_date_errors(*str);

       @lines = ();
       foreach (split(/\n/, $str)) {
          
	 @fields = split(/\s+/, $_);
	 if ($fields[$#fields] =~ /^\d{8}$/) {
	   push(@lines, $fields[0]." ".$fields[$#fields]);
	   next;
	 }

	 push(@lines, $fields[0]." ".$DATE);
       }
       $entry{"ch"}=join("\n", @lines, $CHANGEDLINE);

    }
    else {
       $entry{"ch"}=$CHANGEDLINE;
    }

    #
    # fix remarks
    if ($entry{"rm"}) {
       $entry{"rm"}=join("\n", $entry{"rm"}, $REMARKSLINE);
    }
    else {
       $entry{"rm"}=$REMARKSLINE;
    }

    #
    # fix wd
    if ($entry{"wd"}) {

       $str=$entry{"wd"};

       &fix_date_errors(*str);
       
       @lines = ();
       foreach (split(/\n/, $str)) {
          
          if (/^\d{8,8}$/) {
             push(@lines, $line);
             next;
          }
  
          push(@lines, $DATE);

       }
       $entry{"wd"}=join("\n", @lines);

    }

    # fix ifaddr
    if ($entry{"if"}) {
      @lines = split(/\n/, $entry{"if"});
      for ($i =0; $i <= $#lines; $i++) {
	$mask = 0;
	@fields = split(/\s+/, $lines[$i]);
	foreach $_ (split(/\./, $fields[$#fields])) {
	  last if ($_ == 0);
	  if ($_ < 128) {
	    next;
	  }
	  if ($_ < 192) {
	    $mask+=1;
	    next;
	  }
	  if ($_ < 224) {
	    $mask+= 2;
	    next;
	  }
	  if ($_ < 240) {
	    $mask+= 3;
	    next;
	  }
	  if ($_ < 248) {
	    $mask+= 4;
	    next;
	  }
	  if ($_ < 252) {
	    $mask+= 5;
	    next;
	  }
	  if ($_ < 254) {
	    $mask+= 6;
	    next;
	  }
	  if ($_ < 255) {
	    $mask+= 7;
	    next;
	  }
	  $mask+= 8;
	}
	pop @fields;
	$lines[$i] = join(" ", @fields, "masklen", $mask);
      }
      $entry{"if"} = join("\n", @lines);
    }

    # fix peer
    if ($entry{"pe"}) {
      @lines = split(/\n/, $entry{"pe"});
      for ($i =0; $i <= $#lines; $i++) {
	split(/\s+/, $lines[$i]);
	$lines[$i] = join(" ", $_[2], $_[0], "asno($_[1])");
      }
      $entry{"pe"} = join("\n", @lines);
    }

    #  
    # fix aa
    if ($entry{"aa"}) {
       $entry{"aa"}=~ s/^AS(\d+)/ASN-$1/i;
       $entry{"aa"}=~ s/^AS-/ASN-/i;
       $entry{"aa"}=~ s/^RS-/ASN-RS-/i;
       $entry{"aa"}=~ s/^(\d)/ASN-$1/i;
    }

    #
    # fix community
    if ($entry{"cm"}) {
       $entry{"rs"}="RS-".delete($entry{"cm"});
       $entry{"mr"} = "any";
       $type="rs";
    }

    #
    # fix comm-list
    if ($entry{"cl"}) {
       $entry{"ms"}="RS-".join(", RS-", split(/[\s,]+/, delete($entry{"cl"})));
    }

    #
    # fix community
    if ($entry{"am"}) {
       $entry{"as"}=delete($entry{"am"});
       $type="as";
    }

    #
    # fix as-list
    if ($entry{"al"}) {
       $str=delete($entry{"al"});
       &uniqify_listify(*str);
       $entry{"ms"}=$str;
    }

    if ($entry{"mt"}) {
       $str=$entry{"mt"};
       &fix_mntner_errors(*str);
       $entry{"mt"}=$str;
    }

    if ($entry{"mb"}) {
       $str=$entry{"mb"};
       &fix_mntner_errors(*str);
       &uniqify_listify(*str);
       $entry{"mb"}=$str;
    }
    
    if ($entry{"ml"}) {
       $str=$entry{"ml"}; 
       &fix_mntner_errors(*str);
       &uniqify_listify(*str);
       $entry{"ml"}=$str; 
    }
    
    if ($entry{"em"}) {
       $str=$entry{"em"}; 
       &fix_email_errors(*str);
       $entry{"em"}=$str; 
    }
    
    if ($entry{"dt"}) {
       $str=$entry{"dt"};  
       &fix_email_errors(*str);
       $entry{"dt"}=$str; 
    }
 
    if ($entry{"gd"}) {
       if ($entry{"ny"}) {
          $entry{"ny"}=$entry{"gd"}; 
       }
       else {
          $entry{"ny"}=$entry{"gd"}."\n".$entry{"ny"}; 
       }
    }

    if ($entry{"ny"}) {
       $str=$entry{"ny"};
# ask does this uniquify 
       &fix_email_errors(*str);
       $entry{"ny"}=join("\n", grep( $_ && ((++$items{$_})==1), split(/\s*\n+\s*/, $str)));
       #print "*",$str,"*", join("*", keys %items), "*\n";
       #$entry{"ny"}=join("\n", keys %items);  
    }

    if ($entry{"ho"}) {
       $str=$entry{"ho"}; 
       &uniqify_listify(*str);
       $entry{"ho"}=$str; 
    }

    if ($entry{"ir"}) {
       
       if ($line=&convert2domainname($entry{"ir"})) {
          $entry{"ir"}=$line;
       }
       else {
          $entry{"ir"}=~ s/^\s*(\d+)\.(\d+)\.(\d+)\.(\d+)\s*$/$4.$3.$2.$1.in-addr.arpa/;
       }
    
    }

    # fix default
    if ($entry{"df"}) {
      $str=$entry{"df"};
      &fix_policy_attr_errors(*str);
      $str=~s/default/ANY/g;
      $str=~s/static/ANY/g;

      @lines=();
      foreach (split(/\n/, $str)) {
	($peeras, $pref, $rest) = split(/ +/, $_, 3);
	$rest = "ANY" if (!$rest);
	push(@lines, join("", "to ", $peeras, 
			  "\raction pref=", $pref, 
			  ";\rnetworks ", $rest)); 
      }
      $entry{"df"}=join("\n", @lines);
    }

    #
    # interas-in lines
    
    if ($entry{"it"}) {

       $str=delete($entry{"it"});
       &fix_policy_attr_errors(*str);
  
       $lastline="";
       $thisline="";
       @lines=();

       foreach (split(/\n/, $entry{"it"})) {
          ($peeras, $br, $peerbr, $rest) = split(/ +/, $_, 4);
          $rest=~ /\(\s*PREF\s*=\s*([^)\s]*)\s*\)\s*(.*)$/i;
          $pref=$1;
          $rest=$2;
          &fix_filter_errors(*rest);

          $thisline = "$peeras%$br%$peerbr%$pref";
          if ($thisline eq $lastline) {
	     $lines[$#lines] .= " " . $rest if (@lines);
          }
          else {
	     push(@lines, join("", "from ", $peeras, $peerbr, " at ", $br, 
			           "\raction pref=", $pref,
			           ";\raccept ", $rest));
          }
          $lastline = $thisline;
       }

       if ($entry{"ip"}) {
          $entry{"ip"}.="\n".join("\n", @lines);
       }
       else {
          $entry{"ip"}=join("\n", @lines);
       }

    }

    #
    # interas-out lines
    
    if ($entry{"io"}) {

       $str=delete($entry{"io"});
       &fix_policy_attr_errors(*str);
  
       $lastline="";
       $thisline="";
       @lines=();

       foreach (split(/\n/, $entry{"io"})) {
          
          ($peeras, $br, $peerbr, $rest) = split(/ +/, $_, 4);
          if ($rest =~ /\(\s*METRIC\-OUT\s*=\s*([^)\s]*)\s*\)?\s*(.*)$/i) {
             $pref = $1;
             $rest = $2;
          }
          else {
	     $pref = "?";
          }
          &fix_filter_errors(*$rest);

          $thisline = "$peeras%$br%$peerbr%$pref";
          if ($thisline eq $lastline) {
             $lines[$#lines] .= " " . $rest if (@lines);
          }
          else {
	   
             if ($pref eq "?") {
	        push(@lines, join("", "to ", $peeras, $peerbr, " at ", $br, 
                                      "\rannounce ", $rest));
	     }
             else {
	        push(@lines, join("", "to ", $peeras, $peerbr, " at ", $br, 
                                      "\raction med=", $pref,
                                      ";\rannounce ", $rest));
	     }

          }
       
          $lastline = $thisline;
       }

       if ($entry{"ep"}) {
          $entry{"ep"}.="\n".join("\n", @lines);
       }
       else {
          $entry{"ep"}=join("\n", @lines);
       }

    }

    #
    # as-in lines
    if ($entry{"ai"}) {

       $str=delete($entry{"ai"});

       &fix_policy_attr_errors(*str);
       $str=~ s/\bfrom\s+//gi && $str=~ s/\s+accept\s+/ /gi;
       
       $lastline="";
       $thisline="";
       @lines=();
    
       foreach (split(/\n/, $str)) {
          
          ($peeras, $pref, $rest) = split(/ +/, $_, 3);
	  if (! $rest) {
	    $rest = $pref;
	    $pref = "";
	  }
          &fix_filter_errors(*rest);

          $thisline = "$peeras%$pref";
          if ($thisline eq $lastline) {
	     $lines[$#lines] .= " " . $rest if (@lines);
          }
          else {
	    if ($pref) {
	      push(@lines, join("", "from ", $peeras, "\raction pref=", $pref, 
				";\raccept ", $rest));
	    } else {
	      push(@lines, join("", "from ", $peeras, "\raccept ", $rest));	      
	    }
          }
          $lastline = $thisline;
       }

       foreach (@lines) {
	 s/accept AND NOT/accept ANY AND NOT/i;
	 s/NOT$/NOT {}/i;
	 s/OR$/OR {}/i;
	 s/AND$/AND {}/i;
       }

       if ($entry{"ip"}) {
          $entry{"ip"}.="\n".join("\n", @lines);
       }
       else {
          $entry{"ip"}=join("\n", @lines);
       }

    }

    #
    # as-out lines
    if ($entry{"ao"}) {

       $str=delete($entry{"ao"});

       &fix_policy_attr_errors(*str);
       $str=~ s/\bto\s+//gi && $str=~ s/\s+announce\s+/ /gi;

       $lastline="";
       $thisline="";
       @lines=();

       foreach (split(/\n/, $str)) {
          
          ($peeras, $rest)=split(/ +/, $_, 2);
          &fix_filter_errors(*rest);

          $thisline = "$peeras";
          if ($thisline eq $lastline) {
	     $lines[$#lines] .= " " . $rest if (@lines);
          }
          else {
	     push(@lines, join("", "to ", $peeras, "\rannounce ", $rest));
          }
          $lastline = $thisline;

       }

       foreach (@lines) {
	 s/announce AND NOT/announce ANY AND NOT/i;
	 s/NOT$/NOT {}/i;
	 s/OR$/OR {}/i;
	 s/AND$/AND {}/i;
       }

       if ($entry{"ep"}) {
          $entry{"ep"}.="\n".join("\n", @lines);
       }
       else {
          $entry{"ep"}=join("\n", @lines);
       }

    }
    
    return $type;
    
}

1;



#
#	End of included '/home/davidk/db/src/src/ripe2rpsl.pl' data is here
#

#
#	The file '/home/davidk/db/src/src/enread.pl' is included here
#


#
#       enread - read RIPE database entry
#
#	$RCSfile: enread.pl,v $
#	$Revision: 1.4 $
#	$Author: wlee $
#	$Date: Thu, 23 Apr 1998 19:52:07 -0700 $
#
#       This routine reads RIPE database entries in %entry and returns the
#       type, "" when nothing has been found, $DELETEDOBJECT when
#       the object has been deleted, and an other invalid type when an 
#       invalid object has been found.
#       When no valid/deleted object has been found %entry is set to ().
#
#       file       file to read from


#
# enread
#
# Take care with changing anything in this routine.
# It is highly optimized for speed, especially for (sorted) big objects.
#
# $offset=#
#         >=0   read from position # and return position first found object
#         =-1   return position first found object read from current position and 
#         =-2   read from current position and don't return current position

sub enread {
    local($file, *entry, $offset, $size) = @_;

    local($line,$newtag,$shorttag,$connect,$prefixlength,$standardprefixlength,$linelength);

    local($readsize)=0;
    local($tag)="";
    local($type)="";
    local(@inputlines)=();
    local(@connectlength)=();
    %entry=();

    local(@lines);

    #
    # select the right file for reading for RPSLCONVERSION
    # special update path data

    $file.=".rpsl" if ($offset=~ /^0[^0]/);
  
    # print STDERR "enread file: $file offset: $offset size: $size\n";
    
    # print STDERR "first line: ", scalar(<$file>); seek($file, $offset, 0);

    if (defined($size)) {
       
       local($object);

       if ($SYSREAD) {
          if (-2!=$offset) {
             if ($offset>=0) {
                $offset=sysseek($file, $offset, 0);
             }
             else {
                $offset=sysseek($file, 0, 1) 
             }
          }
          elsif ($offset>=0) {
             sysseek($file, $offset, 0) 
          }
          &safesysread($file, *object, $size);
       }
       else {
          $offset=tell($file) if ($offset!=-2);
          seek($file, $offset, 0) if ($offset>=0);
          &readparagraph($file, *object);
       }

       $object=~ s/\n+$//;

       # print STDERR "enread file: $file size: $size loc: ", tell($file), " ",$object, "-\n";

       ($line,@inputlines)=split(/\n/, $object);

       $line=~ s/\s/ /g;
       
       # print STDERR "$line --- \n", join("\n",@inputlines);

    }
    else {

       # print "no seek $offset $!\n";

       seek($file, $offset, 0) if ($offset>=0);

       # print "seek $!\n";

       #
       # skip empty lines until we find the first data and
       # make sure that we keep the offset
    
       $offset=tell($file) if (-2!=$offset);
       while ((($line=<$file>)=~ s/\s/ /g) &&
	      (($line=~ /^ +$/) || ($line=~ /^ *\#/))) {
          $offset=tell($file) if (-2!=$offset);
          # print STDERR "skip lines: ", $line;
       }

    }
    
    # print "start $!\n";

    # print STDERR "first line: ", $line;
    
    if ($line) {
       
       #
       # return immediately if we found a deleted object
    
       if ($line=~ /^ *\*?$DELETEDOBJECT *\:/o) {
          # print STDERR "XX object $line";
       
          if (!defined($size)) {
             while ((defined($line=<$file>)) && ($line!~ /^\s+$/)) {} 
          }
            
          return ($DELETEDOBJECT, $offset, 0);

       }
       
       for (;;) {
          
          $linelength=length($line);

          if (($line=~ s/^(\*)?([^\*\: ]+)( *\: *)//) ||
              ((@lines) && (($line=~ s/^( +)(\S)/$2/) || ($line=~ s/^()(\#)/$2/)))) {
             
             $readsize+=$linelength;

             if ($3) {
                
                #
                # we found another attribute

                $standardprefixlength=length($1)+length($2)+length($3);

                ($newtag=$2)=~ tr/A-Z/a-z/;
                $connect="\n";

             }
             else {

                #
                # we have a line continuation
                
                $prefixlength=length($1)-$standardprefixlength;

                push(@connectlength, ($prefixlength<=0)?2:($prefixlength+2));                

                $connect="\r";
                
             }
             
             #
             # remove trailing spaces
             
             $line=~ s/ *$//;
             
             if ($tag eq $newtag) {
             
                # print STDERR "tag: ", $tag, "\n";
             
                # tag is same as previous one
             
                if ($line) {
                   # print STDERR "tag: $tag value: $line\n";
                   push(@lines, $connect, $line);
                }
                else {
                   push(@lines, $connect, "")  if ($lines[$#lines]);
                   #&logmessage("ERRLOG", "enread: empty attribute, normal $tag (offset: ".$offset." ".$offset." ".tell($file).") in line: $newtag:");
                }
             
             }
             else {
                
                #
                # tag could have been changed
                
                #
                # store old tag
                
                if ($entry{$shorttag}) {
                   $entry{$shorttag}=join("", $entry{$shorttag}, $connect, @lines) if (@lines);
                }
                else {
                   $entry{$shorttag}=join("", @lines) if (@lines);
                }

                #
                # store line continuation lengths

                if (@connectlength) {
                   if ($entry{$shorttag.$CONTINUATIONSUFFIX}) {
                      $entry{$shorttag.$CONTINUATIONSUFFIX}=join(" ", $entry{$shorttag.$CONTINUATIONSUFFIX}, @connectlength);
                   }
                   else {
                      $entry{$shorttag.$CONTINUATIONSUFFIX}=join(" ", @connectlength);
                   }
                }
                
                $tag=$newtag;
                
                $shorttag=$ATTR{$tag};
                
                if (!$shorttag) {
                   &logmessage("ERRLOG", "enread: unknown attribute: \'$tag\' found, (offset: ".$offset." ".$offset." ".tell($file).") in line: $tag: ".$line);
                   $shorttag=$tag;
                }
                
                #
                # we keep the type of the object
                
                # print STDERR "newtag: ", keys %OBJATSQ, $tag, "\n";
                
                $type=$shorttag if ((!$type) && ($OBJATSQ{$shorttag}));
                
                #
                # print STDERR "type: ", $type, "\n";
                
                if ($line) {
                   # print STDERR "newtag: $tag type: $type value: $value\n";
                   @lines=($line);

                }
                else {
                   @lines=("");
                   #&logmessage("ERRLOG", "enread: empty attribute, newtag $newtag (offset: ".$offset." ".$offset." ".tell($file).") in line:".$line);
                }
             
             }
             
          }
          else {
             
             # now we have the following possibilties:
             #
             # - we are at the end of the object
             # - we found a comment
             # - we have an error condition
             #
             # let's assume the first possibility first since
             # it is most common
             
             if ($line=~ /^ *$/) {

                #   
                # end of object
                
                #
                # store old tag
                
                if ($entry{$shorttag}) {
                   $entry{$shorttag}=join("", $entry{$shorttag},$connect,@lines);
                }
                else {
                   $entry{$shorttag}=join("", @lines);
                }
                
                #
                # store line continuation lengths

                if ($entry{$shorttag.$CONTINUATIONSUFFIX}) {
                   $entry{$shorttag.$CONTINUATIONSUFFIX}=join(" ", $entry{$shorttag.$CONTINUATIONSUFFIX}, @connectlength) if (@connectlength);
                }
                else {
                   $entry{$shorttag.$CONTINUATIONSUFFIX}=join(" ", @connectlength) if (@connectlength);
                }
      
                # print STDERR "type: $type ",$entry{"so"}." $shorttag entry:\n", %entry, "\n";
                
                return ($type, $offset, $readsize) if ($type);
                
                &logmessage("ERRLOG", "enread: object has no type (offset: ".$offset." ".$offset." ".tell($file).") in line: ".$line);  
                   
                %entry=();
                   
                # just create a type that is not the same as others and 
                # that is for sure invalid ...
                      
                return ($DELETEDOBJECT.$DELETEDOBJECT, $offset, 0);
                      
             }
             elsif ($line!~ /^\#/) {
  
                #              
                # no comment, no end of object
                #
                # we have an error condition
                #
                
                # print STDERR "$offset $line";
                      
                &logmessage("ERRLOG", "enread: no attribute in line (tag: $tag, type: $type) (offset: ".$offset." ".$offset." ".tell($file).") in line: ".$line);  
                
                # skip rest of object
                
                if (!defined($size)) {         
                   while ((defined($line=<$file>)) && ($line!~ /^\s+$/)) {}
                }
     
                %entry=();
                      
                # just create a type that is not the same as others and 
                # that is for sure invalid ...
                      
                return ($DELETEDOBJECT.$DELETEDOBJECT, $offset, 0);
                
             }
             
          }
       
          if (defined($size)) {
             ($line=shift(@inputlines))=~ s/\s/ /g;
             #print STDERR "next: -", $line,"-", @inputlines;
          }
          else {
             ($line=<$file>)=~ s/\s/ /g;
             #print STDERR "line: ",$line,"\n";
          }
          
       
       }
  
    }
    else {
       return();
    }

}

1;


#
#	End of included '/home/davidk/db/src/src/enread.pl' data is here
#

#
#	The file '/home/davidk/db/src/src/enwrite.pl' is included here
#



#
#       enwrite - write RIPE database entry
#
#	$RCSfile: enwrite.pl,v $
#	$Revision: 1.4 $
#	$Author: wlee $
#	$Date: Thu, 23 Apr 1998 19:52:07 -0700 $
#
#	This routine writes a RIPE database entry to standard output
#	in long or short form.
#
#       Arguments:
#	$output		file handle for output
#	*object		pointer to assoc array with database entry
#	$long		boolean flag for long or short format output
#	$witherror	boolean flag for with or without error messages
#       $withsugar      boolean flag for with or without syntactic sugar

sub enwrite {
    local($output, *object, $type, $long, $witherrors) = @_;
    
    local($offset)=tell($output)+1;
    local(@errs)=(); @errs=("uw","ue") if ($witherrors);
    local(@buffer)=("\n");
        
    local($val, @continuations, $margin);
    
    #
    # If we have an unknown object, let's try
    # and print this anyway to inform the user ...

    if (!$type) {

       foreach $key (keys %object) {
	    
          next if (($key=~ /$CONTINUATIONSUFFIX$/o) || 
                   ((!$witherrors) && (grep($key eq $_, @errs))));
	  
          foreach $val (split(/\n/, $object{$key})) {
	       
             if (($long) && ($ATTL{$key})) {
                push(@buffer, $ATTL{$key}, ": ", " " x ($MAXATTRIBUTELENGTH - length($ATTL{$key})));
             }
             elsif ((length($key)==2) && ($ATTR{$key})) {
                push(@buffer, "*", $key, ": ");
             }
             else {
                push(@buffer, $key, ": ");
             }

             #
             # for just in case:
             # remove any line continuations at the end of lines ...

             $val=~ s/[^\S\n]+$//;

             #
             # add line continuation leading spaces

             @continuations=split(/ /, $object{$key.$CONTINUATIONSUFFIX});

             foreach (split(/(\r)/, $val)) {
                  
                if ($_ eq "\r") {

                   $margin=shift(@continuations);
                   $margin=2 if ((!$margin) || ($margin<2));

                   if ($long) {
                      push(@buffer, (" " x ($MAXATTRIBUTELENGTH + $margin)));
                   }
                   else {
                      push(@buffer, (" " x (3 + $margin)));
                   }

                }
                elsif (scalar(@buffer)>$MAXLISTLENGTH) {
                   print $output @buffer;
                   @buffer=($_, "\n");
                }
                else {
                   push(@buffer, $_, "\n");
                }

             }

          }
	
       }

       print $output @buffer if (@buffer);
       return $offset;
    
    }
    
    foreach $key (split(/ /, $OBJATSQ{$type}), @errs) {
    
       next if (!$object{$key});

       # print STDERR "*",$key,"* ", $object{$key}, "\n";
    
       foreach $val (split(/\n/, $object{$key})) {

          if ($long) {
             push(@buffer, $ATTL{$key}, ": ", " " x ($MAXATTRIBUTELENGTH - length($ATTL{$key})));
          }
          else {
             push(@buffer, "*", $key, ": ");
          }

          #
          # for just in case:
          # remove any line continuations at the end of lines ...

          $val=~ s/[^\S\n]+$//;

          #
          # add line continuation leading spaces

          @continuations=split(/ /, $object{$key.$CONTINUATIONSUFFIX});

          foreach (split(/(\r)/, $val)) {
                  
             if ($_ eq "\r") {

                $margin=shift(@continuations);
                $margin=2 if ((!$margin) || ($margin<2));

                if ($long) {
                   push(@buffer, (" " x ($MAXATTRIBUTELENGTH + $margin)));
                }
                else {
                   push(@buffer, (" " x (3 + $margin)));
                }

             }
             elsif (scalar(@buffer)>$MAXLISTLENGTH) {
                print $output @buffer;
                @buffer=($_, "\n");
             }
             else {
                push(@buffer, $_, "\n");
             }

          }

       }

    }

    print $output @buffer if (@buffer);

    return $offset;
    
}

1;


#
#	End of included '/home/davidk/db/src/src/enwrite.pl' data is here
#

#
#	'convert2domainname' is included from the file '/home/davidk/db/src/src/misc.pl'
#


#       misc - miscellaneaous functions
#
#	$RCSfile: misc.pl,v $
#	$Revision: 1.4 $
#	$Author: wlee $
#	$Date: Thu, 23 Apr 1998 19:52:07 -0700 $
#


sub convert2domainname {
    local($domain)=@_;

    return "" if (!&isdomname($domain));

    if ($domain=~ /^$VALIDFULLIP4$/o) {

       local($newdomain)=(gethostbyaddr(pack("C4", split(/\./, $domain)), $AF_INET))[0];
       
       return "" if (!&isdomname($domain));

       return $newdomain;

    }
    
    return $domain;

}

#
#	End of included '/home/davidk/db/src/src/misc.pl' data is here
#

#
#	'getYYYYMMDDandHHMMSS' is included from the file '/home/davidk/db/src/src/misc.pl'
#


#       misc - miscellaneaous functions
#
#	$RCSfile: misc.pl,v $
#	$Revision: 1.4 $
#	$Author: wlee $
#	$Date: Thu, 23 Apr 1998 19:52:07 -0700 $
#


#
# the name says all ...:


sub getYYYYMMDDandHHMMSS {

    local($s,$m,$h,$day,$month,$year,$wd,$yd,$is)=localtime(time);

    if ($year=~ /^9[7-9]$/) {
       $year="19".$year;
    }
    elsif ($year=~ /^\d\d$/) {
       $year="20".$year;
    }

    local($YYYYMMDD)=sprintf("%4d%2d%2d",$year,++$month,$day);
    $YYYYMMDD=~ tr/ /0/;

    local($HHMMSS)=sprintf("%2d:%2d:%2d",$h,$m,$s);
    $HHMMSS=~ s/ /0/g;

    return ($YYYYMMDD,$HHMMSS);
}

#
#	End of included '/home/davidk/db/src/src/misc.pl' data is here
#

#
#	'isdomname' is included from the file '/home/davidk/db/src/src/misc.pl'
#


#       misc - miscellaneaous functions
#
#	$RCSfile: misc.pl,v $
#	$Revision: 1.4 $
#	$Author: wlee $
#	$Date: Thu, 23 Apr 1998 19:52:07 -0700 $
#


sub isdomname {

    # print STDERR "dom: ($_[0])", scalar($_[0]=~ /^\s*$DOMAINNAME\s*$/o), "\n";
    
    return scalar($_[0]=~ /^\s*$DOMAINNAME\s*$/o);

}

#
#	End of included '/home/davidk/db/src/src/misc.pl' data is here
#


#
# end of included code

($DATE,$TIME)=&getYYYYMMDDandHHMMSS();
$REMARKSLINE="-\nThis object is automatically converted from the RIPE181 registry";
$CHANGEDLINE=$AUTOBOX." ".$DATE."\n";

local($type, %entry);

while ($type=(&enread(STDIN, *entry, -1))[0]) {

   $type=&ripe2rpsl(*entry, $type);
   &enwrite(STDOUT, *entry, $type, 1, 1);
  
}

# end of program


