in reply to Getting what I seem to believe are error with inet_ntoa(inet_aton())
Welcome to the Monastery, mattp341!
What's happening is you're receiving an undefined/null value from inet_aton() when you mistype a hostname, and that's what inet_ntoa() is complaining about.
You should check the return from inet_aton() before sending it into inet_ntoa(). Here's a very rough example. It'll ask the user for a hostname until inet_aton() returns something useful:
my $addr; while (! $addr){ print "enter a damned FQDN: "; my $input = <STDIN>; chomp $input; $addr = inet_aton($input); } my $ip = inet_ntoa($addr);
You could also just terminate the application if a hostname is mistyped instead of looping and re-asking for input:
my $addr = inet_aton($input); die "invalid hostname specified\n" if ! $addr; my $ip = inet_ntoa($addr); ...
|
|---|
| Replies are listed 'Best First'. | |
|---|---|
|
Re^2: Getting what I seem to believe are error with inet_ntoa(inet_aton())
by mattp341 (Initiate) on Jan 07, 2017 at 06:09 UTC |