1#!/usr/bin/perl 2 3use v5.14; 4use warnings; 5 6use Test::More; 7 8use IO::Socket::IP; 9use Socket qw( SOCK_STREAM AF_INET ); 10 11# Compatibility test for 12# IO::Socket::INET->new( Blocking => 0 ) still creates a defined filehandle 13 14{ 15 my $sock = IO::Socket::IP->new( Family => AF_INET ); 16 my $save_exc = $IO::Socket::errstr; 17 ok( defined $sock, 'Constructor yields handle for Family => AF_INET' ) or 18 diag( "Exception was $save_exc" ); 19 20 ok( defined $sock->fileno, '$sock->fileno for Family => AF_INET' ); 21 is( $sock->sockdomain, AF_INET, '$sock->sockdomain for Family => AF_INET' ); 22 is( $sock->socktype, SOCK_STREAM, '$sock->socktype for Family => AF_INET' ); 23} 24 25SKIP: { 26 my $AF_INET6 = eval { require Socket and Socket::AF_INET6() } or 27 skip "No AF_INET6", 4; 28 29 eval { IO::Socket::IP->new( LocalHost => "::1" ) } or 30 skip "Unable to bind to ::1", 4; 31 32 my $sock = IO::Socket::IP->new( Family => $AF_INET6 ); 33 my $save_exc = $IO::Socket::errstr; 34 ok( defined $sock, 'Constructor yields handle for Family => AF_INET6' ) or 35 diag( "Exception was $save_exc" ); 36 37 ok( defined $sock->fileno, '$sock->fileno for Family => AF_INET6' ); 38 is( $sock->sockdomain, $AF_INET6, '$sock->sockdomain for Family => AF_INET6' ); 39 is( $sock->socktype, SOCK_STREAM, '$sock->socktype for Family => AF_INET6' ); 40} 41 42# Lack of even a Family hint - _a_ socket is created but we don't guarantee 43# what family 44{ 45 my $sock = IO::Socket::IP->new( Type => SOCK_STREAM ); 46 my $save_exc = $IO::Socket::errstr; 47 ok( defined $sock, 'Constructor yields handle for Type => SOCK_STREAM' ) or 48 diag( "Exception was $save_exc" ); 49 50 ok( defined $sock->fileno, '$sock->fileno for Type => SOCK_STREAM' ); 51 is( $sock->socktype, SOCK_STREAM, '$sock->socktype for Type => SOCK_STREAM' ); 52} 53 54done_testing; 55