itry to fix outgoing IPV6 connects
[spider.git] / perl / Msg.pm
index 531bff7336fb969f19cf581f9d7b5f41f24c4a7d..6805e008a770368b33e801c127fc721fc51187bf 100644 (file)
@@ -193,14 +193,19 @@ sub pid_gone
        }
 }
 
+sub ax25
+{
+       my $conn = shift;
+       return $conn->{csort} eq 'ax25';
+}
+
 sub peerhost
 {
-       my $self = shift;
-       my $ip;
-       unless ($self->{peerhost}) {
-               $self->{peerhost} = $self->{sock}->peerhost;
-       }
-       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};
 }
 
 #-----------------------------------------------------------------
@@ -217,22 +222,27 @@ sub connect {
        $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);
+       } else {
+               # Create a new internet socket
+               my $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