Skip to content

Commit

Permalink
fix: add human-readable error when nc is not installed on the host
Browse files Browse the repository at this point in the history
Signed-off-by: Kanishk Pachauri <[email protected]>
  • Loading branch information
Mr-Sunglasses committed Oct 18, 2024
1 parent 121b728 commit 6b1c7a0
Showing 1 changed file with 16 additions and 0 deletions.
16 changes: 16 additions & 0 deletions hack/test-port-forwarding.pl
Original file line number Diff line number Diff line change
Expand Up @@ -20,8 +20,24 @@
use Socket qw(inet_ntoa);
use Sys::Hostname qw(hostname);

# check for nc
sub check_netcat_installed {
my $nc_path = `which nc 2>/dev/null`;
chomp $nc_path;
unless ($nc_path) {
die "Error: 'nc' (netcat) is not installed on the host system.\n" .
"Please install netcat to run this test script:\n" .
" - On macOS: brew install netcat\n" .
" - On Ubuntu/Debian: sudo apt-get install netcat\n" .
" - On RHEL/CentOS: sudo yum install nmap-ncat\n";
}
}

my $instance = shift;

# Check for netcat before proceeding
check_netcat_installed() unless -f $instance;

my $addr = scalar gethostbyname(hostname());
# If hostname address cannot be determines, use localhost to trigger fallback to system_profiler lookup
my $ipv4 = length $addr ? inet_ntoa($addr) : "127.0.0.1";
Expand Down

0 comments on commit 6b1c7a0

Please sign in to comment.