This is a live mirror of the Perl 5 development currently hosted at https://github.com/perl/perl5
Upgrade Socket from 2.002 to 2.003
[perl5.git] / cpan / Socket / t / ip_mreq.t
CommitLineData
3be135d8
TC
1use strict;
2use warnings;
3use Test::More;
4
5use Socket qw(
6 INADDR_ANY
7 pack_ip_mreq unpack_ip_mreq
d4ada64a 8 pack_ip_mreq_source unpack_ip_mreq_source
3be135d8
TC
9);
10
11# Check that pack/unpack_ip_mreq either croak with "Not implemented", or
12# roundtrip as identity
13
14my $packed;
15eval {
16 $packed = pack_ip_mreq "\xe0\0\0\1", INADDR_ANY;
17};
18if( !defined $packed ) {
19 plan skip_all => "No pack_ip_mreq" if $@ =~ m/ not implemented /;
20 die $@;
21}
22
d4ada64a 23plan tests => 6;
3be135d8
TC
24
25my @unpacked = unpack_ip_mreq $packed;
26
27is( $unpacked[0], "\xe0\0\0\1", 'unpack_ip_mreq multiaddr' );
28is( $unpacked[1], INADDR_ANY, 'unpack_ip_mreq interface' );
29
30is( (unpack_ip_mreq pack_ip_mreq "\xe0\0\0\1")[1], INADDR_ANY, 'pack_ip_mreq interface defaults to INADDR_ANY' );
d4ada64a
SH
31
32SKIP: {
33 my $mreq;
34 skip 3, "No pack_ip_mreq_source" unless defined eval { $mreq = pack_ip_mreq_source "\xe0\0\0\2", "\x0a\0\0\1", INADDR_ANY };
35
36 @unpacked = unpack_ip_mreq_source $mreq;
37
38 is( $unpacked[0], "\xe0\0\0\2", 'unpack_ip_mreq_source multiaddr' );
39 is( $unpacked[1], "\x0a\0\0\1", 'unpack_ip_mreq_source source' );
40 is( $unpacked[2], INADDR_ANY, 'unpack_ip_mreq_source interface' );
41}