| 1 | # | ||
| 2 | # $Id: Layer3.pm 2008 2015-02-10 06:33:53Z gomor $ | ||
| 3 | # | ||
| 4 | package Net::Write::Layer3; | ||
| 5 | 1 | ▶ | use strict; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 6 | 1 | ▶ | use warnings; |
|
Subroutine
BEGIN: called CC=1 SCAR=0.0
| |||
| 7 | |||
| 8 | 0 | ▶ | use Net::Write::Layer qw(:constants); |
|
Subroutine
BEGIN: called CC=1 SCAR=2.6
| |||
| 9 | use base qw(Net::Write::Layer); | ||
| 10 | __PACKAGE__->cgBuildIndices; | ||
| 11 | |||
| 12 | BEGIN { | ||
| 13 | my $osname = { | ||
| 14 | cygwin => \&_newWin32, | ||
| 15 | MSWin32 => \&_newWin32, | ||
| 16 | }; | ||
| 17 | |||
| 18 | *new = $osname->{$^O} || \&_newOther; | ||
| 19 | } | ||
| 20 | |||
| 21 | no strict 'vars'; | ||
| 22 | |||
| 23 | sub _newWin32 { | ||
| 24 | print STDERR "[-] Not possible to use layer 3 under Windows. Use layer 2 ". | ||
| 25 | "instead.\n"; | ||
| 26 | return; | ||
| 27 | } | ||
| 28 | |||
| 29 | sub _newOther { | ||
| 30 | my $self = shift->SUPER::new( | ||
| 31 | protocol => NW_IPPROTO_RAW, | ||
| 32 | family => NW_AF_INET, | ||
| 33 | @_, | ||
| 34 | ) or return; | ||
| 35 | |||
| 36 | if (! $self->[$__dst]) { | ||
| 37 | print STDERR "[-] @{[(caller(0))[3]]}: you must pass `dst' parameter\n"; | ||
| 38 | return; | ||
| 39 | } | ||
| 40 | |||
| 41 | return $self; | ||
| 42 | } | ||
| 43 | |||
| 44 | sub open { shift->SUPER::open(1) } | ||
| 45 | |||
| 46 | sub _setIpHdrincl { | ||
| 47 | my $self = shift; | ||
| 48 | my ($sock, $family) = @_; | ||
| 49 | if ($family == NW_AF_INET) { | ||
| 50 | return setsockopt($sock, NW_IPPROTO_IP, NW_IP_HDRINCL, 1); | ||
| 51 | } | ||
| 52 | if ($family == NW_AF_INET6) { | ||
| 53 | # Currently, only Linux supports IPHDRINCL for IPv6, no Layer3 sending for others :( | ||
| 54 | if ($^O ne 'linux') { | ||
| 55 | die("[-] @{[(caller(0))[3]]}: IPHDRINCL only supported on Linux\n"); | ||
| 56 | } | ||
| 57 | return setsockopt($sock, NW_IPPROTO_IPv6, NW_IP_HDRINCL, 1); | ||
| 58 | } | ||
| 59 | return; | ||
| 60 | } | ||
| 61 | |||
| 62 | 1; | ||
| 63 | |||
| 64 | __END__ | ||