@@ -1,5 +1,18 @@
Revision history for Perl extension Net::Write.
+1.08 Fri Jan 23 07:53:16 CET 2015
+ - bugfix: on setting AF_INET6(), and makes Socket6 module optional
+ => thanks to Vince
+ - update: copyright notice
+ - update: Kwalitee
+
+1.07 Sun Sep 2 18:42:02 CEST 2012
+ - bugfix: returns true when _check() is ok
+
+1.06 Sat Sep 1 12:45:09 CEST 2012
+ - update: better error handling scheme
+ - update: copyright notice
+
1.05 Wed Jun 10 20:37:44 CEST 2009
- bugfix: removed a warning on AF_INET6 constant declaration
- update: copyright notice
@@ -17,4 +17,5 @@ README
t/01-pod-coverage.t
t/01-test-pod.t
t/01-use.t
-META.yml Module meta-data (added by MakeMaker)
+META.yml
+META.json
@@ -0,0 +1,55 @@
+{
+ "abstract" : "a portable interface to open and send raw data to network",
+ "author" : [
+ "GomoR <gomor_at_cpan.org>"
+ ],
+ "dynamic_config" : 1,
+ "generated_by" : "Module::Build version 0.421",
+ "license" : [
+ "artistic_1"
+ ],
+ "meta-spec" : {
+ "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
+ "version" : "2"
+ },
+ "name" : "Net-Write",
+ "prereqs" : {
+ "configure" : {
+ "requires" : {
+ "Module::Build" : "0"
+ }
+ },
+ "runtime" : {
+ "requires" : {
+ "Class::Gomor" : "0",
+ "Net::Pcap" : "0.12",
+ "perl" : "v5.6.1"
+ }
+ }
+ },
+ "provides" : {
+ "Net::Write" : {
+ "file" : "lib/Net/Write.pm",
+ "version" : "1.08"
+ },
+ "Net::Write::Layer" : {
+ "file" : "lib/Net/Write/Layer.pm"
+ },
+ "Net::Write::Layer2" : {
+ "file" : "lib/Net/Write/Layer2.pm"
+ },
+ "Net::Write::Layer3" : {
+ "file" : "lib/Net/Write/Layer3.pm"
+ },
+ "Net::Write::Layer4" : {
+ "file" : "lib/Net/Write/Layer4.pm"
+ }
+ },
+ "release_status" : "stable",
+ "resources" : {
+ "license" : [
+ "http://opensource.org/licenses/artistic-license.php"
+ ]
+ },
+ "version" : "1.08"
+}
@@ -1,16 +1,33 @@
---- #YAML:1.0
-name: Net-Write
-version: 1.05
-abstract: a portable interface to open and send raw data to network
-license: artistic
-author:
- - GomoR <gomor-cpan_at_gomor.org>
-generated_by: ExtUtils::MakeMaker version 6.42
-distribution_type: module
-requires:
- Class::Gomor: 0
- Net::Pcap: 0.12
- Socket6: 0
+---
+abstract: 'a portable interface to open and send raw data to network'
+author:
+ - 'GomoR <gomor_at_cpan.org>'
+build_requires: {}
+configure_requires:
+ Module::Build: '0'
+dynamic_config: 1
+generated_by: 'Module::Build version 0.421, CPAN::Meta::Converter version 2.143240'
+license: artistic
meta-spec:
- url: http://module-build.sourceforge.net/META-spec-v1.3.html
- version: 1.3
+ url: http://module-build.sourceforge.net/META-spec-v1.4.html
+ version: '1.4'
+name: Net-Write
+provides:
+ Net::Write:
+ file: lib/Net/Write.pm
+ version: '1.08'
+ Net::Write::Layer:
+ file: lib/Net/Write/Layer.pm
+ Net::Write::Layer2:
+ file: lib/Net/Write/Layer2.pm
+ Net::Write::Layer3:
+ file: lib/Net/Write/Layer3.pm
+ Net::Write::Layer4:
+ file: lib/Net/Write/Layer4.pm
+requires:
+ Class::Gomor: '0'
+ Net::Pcap: '0.12'
+ perl: v5.6.1
+resources:
+ license: http://opensource.org/licenses/artistic-license.php
+version: '1.08'
@@ -1,17 +1,27 @@
#
-# $Id: Makefile.PL 1636 2009-06-10 18:38:24Z gomor $
+# $Id: Makefile.PL 2005 2015-01-23 06:56:13Z gomor $
#
use ExtUtils::MakeMaker;
+my @conditions_modules = ();
+eval {
+ require Socket;
+ Socket->import(qw(AF_INET6 getaddrinfo));
+};
+if ($@) {
+ @conditions_modules = ( Socket6 => 0 );
+}
+
WriteMakefile(
- NAME => 'Net::Write',
- LICENSE => 'artistic',
- VERSION_FROM => 'lib/Net/Write.pm',
+ NAME => 'Net::Write',
+ LICENSE => 'artistic',
+ VERSION_FROM => 'lib/Net/Write.pm',
ABSTRACT_FROM => 'lib/Net/Write.pm',
- PREREQ_PM => {
+ AUTHOR => 'GomoR <gomor_at_cpan.org>',
+ MIN_PERL_VERSION => '5.6.1',
+ PREREQ_PM => {
Class::Gomor => 0,
- Socket6 => 0,
- Net::Pcap => '0.12',
+ Net::Pcap => '0.12',
+ @conditions_modules,
},
- AUTHOR => 'GomoR <gomor-cpan_at_gomor.org>',
);
@@ -34,5 +34,5 @@ COPYRIGHT AND LICENSE
You may distribute this module under the terms of the Artistic license.
See LICENSE.Artistic file in the source distribution archive.
-Copyright (c) 2006-2009, Patrice <GomoR> Auffret
+Copyright (c) 2006-2015, Patrice <GomoR> Auffret
@@ -1,13 +1,11 @@
#
-# $Id: Layer.pm 1636 2009-06-10 18:38:24Z gomor $
+# $Id: Layer.pm 2005 2015-01-23 06:56:13Z gomor $
#
package Net::Write::Layer;
use strict;
use warnings;
-require Exporter;
-require Class::Gomor::Array;
-our @ISA = qw(Exporter Class::Gomor::Array);
+use base qw(Exporter Class::Gomor::Array);
our @AS = qw(
dev
dst
@@ -83,18 +81,24 @@ sub _setIpHdrInclConstant {
eval "use constant NW_IP_HDRINCL => $val;";
}
-sub _setAfinet6Constant {
- require Socket6;
- require Socket;
- my $val = 0;
- if (defined(&Socket6::AF_INET6)) {
- $val = &Socket6::AF_INET6;
- }
- elsif (defined(&Socket::AF_INET6)) {
- $val = &Socket::AF_INET6;
- }
- eval "use constant NW_AF_INET6 => $val;";
-}
+#
+# ACF - This could result in NW_AF_INET6 => 0 if neither
+# Socket6::AF_INET6 nor Socket::AF_INET6 is defined. My change
+# doesn't preserve that, but it isn't clear that was an intended or
+# useful feature.
+#
+#sub _setAfinet6Constant {
+# require Socket6;
+# require Socket;
+# my $val = 0;
+# if (defined(&Socket6::AF_INET6)) {
+# $val = &Socket6::AF_INET6;
+# }
+# elsif (defined(&Socket::AF_INET6)) {
+# $val = &Socket::AF_INET6;
+# }
+# eval "use constant NW_AF_INET6 => $val;";
+#}
BEGIN {
my $osname = {
@@ -102,23 +106,48 @@ BEGIN {
MSWin32 => \&_checkWin32,
};
- *_check = $osname->{$^O} || \&_checkOther;
+ {
+ no strict 'refs';
+ *{ __PACKAGE__ . "::_check" } = $osname->{$^O} || \&_checkOther;
+ }
_setIpProtoIpConstant();
_setIpProtoIpv6Constant();
_setIpProtoRawConstant();
_setIpHdrInclConstant();
- _setAfinet6Constant();
+ #_setAfinet6Constant();
+}
+
+use Socket qw(:DEFAULT AF_INET);
+BEGIN {
+ # imports that may or may not be in Socket.
+ my @imports = (qw(AF_INET6 getaddrinfo));
+ my @socket6_imports;
+
+ # This might be overkill, but I'm not certain that all these imports
+ # were added to Socket at the same time.
+ for my $import (@imports) {
+ eval { Socket->import($import); };
+ if ($@) {
+ push @socket6_imports, $import;
+ }
+ }
+
+ if (@socket6_imports) {
+
+ # something we want wasn't found in Socket time to try Socket6
+ eval { require Socket6 };
+ die $@ if $@;
+ Socket6->import(@socket6_imports);
+ }
}
no strict 'vars';
-use Socket;
-use Socket6 qw(getaddrinfo);
use IO::Socket;
use Net::Pcap;
-use Carp;
use constant NW_AF_INET => AF_INET();
+use constant NW_AF_INET6 => AF_INET6();
use constant NW_AF_UNSPEC => AF_UNSPEC();
use constant NW_IPPROTO_ICMPv4 => 1;
@@ -146,41 +175,64 @@ our @EXPORT_OK = (
@{$EXPORT_TAGS{constants}},
);
-sub _checkWin32 { }
+sub _checkWin32 {
+ return 1;
+}
sub _checkOther {
- croak("Must be EUID 0 (or equivalent) to open a device for writing.\n")
- if $>;
+ if ($>) {
+ print STDERR "[-] Must be EUID 0 (or equivalent) to open a device for ".
+ "writing.\n";
+ return;
+ }
+
+ return 1;
}
-sub new { _check(); shift->SUPER::new(@_) }
+sub new {
+ my $self = shift->SUPER::new(
+ @_,
+ );
+
+ _check() or return;
+
+ return $self;
+}
+
+sub _croak {
+ my ($msg) = @_;
+ print STDERR "[-] $msg\n";
+ return;
+}
sub open {
my $self = shift;
my ($hdrincl) = @_;
my @res = getaddrinfo($self->[$__dst], 0, $self->[$__family], SOCK_STREAM)
- or croak("@{[(caller(0))[3]]}: getaddrinfo: $!\n");
+ or return _croak("@{[(caller(0))[3]]}: getaddrinfo: $!");
my ($family, $saddr) = @res[0, 3] if @res >= 5;
$self->[$___sockaddr] = $saddr;
socket(my $s, $family, SOCK_RAW, $self->[$__protocol])
- or croak("@{[(caller(0))[3]]}: socket: $!\n");
+ or return _croak("@{[(caller(0))[3]]}: socket: $!");
- my $fd = fileno($s) or croak("@{[(caller(0))[3]]}: fileno: $!\n");
+ my $fd = fileno($s)
+ or return _croak("@{[(caller(0))[3]]}: fileno: $!");
if ($hdrincl) {
$self->_setIpHdrincl($s, $self->[$__family])
- or croak("@{[(caller(0))[3]]}: setsockopt: $!\n");
+ or return _croak("@{[(caller(0))[3]]}: setsockopt: $!");
}
my $io = IO::Socket->new;
- $io->fdopen($fd, 'w') or croak("@{[(caller(0))[3]]}: fdopen: $!\n");
+ $io->fdopen($fd, 'w')
+ or return _croak("@{[(caller(0))[3]]}: fdopen: $!");
$self->[$___io] = $io;
- 1;
+ return 1;
}
sub send {
@@ -199,13 +251,13 @@ sub send {
$self->cgDebugPrint(2, "host is down");
last;
}
- carp("@{[(caller(0))[3]]}: $!\n");
- return undef;
+ print STDERR "[!] @{[(caller(0))[3]]}: $!\n";
+ return;
}
last;
}
- 1;
+ return 1;
}
sub close { shift->_io->close }
@@ -256,11 +308,11 @@ Adresse family to use (NW_AF_INET, NW_AF_INET6).
=item B<new>
-Object constructor.
+Object constructor. Returns undef on error.
=item B<open>
-Open the descriptor, when you are ready to B<send>.
+Open the descriptor, when you are ready to B<send>. Returns undef on error.
=item B<send> (scalar)
@@ -316,7 +368,7 @@ Patrice E<lt>GomoRE<gt> Auffret
=head1 COPYRIGHT AND LICENSE
-Copyright (c) 2006-2009, Patrice E<lt>GomoRE<gt> Auffret
+Copyright (c) 2006-2015, Patrice E<lt>GomoRE<gt> Auffret
You may distribute this module under the terms of the Artistic license.
See LICENSE.Artistic file in the source distribution archive.
@@ -1,26 +1,28 @@
#
-# $Id: Layer2.pm 1636 2009-06-10 18:38:24Z gomor $
+# $Id: Layer2.pm 2005 2015-01-23 06:56:13Z gomor $
#
package Net::Write::Layer2;
use strict;
use warnings;
-require Net::Write::Layer;
-our @ISA = qw(Net::Write::Layer);
+use base qw(Net::Write::Layer);
__PACKAGE__->cgBuildIndices;
no strict 'vars';
-use Carp;
use Net::Pcap;
sub new {
- my $self = shift->SUPER::new(@_);
+ my $self = shift->SUPER::new(
+ @_,
+ ) or return;
- croak("@{[(caller(0))[3]]}: you must pass `dev' parameter\n")
- unless $self->[$__dev];
+ if (! $self->[$__dev]) {
+ print STDERR "[-] @{[(caller(0))[3]]}: you must pass `dev' parameter\n";
+ return;
+ }
- $self;
+ return $self;
}
sub open {
@@ -35,13 +37,14 @@ sub open {
\$err,
);
unless ($pd) {
- croak("@{[(caller(0))[3]]}: Net::Pcap::open_live: @{[$self->dev]}: ".
- "$err\n");
+ print STDERR "[-] @{[(caller(0))[3]]}: Net::Pcap::open_live: ".
+ "@{[$self->dev]}: $err\n";
+ return;
}
$self->[$___io] = $pd;
- 1;
+ return 1;
}
sub send {
@@ -59,13 +62,14 @@ sub send {
$self->cgDebugPrint(2, "host is down");
last;
}
- carp("@{[(caller(0))[3]]}: ".Net::Pcap::geterr($self->[$___io])."\n");
- return undef;
+ print STDERR "[!] @{[(caller(0))[3]]}: ".
+ Net::Pcap::geterr($self->[$___io])."\n";
+ return;
}
last;
}
- 1;
+ return 1;
}
sub close {
@@ -121,11 +125,11 @@ Under Windows systems, this is more complex; example:
=item B<new>
-Object constructor. You MUST pass a valid B<dev> attribute. There is no default value.
+Object constructor. You MUST pass a valid B<dev> attribute. There is no default value. Returns undef on error.
=item B<open>
-Open the interface.
+Open the interface. Returns undef on error.
=item B<send> (scalar)
@@ -151,7 +155,7 @@ Patrice E<lt>GomoRE<gt> Auffret
=head1 COPYRIGHT AND LICENSE
-Copyright (c) 2006-2009, Patrice E<lt>GomoRE<gt> Auffret
+Copyright (c) 2006-2015, Patrice E<lt>GomoRE<gt> Auffret
You may distribute this module under the terms of the Artistic license.
See LICENSE.Artistic file in the source distribution archive.
@@ -1,13 +1,12 @@
#
-# $Id: Layer3.pm 1636 2009-06-10 18:38:24Z gomor $
+# $Id: Layer3.pm 2005 2015-01-23 06:56:13Z gomor $
#
package Net::Write::Layer3;
use strict;
use warnings;
-use Carp;
use Net::Write::Layer qw(:constants);
-our @ISA = qw(Net::Write::Layer);
+use base qw(Net::Write::Layer);
__PACKAGE__->cgBuildIndices;
BEGIN {
@@ -22,7 +21,9 @@ BEGIN {
no strict 'vars';
sub _newWin32 {
- croak("Not possible to use layer 3 under Windows. Use layer 2 instead.\n");
+ print STDERR "[-] Not possible to use layer 3 under Windows. Use layer 2 ".
+ "instead.\n";
+ return;
}
sub _newOther {
@@ -30,12 +31,14 @@ sub _newOther {
protocol => NW_IPPROTO_RAW,
family => NW_AF_INET,
@_,
- );
+ ) or return;
- croak("@{[(caller(0))[3]]}: you must pass `dst' parameter\n")
- unless $self->[$__dst];
+ if (! $self->[$__dst]) {
+ print STDERR "[-] @{[(caller(0))[3]]}: you must pass `dst' parameter\n";
+ return;
+ }
- $self;
+ return $self;
}
sub open { shift->SUPER::open(1) }
@@ -109,9 +112,11 @@ protocol: NW_IPPROTO_RAW
family: NW_AF_INET
+Returns undef on error.
+
=item B<open>
-Open the interface.
+Open the interface. Returns undef on error.
=item B<send> (scalar)
@@ -139,7 +144,7 @@ Patrice E<lt>GomoRE<gt> Auffret
=head1 COPYRIGHT AND LICENSE
-Copyright (c) 2006-2009, Patrice E<lt>GomoRE<gt> Auffret
+Copyright (c) 2006-2015, Patrice E<lt>GomoRE<gt> Auffret
You may distribute this module under the terms of the Artistic license.
See LICENSE.Artistic file in the source distribution archive.
@@ -1,13 +1,12 @@
#
-# $Id: Layer4.pm 1636 2009-06-10 18:38:24Z gomor $
+# $Id: Layer4.pm 2005 2015-01-23 06:56:13Z gomor $
#
package Net::Write::Layer4;
use strict;
use warnings;
-use Carp;
use Net::Write::Layer qw(:constants);
-our @ISA = qw(Net::Write::Layer);
+use base qw(Net::Write::Layer);
__PACKAGE__->cgBuildIndices;
BEGIN {
@@ -22,7 +21,9 @@ BEGIN {
no strict 'vars';
sub _newWin32 {
- croak("Not possible to use layer 4 under Windows. Use layer 2 instead.\n");
+ print STDERR "[-] Not possible to use layer 4 under Windows. Use layer 2 ".
+ "instead.\n";
+ return;
}
sub _newOther {
@@ -30,12 +31,14 @@ sub _newOther {
protocol => NW_IPPROTO_TCP,
family => NW_AF_INET,
@_,
- );
+ ) or return;
- croak("@{[(caller(0))[3]]}: you must pass `dst' parameter\n")
- unless $self->[$__dst];
+ if (! $self->[$__dst]) {
+ print STDERR "[-] @{[(caller(0))[3]]}: you must pass `dst' parameter\n";
+ return;
+ }
- $self;
+ return $self;
}
1;
@@ -95,9 +98,11 @@ protocol: NW_IPPROTO_TCP
family: NW_AF_INET
+Returns undef on error.
+
=item B<open>
-Open the interface.
+Open the interface. Returns undef on error.
=item B<send> (scalar)
@@ -123,7 +128,7 @@ Patrice E<lt>GomoRE<gt> Auffret
=head1 COPYRIGHT AND LICENSE
-Copyright (c) 2006-2009, Patrice E<lt>GomoRE<gt> Auffret
+Copyright (c) 2006-2015, Patrice E<lt>GomoRE<gt> Auffret
You may distribute this module under the terms of the Artistic license.
See LICENSE.Artistic file in the source distribution archive.
@@ -1,5 +1,5 @@
#
-# $Id: Write.pm 1636 2009-06-10 18:38:24Z gomor $
+# $Id: Write.pm 2005 2015-01-23 06:56:13Z gomor $
#
package Net::Write;
use strict;
@@ -7,7 +7,7 @@ use warnings;
require v5.6.1;
-our $VERSION = '1.05';
+our $VERSION = '1.08';
1;
@@ -35,7 +35,7 @@ Patrice E<lt>GomoRE<gt> Auffret
=head1 COPYRIGHT AND LICENSE
-Copyright (c) 2006-2009, Patrice E<lt>GomoRE<gt> Auffret
+Copyright (c) 2006-2015, Patrice E<lt>GomoRE<gt> Auffret
You may distribute this module under the terms of the Artistic license.
See LICENSE.Artistic file in the source distribution archive.