}
}
+sub ax25
+{
+ my $conn = shift;
+ return $conn->{csort} eq 'ax25';
+}
+
sub peerhost
{
- my $self = shift;
- return $self->{peerhost};
+ my $conn = shift;
+ $conn->{peerhost} ||= 'ax25' if $conn->ax25;
+ $conn->{peerhost} ||= $conn->{sock}->peerhost if $conn->{sock} && $conn->{sock}->isa('IO::Socket::INET');
+ $conn->{peerhost} ||= 'UNKNOWN';
+ return $conn->{peerhost};
}
#-----------------------------------------------------------------
$conn->{peerport} = $to_port;
$conn->{sort} = 'Outgoing';
- # Create a new internet socket
- my $sock = $io_socket->new();
- return undef unless $sock;
-
- my $proto = getprotobyname('tcp');
- $sock->socket(AF_INET, SOCK_STREAM, $proto) or return undef;
-
- blocking($sock, 0);
- $conn->{blocking} = 0;
+ my $sock;
+ if ($blocking_supported) {
+ $sock = $io_socket->new(PeerAddr => $to_host, PeerPort => $to_port, Proto => 'tcp', Blocking =>0) or return undef;
+ } else {
+ # Create a new internet socket
+ $sock = $io_socket->new();
+ return undef unless $sock;
- # does the host resolve?
- my $ip = gethostbyname($to_host);
- return undef unless $ip;
-
- my $r = connect($sock, pack_sockaddr_in($to_port, $ip));
- return undef unless $r || _err_will_block($!);
+ my $proto = getprotobyname('tcp');
+ $sock->socket(AF_INET, SOCK_STREAM, $proto) or return undef;
+
+ blocking($sock, 0);
+ $conn->{blocking} = 0;
+
+ # does the host resolve?
+ my $ip = gethostbyname($to_host);
+ return undef unless $ip;
+
+ my $r = connect($sock, pack_sockaddr_in($to_port, $ip));
+ return undef unless $r || _err_will_block($!);
+ }
$conn->{sock} = $sock;
$conn->{peerhost} = $sock->peerhost; # for consistency
if (defined($sock)) {
set_event_handler ($sock, read => undef, write => undef, error => undef);
- shutdown($sock, 3);
+ shutdown($sock, 2);
close($sock);
}