package ping;

use warnings;
use strict;

use Net::Ping;
use Data::Dump qw/dump/;
use Time::HiRes;
use client;

sub host {
	Net::Ping->new->ping( shift, 0.7 );
}

sub fping {
	my $p = Net::Ping->new('syn', 0.3);
	$p->hires;

	my $status;
	my %syn;

	foreach my $host ( @_ ) {
		my ($ret,$nslookup_duration,$ip) = $p->ping($host);

		if ( $ret ) {
			$syn{$host} = $ip;
#			$status->{dns}->{$ip} = $nslookup_duration * 1000;
		} else {
			push @{ $status->{address_not_found} }, $host;
		}
	}

	while (my ($host,$rtt,$ip) = $p->ack) {
		$status->{$ip}->{rtt} = $rtt * 1000; # ms
		warn "# $host $rtt $ip\n";
		client::conf( $ip => 'hostname', default => $host ) if $host ne $ip;
	}

	warn dump($status);

	return $status;

}

1;
