Net-IANA-Services

 view release on metacpan or  search on metacpan

lib/Net/IANA/Services.pm  view on Meta::CPAN


#  Import needed modules
use YAML::Any qw/ LoadFile /;
use File::ShareDir qw/ dist_file /;


#  Export our vars/subs
use Exporter::Easy (
    TAGS => [
        hashes => [qw(
            $IANA_HASH_INFO_FOR_SERVICE
            $IANA_HASH_PORTS_FOR_SERVICE
            $IANA_HASH_SERVICES_FOR_PORT
            $IANA_HASH_SERVICES_FOR_PORT_PROTO
        )],

        regexes => [qw(
            $IANA_REGEX_PORTS
            $IANA_REGEX_PORTS_DCCP
            $IANA_REGEX_PORTS_SCTP
            $IANA_REGEX_PORTS_TCP
            $IANA_REGEX_PORTS_UDP
            $IANA_REGEX_SERVICES
            $IANA_REGEX_SERVICES_DCCP
            $IANA_REGEX_SERVICES_SCTP
            $IANA_REGEX_SERVICES_TCP
            $IANA_REGEX_SERVICES_UDP
        )],

        subs => [qw(
            iana_has_port
            iana_has_service
            iana_info_for_port
            iana_info_for_service
        )],

        all => [qw/ :hashes  :regexes  :subs /],
    ],
    VARS => 1,
);


#  Constants
my $_HASHES_REF = LoadFile dist_file q{Net-IANA-Services}, q{services_hashes_dump.yml};






#####################
#  Regex constants  #
#####################



our $IANA_REGEX_PORTS = qr{\b(?<!-)(?:1(?:1(?:1(?:[234589]|0[345689]?|6[12345]?|7[12345]?|1[012]?)?|3(?:[034589]|2[01]?|19?|67?|71?)?|7(?:[0134678]|2[03]?|51?|96?)?|2(?:[23456789]|0[128]?|1?1)?|9(?:[01234578]|9[789]?|67?)?|0(?:[1234678]|0[01]?|9?5)?|...



our $IANA_REGEX_SERVICES = qr{\b(?<![-])(?:s(?:e(?:[pt]|r(?:v(?:e(?:r(?:view(?:-(?:asn?|icc|gf|rm)|dbms)|-find|graph|start|wsd2)|xec)|i(?:ce(?:-ctrl|meter|tags)|staitsm)|s(?:erv|tat))|comm-(?:scadmin|wlink)|ialgateway|aph)|c(?:-(?:t4net-(?:clt|srv)|p...



our $IANA_REGEX_PORTS_DCCP = qr{\b(?<!-)(?:1(?:02[12]|113)|500[45]|4556|6514|9)\b}i;  ## no critic(RegularExpressions)



our $IANA_REGEX_PORTS_SCTP = qr{\b(?<!-)(?:2(?:9(?:1(?:6[89]|18)|0[45]|4[45])|0(?:0?49)?|(?:547)?1|2(?:25)?)|5(?:0(?:6[01]|9[01])|91[0123]|67[25]|445|868)|3(?:64(?:4[34]|[12]2)|86[348]|097|565)|1(?:1(?:99[789]|67)|02[12]|4001|79)|4(?:7(?:39|40)|(?:33...



our $IANA_REGEX_PORTS_TCP = qr{\b(?<!-)(?:1(?:1(?:1(?:[234589]|0[34569]?|6[12345]?|7[2345]?|1[012]?)?|3(?:[034589]|2[01]?|19?|67?|71?)?|7(?:[0134678]|2[03]?|51?|96?)?|2(?:[23456789]|0[128]?|1?1)?|0(?:[1234678]|0[01]?|9?5)?|6(?:[13456789]|0?0|23?)?|8(...



our $IANA_REGEX_PORTS_UDP = qr{\b(?<!-)(?:1(?:1(?:1(?:[234589]|6[12345]?|0[68]?|1[12]?|71?)?|3(?:[034589]|2[01]?|19?|67?|71?)?|7(?:[0134678]|2[03]?|51?|96?)?|2(?:[23456789]|0[18]?|1?1)?|0(?:[1234678]|0[01]?|9?5)?|8(?:[012345689]|7[67]?)?|6(?:[1234567...



our $IANA_REGEX_SERVICES_DCCP = qr{\b(?<![-])(?:(?:avt-profile-|exp)[12]|d(?:tn-bundle|iscard)|ltp-deepspace|syslog-tls)(?![-])\b}i;  ## no critic(RegularExpressions)



our $IANA_REGEX_SERVICES_SCTP = qr{\b(?<![-])(?:a(?:sap-sctp(?:-tls)?|(?:hs|mq)p|25-fap-fgw|urora|ds-c)|s(?:i(?:mco|ps?)|(?:bc|gs)ap|1-control|mbdirect|sh|ua)|i(?:u(?:hsctpassoc|a)|tu-bicc-stc|pfixs?)|m(?:2(?:[pu]a|ap)|3(?:ap|ua)|egaco-h248)|wme(?:re...



our $IANA_REGEX_SERVICES_TCP = qr{\b(?<![-])(?:s(?:e(?:[pt]|r(?:v(?:e(?:r(?:view(?:-(?:asn?|icc|gf|rm)|dbms)|-find|graph|start|wsd2)|xec)|i(?:ce(?:-ctrl|meter|tags)|staitsm)|stat)|comm-(?:scadmin|wlink)|ialgateway|aph)|c(?:-(?:t4net-(?:clt|srv)|pc2fa...



our $IANA_REGEX_SERVICES_UDP = qr{\b(?<![-])(?:s(?:u(?:[am]|n(?:-(?:s(?:r-(?:iiop(?:-aut|s)?|https?|jm[sx]|admin)|ea-port)|as-(?:j(?:mxrmi|pda)|iiops(?:-ca)?|nodeagt)|user-https|mc-grp|dr|lm)|c(?:acao-(?:(?:jmx|sn)mp|websvc|csa|rmi)|luster(?:geo|mgr)...




####################
#  Hash constants  #
####################



our $IANA_HASH_INFO_FOR_SERVICE = $_HASHES_REF->{ q{service_info} };




our $IANA_HASH_SERVICES_FOR_PORT = $_HASHES_REF->{ q{port} };




our $IANA_HASH_SERVICES_FOR_PORT_PROTO = $_HASHES_REF->{ q{port_proto} };




our $IANA_HASH_PORTS_FOR_SERVICE = $_HASHES_REF->{ q{service} };




#################
#  Subroutines  #
#################



sub iana_has_port {
    my ($port, $protocol) = @_;
    if (defined $protocol) {
        my $port_ref = $IANA_HASH_SERVICES_FOR_PORT_PROTO->{ $port };
        if (defined $port_ref) {
            return $port_ref->{ $protocol } ? 1 : 0;
        }
        else {
            return 0;
        }
    }
    else {
        return $IANA_HASH_SERVICES_FOR_PORT->{ $port } ? 1 : 0;
    }
}




sub iana_has_service {
    my ($service, $protocol) = @_;
    if (defined $protocol) {
        my $serv_ref = $IANA_HASH_INFO_FOR_SERVICE->{ $service };
        if (defined $serv_ref) {



( run in 2.378 seconds using v1.01-cache-2.11-cpan-75ffa21a3d4 )