The Perl Toolchain Summit needs more sponsors. If your company depends on Perl, please support this very important event.
Changes 07
MANIFEST 12
META.json 043
META.yml 1523
README 11
lib/Net/Write/Layer.pm 2141
lib/Net/Write/Layer2.pm 1721
lib/Net/Write/Layer3.pm 1015
lib/Net/Write/Layer4.pm 1015
lib/Net/Write.pm 33
10 files changed (This is a version diff) 78171
@@ -1,5 +1,12 @@
 Revision history for Perl extension Net::Write.
 
+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                                 Module YAML meta-data (added by MakeMaker)
+META.json                                Module JSON meta-data (added by MakeMaker)
@@ -0,0 +1,43 @@
+{
+   "abstract" : "a portable interface to open and send raw data to network",
+   "author" : [
+      "GomoR <gomor-cpan_at_gomor.org>"
+   ],
+   "dynamic_config" : 1,
+   "generated_by" : "ExtUtils::MakeMaker version 6.62, CPAN::Meta::Converter version 2.112150",
+   "license" : [
+      "artistic_1"
+   ],
+   "meta-spec" : {
+      "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec",
+      "version" : "2"
+   },
+   "name" : "Net-Write",
+   "no_index" : {
+      "directory" : [
+         "t",
+         "inc"
+      ]
+   },
+   "prereqs" : {
+      "build" : {
+         "requires" : {
+            "ExtUtils::MakeMaker" : 0
+         }
+      },
+      "configure" : {
+         "requires" : {
+            "ExtUtils::MakeMaker" : 0
+         }
+      },
+      "runtime" : {
+         "requires" : {
+            "Class::Gomor" : 0,
+            "Net::Pcap" : "0.12",
+            "Socket6" : 0
+         }
+      }
+   },
+   "release_status" : "stable",
+   "version" : "1.07"
+}
@@ -1,16 +1,24 @@
---- #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-cpan_at_gomor.org>'
+build_requires:
+  ExtUtils::MakeMaker: 0
+configure_requires:
+  ExtUtils::MakeMaker: 0
+dynamic_config: 1
+generated_by: 'ExtUtils::MakeMaker version 6.62, CPAN::Meta::Converter version 2.112150'
+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
+no_index:
+  directory:
+    - t
+    - inc
+requires:
+  Class::Gomor: 0
+  Net::Pcap: 0.12
+  Socket6: 0
+version: 1.07
@@ -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-2012, Patrice <GomoR> Auffret
 
@@ -1,13 +1,11 @@
 #
-# $Id: Layer.pm 1636 2009-06-10 18:38:24Z gomor $
+# $Id: Layer.pm 2003 2012-09-02 16:43:45Z 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
@@ -116,7 +114,6 @@ 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_UNSPEC => AF_UNSPEC();
@@ -146,41 +143,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 {
+   my $self = shift->SUPER::new(
+      @_,
+   );
+
+   _check() or return;
+
+   return $self;
 }
 
-sub new { _check(); shift->SUPER::new(@_) }
+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 +219,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 +276,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 +336,7 @@ Patrice E<lt>GomoRE<gt> Auffret
 
 =head1 COPYRIGHT AND LICENSE
 
-Copyright (c) 2006-2009, Patrice E<lt>GomoRE<gt> Auffret
+Copyright (c) 2006-2012, 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 2000 2012-08-31 14:57:05Z 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-2012, 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 2000 2012-08-31 14:57:05Z 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-2012, 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 2000 2012-08-31 14:57:05Z 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-2012, 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 2003 2012-09-02 16:43:45Z gomor $
 #
 package Net::Write;
 use strict;
@@ -7,7 +7,7 @@ use warnings;
 
 require v5.6.1;
 
-our $VERSION = '1.05';
+our $VERSION = '1.07';
 
 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-2012, 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.