Subject: | Reimplement using core Socket |
FYI, the core Socket module now contains (almost [*]) all the constants
and structure functions needed by IO::Socket::Multicast6.
Find attached a patch that drops the Socket6 and Socket::Multicast6
dependencies and instead uses only Socket 2.002.
[*]: Note this isn't finished yet, because currently Socket still
lacks the source group membership constants and structure functions. I
am in the process of adding these now.
Since Socket itself is a (dual-life) core module, this should reduce the
amount of out-of-core dependencies, especially XS ones, in your module.
Thanks.
--
Paul Evans
Subject: | use-core-Socket.patch |
=== modified file 'Build.PL'
--- Build.PL 2012-06-07 10:57:42 +0000
+++ Build.PL 2012-06-07 11:15:07 +0000
@@ -23,11 +23,9 @@
},
requires => {
'perl' => '5.6.1',
- 'Socket' => 0,
+ 'Socket' => '2.002',
'Test::More' => 0,
- 'Socket6' => 0.19,
'IO::Interface' => 1.01,
- 'Socket::Multicast6' => '0.01',
'IO::Socket::INET6' => '2.51',
},
);
=== modified file 'lib/IO/Socket/Multicast6.pm'
--- lib/IO/Socket/Multicast6.pm 2012-06-07 10:57:42 +0000
+++ lib/IO/Socket/Multicast6.pm 2012-06-07 11:15:07 +0000
@@ -5,9 +5,14 @@
use IO::Socket::INET6;
use IO::Interface::Simple;
-use Socket::Multicast6 qw/ :all /;
-use Socket;
-use Socket6;
+use Socket 2.002 qw(
+ AF_INET IPPROTO_IP IP_ADD_MEMBERSHIP IP_DROP_MEMBERSHIP
+ AF_INET6 IPPROTO_IPV6 IPV6_ADD_MEMBERSHIP IPV6_DROP_MEMBERSHIP
+ IP_MULTICAST_TTL IP_MULTICAST_LOOP IP_MULTICAST_IF
+ IPV6_MULTICAST_HOPS IPV6_MULTICAST_LOOP IPV6_MULTICAST_IF
+ inet_pton inet_ntop
+ pack_ip_mreq pack_ipv6_mreq
+);
use Carp 'croak';
@@ -53,8 +58,8 @@
my $ipv6_mreq = pack_ipv6_mreq( inet_pton( AF_INET6, $group ),
$if_index );
- setsockopt($sock, IPPROTO_IPV6, IPV6_JOIN_GROUP, $ipv6_mreq )
- or croak "Could not set IPV6_JOIN_GROUP socket option: $!";
+ setsockopt($sock, IPPROTO_IPV6, IPV6_ADD_MEMBERSHIP, $ipv6_mreq )
+ or croak "Could not set IPV6_ADD_MEMBERSHIP socket option: $!";
} else {
croak("mcast_add failed, unsupported socket family." );
}
@@ -69,14 +74,16 @@
my $source = shift || croak 'usage: $sock->mcast_add_source($mcast_addr, $source_addr [,$interface])';
my $interface = shift;
+ defined Socket::IP_ADD_SOURCE_MEMBERSHIP() or croak 'IP_ADD_SOURCE_MEMBERSHIP unsupported';
+
if ($sock->sockdomain() == AF_INET) {
my $if_addr = _get_if_ipv4addr($interface);
- my $ip_mreq = pack_ip_mreq_source(
+ my $ip_mreq = Socket::pack_ip_mreq_source(
inet_pton( AF_INET, $group ),
inet_pton( AF_INET, $source ),
inet_pton( AF_INET, $if_addr ) );
- setsockopt($sock, IPPROTO_IP, IP_ADD_SOURCE_MEMBERSHIP, $ip_mreq )
+ setsockopt($sock, IPPROTO_IP, Socket::IP_ADD_SOURCE_MEMBERSHIP(), $ip_mreq )
or croak "Could not set IP_ADD_SOURCE_MEMBERSHIP socket option: $!";
} elsif ($sock->sockdomain() == AF_INET6) {
croak("mcast_add_source failed, IPv6 is currently unsupported." );
@@ -106,8 +113,8 @@
my $ipv6_mreq = pack_ipv6_mreq( inet_pton( AF_INET6, $group ),
$if_index );
- setsockopt($sock, IPPROTO_IPV6, IPV6_LEAVE_GROUP, $ipv6_mreq )
- or croak "Could not set IPV6_LEAVE_GROUP socket option: $!";
+ setsockopt($sock, IPPROTO_IPV6, IPV6_DROP_MEMBERSHIP, $ipv6_mreq )
+ or croak "Could not set IPV6_DROP_MEMBERSHIP socket option: $!";
} else {
croak("mcast_add failed, unsupported socket family." );
}
@@ -352,10 +359,9 @@
This module depends on a number of other modules:
- Socket6 version 0.19 or higher.
+ Socket 2.002 or higher.
IO::Socket::INET6 version 2.51 or higher.
IO::Interface version 1.01 or higher.
- Socket::Multicast6 0.01 or higher.
Your operating system must have IPv6 and Multicast support.
=== modified file 't/35mcastsend.t'
--- t/35mcastsend.t 2012-06-07 10:57:42 +0000
+++ t/35mcastsend.t 2012-06-07 11:15:07 +0000
@@ -3,8 +3,7 @@
#
use strict;
-use Socket6 qw/ inet_pton pack_sockaddr_in6/;
-use Socket qw/ pack_sockaddr_in /;
+use Socket qw/ pack_sockaddr_in inet_pton pack_sockaddr_in6 /;
use Test::More tests => 11;