Domain.pm

filter: Statementstmt 40.1% 55 / 137 Branchbran 22.6% 19 / 84 Conditioncond 16.9% 10 / 59 MC/DCmcdc 0.0% 0 / 31 Subroutinesub 100% 12 / 12 Podpod 100% 4 / 4 totaltotal 30.5% 100 / 327 CC 65 SCAR 54.9
CC
65
Cov
30%
_hostdomain
438.6
_hostname
173.8
domainname
168.3
CRAP 241.7
« FTP.pm ↑ Summary SMTP.pm »
1 # Net::Domain.pm
2 #
3 # Copyright (C) 1995-1998 Graham Barr. All rights reserved.
4 # Copyright (C) 2013-2014, 2020 Steve Hay. All rights reserved.
5 # This module is free software; you can redistribute it and/or modify it under
6 # the same terms as Perl itself, i.e. under the terms of either the GNU General
7 # Public License or the Artistic License, as specified in the F<LICENCE> file.
8  
9 package Net::Domain;
10  
11 2 ▶use 5.008001;
Subroutine BEGIN: called CC=1 SCAR=0.0
12  
13 2 ▶use strict;
Subroutine BEGIN: called CC=1 SCAR=0.0
14 2 ▶use warnings;
Subroutine BEGIN: called CC=1 SCAR=0.0
15  
16 2 ▶use Carp;
Subroutine BEGIN: called CC=1 SCAR=0.0
17 2 ▶use Exporter;
Subroutine BEGIN: called CC=1 SCAR=0.0
18 2 ▶use Net::Config;
Subroutine BEGIN: called CC=1 SCAR=0.0
19  
20 2 our @ISA = qw(Exporter);
21 2 our @EXPORT_OK = qw(hostname hostdomain hostfqdn domainname);
22 2 our $VERSION = "3.16";
23  
24 2 my ($host, $domain, $fqdn) = (undef, undef, undef);
25  
26 # Try every conceivable way to get hostname.
27  
28  
29 1 ▶sub _hostname {
Subroutine _hostname: called CC=21 SCAR=51.6
30  
31 # we already know it
32 1 ▶ return $host
Branch: 1 branch
BranchTrueFalseTotal
if defined $host 0 1 1
33 if (defined $host);
34  
35 1 ▶ if ($^O eq 'MSWin32') {
Branch: 3 branches
BranchTrueFalseTotal
if ($^O eq 'MSWin32') { } 0 1 1
elsif ($^O eq 'MacOS') { } 0 1 1
elsif ($^O eq 'VMS') { } 0 1 1
36 0 require Socket;
37 0 ▶ my ($name, $alias, $type, $len, @addr) = gethostbyname($ENV{'COMPUTERNAME'} || 'localhost');
Condition0%0/2
$ENV{'COMPUTERNAME'} || 'localhost'
l!l
00
MC/DC0%0/1
$ENV{'COMPUTERNAME'} || 'localhost'
$ENV{'COMPUTERNAME'}
Truth table0%0/2
A
A= $ENV{'COMPUTERNAME'}
Aresult
11
00
38 0 ▶ while (@addr) {
Branch: 1 branch
BranchTrueFalseTotal
if (@addr) 0 0 0
39 0 my $a = shift(@addr);
40 0 $host = gethostbyaddr($a, Socket::AF_INET());
41 0 ▶ last if defined $host;
Branch: 1 branch
BranchTrueFalseTotal
if defined $host 0 0 0
42 }
43 0 ▶ if (defined($host) && index($host, '.') > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $host and index($host, ".") > 0) 0 0 0
Condition0%0/3
defined $host and index($host, ".") > 0
!ll&&!rl&&r
000
MC/DC0%0/2
defined $host and index($host, ".") > 0
defined $host index($host, ".") > 0
Truth table0%0/3
A and B
A= defined $hostB= index($host, ".") > 0
ABresult
0X0
100
111
44 0 $fqdn = $host;
45 0 ($host, $domain) = $fqdn =~ /^([^.]+)\.(.*)$/;
46 }
47 0 return $host;
48 }
49 elsif ($^O eq 'MacOS') {
50 0 chomp($host = `hostname`);
51 }
52 elsif ($^O eq 'VMS') { ## multiple varieties of net s/w makes this hard
53 0 ▶ $host = $ENV{'UCX$INET_HOST'} if defined($ENV{'UCX$INET_HOST'});
Branch: 1 branch
BranchTrueFalseTotal
if defined $ENV{"UCX\$INET_HOST"} 0 0 0
54 0 ▶ $host = $ENV{'MULTINET_HOST_NAME'} if defined($ENV{'MULTINET_HOST_NAME'});
Branch: 1 branch
BranchTrueFalseTotal
if defined $ENV{"MULTINET_HOST_NAME"} 0 0 0
55 0 ▶ if (index($host, '.') > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (index($host, ".") > 0) 0 0 0
56 0 $fqdn = $host;
57 0 ($host, $domain) = $fqdn =~ /^([^.]+)\.(.*)$/;
58 }
59 0 return $host;
60 }
61 else {
62 1 local $SIG{'__DIE__'};
63  
64 # syscall is preferred since it avoids tainting problems
65 eval {
66 1 my $tmp = "\0" x 256; ## preload scalar
67 eval {
68 package main;
69 1 require "syscall.ph"; ## no critic (Modules::RequireBarewordIncludes)
70 0 defined(&main::SYS_gethostname);
71 }
72 1 ▶ || eval {
Condition33%2/6
(eval { do { package main; require 'syscall.ph'; defined &main::SYS_gethostname } } || eval { do { package main; require 'sys/syscall.ph'; defined &main::SYS_gethostname } }) && ($host = syscall(&main::SYS_gethostname, $tmp, 256) == 0 ? $tmp : undef)
!ll&&!rl&&r
100
eval { do { package main; require "syscall.ph"; defined &main::SYS_gethostname } } or eval { do { package main; require "sys/syscall.ph"; defined &main::SYS_gethostname } }
l!l&&r!l&&!r
001
MC/DC0%0/3
(eval { do { package main; require 'syscall.ph'; defined &main::SYS_gethostname } } || eval { do { package main; require 'sys/syscall.ph'; defined &main::SYS_gethostname } }) && ($host = syscall(&main::SYS_gethostname, $tmp, 256) == 0 ? $tmp : undef)
eval { do { package main; require "syscall.ph"; defined &main::SYS_gethostname } } eval { do { package main; require "sys/syscall.ph"; defined &main::SYS_gethostname } } ($host = syscall(&main::SYS_gethostname, $tmp, 256) == 0 ? $tmp : undef)
Truth table20%1/5
A or B && C
A= eval { do { package main; require "syscall.ph"; defined &main::SYS_gethostname } }B= eval { do { package main; require "sys/syscall.ph"; defined &main::SYS_gethostname } }C= ($host = syscall(&main::SYS_gethostname, $tmp, 256) == 0 ? $tmp : undef)
ABCresult
00X0
1X00
0100
1X11
0111
73 package main;
74 1 require "sys/syscall.ph"; ## no critic (Modules::RequireBarewordIncludes)
75 0 ▶ defined(&main::SYS_gethostname);
Branch: 1 branch
BranchTrueFalseTotal
syscall(&SYS_gethostname, $tmp, 256) == 0 ? : 0 0 0
76 }
77 and $host =
78 (syscall(&main::SYS_gethostname, $tmp, 256) == 0)
79 ? $tmp
80 : undef;
81 }
82  
83 # POSIX
84 || eval {
85 1 require POSIX;
86 1 $host = (POSIX::uname())[1];
87 }
88  
89 # trusty old hostname command
90 || eval {
91 0 chop($host = `(hostname) 2>/dev/null`); # BSD'ish
92 }
93  
94 # sysV/POSIX uname command (may truncate)
95 || eval {
96 0 chop($host = `uname -n 2>/dev/null`); ## SYSV'ish && POSIX'ish
97 }
98  
99 # Apollo pre-SR10
100 0 || eval { $host = (split(/[:. ]/, `/com/host`, 6))[0]; }
101  
102 0 ▶ || eval { $host = ""; };
Branch: 1 branch
BranchTrueFalseTotal
eval { do { my $tmp = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; eval { do { package main; require "syscall.ph"; defined &main::SYS_gethostname } } || eval { do { package main; require "sys/syscall.ph"; defined &main::SYS_gethostname } } and $host = syscall(&main::SYS_gethostname, $tmp, 256) == 0 ? $tmp : undef } } or eval { do { require POSIX; $host = (POSIX::uname())[1] } } or eval { do { chop($host = `(hostname) 2>/dev/null`) } } or eval { do { chop($host = `uname -n 2>/dev/null`) } } or eval { do { $host = (split(/[:. ]/, `/com/host`, 6))[0] } } or eval { do { $host = "" } } 1 0 1
Condition33%4/12
eval { do { my $tmp = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; eval { do { package main; require "syscall.ph"; defined &main::SYS_gethostname } } || eval { do { package main; require "sys/syscall.ph"; defined &main::SYS_gethostname } } and $host = syscall(&main::SYS_gethostname, $tmp, 256) == 0 ? $tmp : undef } } or eval { do { require POSIX; $host = (POSIX::uname())[1] } } or eval { do { chop($host = `(hostname) 2>/dev/null`) } } or eval { do { chop($host = `uname -n 2>/dev/null`) } } or eval { do { $host = (split(/[:. ]/, `/com/host`, 6))[0] } }
l!l&&r!l&&!r
100
eval { do { my $tmp = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; eval { do { package main; require "syscall.ph"; defined &main::SYS_gethostname } } || eval { do { package main; require "sys/syscall.ph"; defined &main::SYS_gethostname } } and $host = syscall(&main::SYS_gethostname, $tmp, 256) == 0 ? $tmp : undef } } or eval { do { require POSIX; $host = (POSIX::uname())[1] } } or eval { do { chop($host = `(hostname) 2>/dev/null`) } } or eval { do { chop($host = `uname -n 2>/dev/null`) } }
l!l&&r!l&&!r
100
eval { do { my $tmp = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; eval { do { package main; require "syscall.ph"; defined &main::SYS_gethostname } } || eval { do { package main; require "sys/syscall.ph"; defined &main::SYS_gethostname } } and $host = syscall(&main::SYS_gethostname, $tmp, 256) == 0 ? $tmp : undef } } or eval { do { require POSIX; $host = (POSIX::uname())[1] } } or eval { do { chop($host = `(hostname) 2>/dev/null`) } }
l!l&&r!l&&!r
100
eval { do { my $tmp = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; eval { do { package main; require "syscall.ph"; defined &main::SYS_gethostname } } || eval { do { package main; require "sys/syscall.ph"; defined &main::SYS_gethostname } } and $host = syscall(&main::SYS_gethostname, $tmp, 256) == 0 ? $tmp : undef } } or eval { do { require POSIX; $host = (POSIX::uname())[1] } }
l!l&&r!l&&!r
010
MC/DC0%0/5
eval { do { my $tmp = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; eval { do { package main; require "syscall.ph"; defined &main::SYS_gethostname } } || eval { do { package main; require "sys/syscall.ph"; defined &main::SYS_gethostname } } and $host = syscall(&main::SYS_gethostname, $tmp, 256) == 0 ? $tmp : undef } } or eval { do { require POSIX; $host = (POSIX::uname())[1] } } or eval { do { chop($host = `(hostname) 2>/dev/null`) } } or eval { do { chop($host = `uname -n 2>/dev/null`) } } or eval { do { $host = (split(/[:. ]/, `/com/host`, 6))[0] } }
eval { do { my $tmp = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; eval { do { package main; require "syscall.ph"; defined &main::SYS_gethostname } } || eval { do { package main; require "sys/syscall.ph"; defined &main::SYS_gethostname } } and $host = syscall(&main::SYS_gethostname, $tmp, 256) == 0 ? $tmp : undef } } eval { do { require POSIX; $host = (POSIX::uname())[1] } } eval { do { chop($host = `(hostname) 2>/dev/null`) } } eval { do { chop($host = `uname -n 2>/dev/null`) } } eval { do { $host = (split(/[:. ]/, `/com/host`, 6))[0] } }
Truth table16%1/6
A or B or C or D or E
A= eval { do { my $tmp = "\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0\0"; eval { do { package main; require "syscall.ph"; defined &main::SYS_gethostname } } || eval { do { package main; require "sys/syscall.ph"; defined &main::SYS_gethostname } } and $host = syscall(&main::SYS_gethostname, $tmp, 256) == 0 ? $tmp : undef } }B= eval { do { require POSIX; $host = (POSIX::uname())[1] } }C= eval { do { chop($host = `(hostname) 2>/dev/null`) } }D= eval { do { chop($host = `uname -n 2>/dev/null`) } }E= eval { do { $host = (split(/[:. ]/, `/com/host`, 6))[0] } }
ABCDEresult
1XXXX1
01XXX1
001XX1
0001X1
000011
000000
103 }
104  
105 # remove garbage
106 1 $host =~ s/[\0\r\n]+//go;
107 1 $host =~ s/(\A\.+|\.+\Z)//go;
108 1 $host =~ s/\.\.+/\./go;
109  
110 1 $host;
111 }
112  
113  
114 1 ▶sub _hostdomain {
Subroutine _hostdomain: called CC=27 SCAR=60.8
115  
116 # we already know it
117 1 ▶ return $domain
Branch: 1 branch
BranchTrueFalseTotal
if defined $domain 0 1 1
118 if (defined $domain);
119  
120 1 local $SIG{'__DIE__'};
121  
122 return $domain = $NetConfig{'inet_domain'}
123 1 ▶ if defined $NetConfig{'inet_domain'};
Branch: 1 branch
BranchTrueFalseTotal
if defined $Net::Domain::NetConfig{"inet_domain"} 0 1 1
124  
125 # try looking in /etc/resolv.conf
126 # putting this here and assuming that it is correct, eliminates
127 # calls to gethostbyname, and therefore DNS lookups. This helps
128 # those on dialup systems.
129  
130 1 local ($_);
131  
132 1 ▶ if (open(my $res, '<', "/etc/resolv.conf")) {
Branch: 1 branch
BranchTrueFalseTotal
if (open my $res, "<", "/etc/resolv.conf") 1 0 1
133 1 ▶ while (<$res>) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined($_ = readline $res)) 10 1 11
134 10 ▶ $domain = $1
Branch: 1 branch
BranchTrueFalseTotal
if /\A\s*(?:domain|search)\s+(\S+)/ 1 9 10
135 if (/\A\s*(?:domain|search)\s+(\S+)/);
136 }
137 1 close($res);
138  
139 1 ▶ return $domain
Branch: 1 branch
BranchTrueFalseTotal
if defined $domain 1 0 1
140 if (defined $domain);
141 }
142  
143 # just try hostname and system calls
144  
145 0 my $host = _hostname();
146 0 my (@hosts);
147  
148 0 @hosts = ($host, "localhost");
149  
150 0 ▶ unless (defined($host) && $host =~ /\./) {
Branch: 1 branch
BranchTrueFalseTotal
unless (defined $host and $host =~ /\./) 0 0 0
Condition0%0/3
defined $host and $host =~ /\./
!ll&&!rl&&r
000
MC/DC0%0/2
defined $host and $host =~ /\./
defined $host $host =~ /\./
Truth table0%0/3
A and B
A= defined $hostB= $host =~ /\./
ABresult
0X0
100
111
151 0 my $dom = undef;
152 0 eval {
153 0 my $tmp = "\0" x 256; ## preload scalar
154 eval {
155 package main;
156 0 require "syscall.ph"; ## no critic (Modules::RequireBarewordIncludes)
157 }
158 0 ▶ || eval {
Branch: 1 branch
BranchTrueFalseTotal
eval { do { package main; require "syscall.ph" } } || eval { do { package main; require "sys/syscall.ph" } } and $dom = syscall(&main::SYS_getdomainname, $tmp, 256) == 0 ? $tmp : undef 0 0 0
Condition0%0/3
eval { do { package main; require "syscall.ph" } } or eval { do { package main; require "sys/syscall.ph" } }
l!l&&r!l&&!r
000
MC/DC0%0/2
eval { do { package main; require "syscall.ph" } } or eval { do { package main; require "sys/syscall.ph" } }
eval { do { package main; require "syscall.ph" } } eval { do { package main; require "sys/syscall.ph" } }
Truth table0%0/3
A or B
A= eval { do { package main; require "syscall.ph" } }B= eval { do { package main; require "sys/syscall.ph" } }
ABresult
1X1
011
000
159 package main;
160 0 ▶ require "sys/syscall.ph"; ## no critic (Modules::RequireBarewordIncludes)
Branch: 1 branch
BranchTrueFalseTotal
syscall(&SYS_getdomainname, $tmp, 256) == 0 ? : 0 0 0
161 }
162 and $dom =
163 (syscall(&main::SYS_getdomainname, $tmp, 256) == 0)
164 ? $tmp
165 : undef;
166 };
167  
168 0 ▶ if ($^O eq 'VMS') {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq "VMS") 0 0 0
169 $dom ||= $ENV{'TCPIP$INET_DOMAIN'}
170 0 ▶ || $ENV{'UCX$INET_DOMAIN'};
Condition0%0/6
$dom ||= $ENV{"TCPIP\$INET_DOMAIN"} || $ENV{"UCX\$INET_DOMAIN"}
l!l&&r!l&&!r
000
$ENV{'TCPIP$INET_DOMAIN'} || $ENV{'UCX$INET_DOMAIN'}
l!l&&r!l&&!r
000
MC/DC0%0/3
$dom ||= $ENV{"TCPIP\$INET_DOMAIN"} || $ENV{"UCX\$INET_DOMAIN"}
$dom $ENV{'TCPIP$INET_DOMAIN'} $ENV{'UCX$INET_DOMAIN'}
Truth table0%0/4
A ||= B || C
A= $domB= $ENV{'TCPIP$INET_DOMAIN'}C= $ENV{'UCX$INET_DOMAIN'}
ABCresult
1XX1
01X1
0011
0000
171 }
172  
173 0 ▶ chop($dom = `domainname 2>/dev/null`)
Branch: 1 branch
BranchTrueFalseTotal
unless defined $dom or $^O =~ /^(?:cygwin|MSWin32|android)/ 0 0 0
Condition0%0/3
defined $dom or $^O =~ /^(?:cygwin|MSWin32|android)/
l!l&&r!l&&!r
000
MC/DC0%0/2
defined $dom or $^O =~ /^(?:cygwin|MSWin32|android)/
defined $dom $^O =~ /^(?:cygwin|MSWin32|android)/
Truth table0%0/3
A or B
A= defined $domB= $^O =~ /^(?:cygwin|MSWin32|android)/
ABresult
1X1
011
000
174 unless (defined $dom || $^O =~ /^(?:cygwin|MSWin32|android)/);
175  
176 0 ▶ if (defined $dom) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $dom) 0 0 0
177 0 my @h = ();
178 0 $dom =~ s/^\.+//;
179 0 ▶ while (length($dom)) {
Branch: 1 branch
BranchTrueFalseTotal
if (length $dom) 0 0 0
180 0 push(@h, "$host.$dom");
181 0 ▶ $dom =~ s/^[^.]+.+// or last;
Branch: 1 branch
BranchTrueFalseTotal
$dom =~ s/^[^.]+.+// or last 0 0 0
182 }
183 0 unshift(@hosts, @h);
184 }
185 }
186  
187 # Attempt to locate FQDN
188  
189 0 foreach (grep { defined $_ } @hosts) {
190 0 my @info = gethostbyname($_);
191  
192 0 ▶ next unless @info;
Branch: 1 branch
BranchTrueFalseTotal
unless @info 0 0 0
193  
194 # look at real name & aliases
195 0 foreach my $site ($info[0], split(/ /, $info[1])) {
196 0 ▶ if (rindex($site, ".") > 0) {
Branch: 1 branch
BranchTrueFalseTotal
if (rindex($site, ".") > 0) 0 0 0
197  
198 # Extract domain from FQDN
199  
200 0 ($domain = $site) =~ s/\A[^.]+\.//;
201 0 return $domain;
202 }
203 }
204 }
205  
206 # Look for environment variable
207  
208 0 ▶ $domain ||= $ENV{LOCALDOMAIN} || $ENV{DOMAIN};
Condition0%0/6
$domain ||= $ENV{"LOCALDOMAIN"} || $ENV{"DOMAIN"}
l!l&&r!l&&!r
000
$ENV{'LOCALDOMAIN'} || $ENV{'DOMAIN'}
l!l&&r!l&&!r
000
MC/DC0%0/3
$domain ||= $ENV{"LOCALDOMAIN"} || $ENV{"DOMAIN"}
$domain $ENV{'LOCALDOMAIN'} $ENV{'DOMAIN'}
Truth table0%0/4
A ||= B || C
A= $domainB= $ENV{'LOCALDOMAIN'}C= $ENV{'DOMAIN'}
ABCresult
1XX1
01X1
0011
0000
209  
210 0 ▶ if (defined $domain) {
Branch: 1 branch
BranchTrueFalseTotal
if (defined $domain) 0 0 0
211 0 $domain =~ s/[\r\n\0]+//g;
212 0 $domain =~ s/(\A\.+|\.+\Z)//g;
213 0 $domain =~ s/\.\.+/\./g;
214 }
215  
216 0 $domain;
217 }
218  
219  
220 3 ▶sub domainname {
Subroutine domainname: called CC=17 SCAR=51.3
Pod documented
221  
222 3 ▶ return $fqdn
Branch: 1 branch
BranchTrueFalseTotal
if defined $fqdn 2 1 3
223 if (defined $fqdn);
224  
225 1 _hostname();
226  
227 # *.local names are special on darwin. If we call gethostbyname below, it
228 # may hang while waiting for another, non-existent computer to respond.
229 1 ▶ if($^O eq 'darwin' && $host =~ /\.local$/) {
Branch: 1 branch
BranchTrueFalseTotal
if ($^O eq "darwin" and $host =~ /\.local$/) 0 1 1
Condition33%1/3
$^O eq "darwin" and $host =~ /\.local$/
!ll&&!rl&&r
100
MC/DC0%0/2
$^O eq "darwin" and $host =~ /\.local$/
$^O eq "darwin" $host =~ /\.local$/
Truth table33%1/3
A and B
A= $^O eq "darwin"B= $host =~ /\.local$/
ABresult
0X0
100
111
230 0 return $host;
231 }
232  
233 1 _hostdomain();
234  
235 # Assumption: If the host name does not contain a period
236 # and the domain name does, then assume that they are correct
237 # this helps to eliminate calls to gethostbyname, and therefore
238 # eliminate DNS lookups
239  
240 1 ▶ return $fqdn = $host . "." . $domain
Branch: 1 branch
BranchTrueFalseTotal
if defined $host and defined $domain and not $host =~ /\./ and $domain =~ /\./ 1 0 1
Condition33%3/9
defined $host and defined $domain and not $host =~ /\./ and $domain =~ /\./
!ll&&!rl&&r
001
defined $host and defined $domain and not $host =~ /\./
!ll&&!rl&&r
001
defined $host and defined $domain
!ll&&!rl&&r
001
MC/DC0%0/4
defined $host and defined $domain and not $host =~ /\./ and $domain =~ /\./
defined $host defined $domain not $host =~ /\./ $domain =~ /\./
Truth table20%1/5
A and B and not(C) and D
A= defined $hostB= defined $domainC= not $host =~ /\./D= $domain =~ /\./
ABCDresult
0XXX0
10XX0
110X0
11100
11111
241 if (defined $host
242 and defined $domain
243 and $host !~ /\./
244 and $domain =~ /\./);
245  
246 # For hosts that have no name, just an IP address
247 0 ▶ return $fqdn = $host if defined $host and $host =~ /^\d+(\.\d+){3}$/;
Branch: 1 branch
BranchTrueFalseTotal
if defined $host and $host =~ /^\d+(\.\d+){3}$/ 0 0 0
Condition0%0/3
defined $host and $host =~ /^\d+(\.\d+){3}$/
!ll&&!rl&&r
000
MC/DC0%0/2
defined $host and $host =~ /^\d+(\.\d+){3}$/
defined $host $host =~ /^\d+(\.\d+){3}$/
Truth table0%0/3
A and B
A= defined $hostB= $host =~ /^\d+(\.\d+){3}$/
ABresult
0X0
100
111
248  
249 0 ▶ my @host = defined $host ? split(/\./, $host) : ('localhost');
Branch: 1 branch
BranchTrueFalseTotal
defined $host ? : 0 0 0
250 0 ▶ my @domain = defined $domain ? split(/\./, $domain) : ();
Branch: 1 branch
BranchTrueFalseTotal
defined $domain ? : 0 0 0
251 0 my @fqdn = ();
252  
253 # Determine from @host & @domain the FQDN
254  
255 0 my @d = @domain;
256  
257 LOOP:
258 0 while (1) {
259 0 my @h = @host;
260 0 ▶ while (@h) {
Branch: 1 branch
BranchTrueFalseTotal
if (@h) 0 0 0
261 0 my $tmp = join(".", @h, @d);
262 0 ▶ if ((gethostbyname($tmp))[0]) {
Branch: 1 branch
BranchTrueFalseTotal
if ((gethostbyname $tmp)[0]) 0 0 0
263 0 @fqdn = (@h, @d);
264 0 $fqdn = $tmp;
265 0 last LOOP;
266 }
267 0 pop @h;
268 }
269 0 ▶ last unless shift @d;
Branch: 1 branch
BranchTrueFalseTotal
unless shift @d 0 0 0
270 }
271  
272 0 ▶ if (@fqdn) {
Branch: 1 branch
BranchTrueFalseTotal
if (@fqdn) { } 0 0 0
273 0 $host = shift @fqdn;
274 0 ▶ until ((gethostbyname($host))[0]) {
Branch: 1 branch
BranchTrueFalseTotal
unless ((gethostbyname $host)[0]) 0 0 0
275 0 $host .= "." . shift @fqdn;
276 }
277 0 $domain = join(".", @fqdn);
278 }
279 else {
280 0 undef $host;
281 0 undef $domain;
282 0 undef $fqdn;
283 }
284  
285 0 $fqdn;
286 }
287  
288  
289 1 ▶sub hostfqdn { domainname() }
Subroutine hostfqdn: called CC=1 SCAR=0.0
Pod documented
290  
291  
292 5 ▶sub hostname {
Subroutine hostname: called CC=2 SCAR=7.2
Pod documented
293 5 ▶ domainname()
Branch: 1 branch
BranchTrueFalseTotal
unless defined $host 0 5 5
294 unless (defined $host);
295 5 return $host;
296 }
297  
298  
299 5 ▶sub hostdomain {
Subroutine hostdomain: called CC=2 SCAR=7.2
Pod documented
300 5 ▶ domainname()
Branch: 1 branch
BranchTrueFalseTotal
unless defined $domain 0 5 5
301 unless (defined $domain);
302 5 return $domain;
303 }
304  
305 2 1; # Keep require happy
306  
307 __END__
« FTP.pm ↑ Summary SMTP.pm »