#!/usr/bin/perl use Net::Radius::Dictionary; use Net::Radius::Packet (); use Socket; . . . sub build_radius_packet { my (%attribute) = @_; my $packet = Net::Radius::Packet->new($CONFIG->{'dictionary'}); if (defined $packet) { $packet->set_code('Accounting-Request'); $packet->set_identifier(inet_ntoa(inet_aton($CONFIG->{'hostname'}))); $packet->set_authenticator(undef); $packet->set_attr($_, $attribute{$_}) foreach sort keys %attribute; $packet->dump if $CONFIG->{'debug'}; } return $packet; } sub send_radius_packet { my ($packet) = @_; my $response; return undef unless socket(SOCK_UDP, PF_INET, SOCK_DGRAM, getprotobyname('udp')); my $data = Net::Radius::Packet::auth_resp($packet->pack, $CONFIG->{'secret'}); for (1..$CONFIG->{'retry'}) { send(SOCK_UDP, $data, 0, $remote_addr); sleep 1; vec(my $rbit, fileno(SOCK_UDP), 1) = 1; vec(my $wbit, fileno(SOCK_UDP), 1) = 1; $response = select($rbit, $wbit, ($rbit | $wbit), $CONFIG->{'timeout'}); last if $response > 1; } close(SOCK_UDP); return $response; }