NetPacket-1.8.0000755001750001750 015141002125 13304 5ustar00yanickyanick000000000000README100644001750001750 261215141002125 14246 0ustar00yanickyanick000000000000NetPacket-1.8.0NetPacket version 0.41.1 This is a whole bunch of Perl modules which I have named NetPacket::*. These modules do basic disassembly of network packets of various Internet protocols. NetPacket 0.01 contained hooks for assembly of packets which have been implemented in version 0.04 by Stephanie Wehner . I've used these scripts for a variety of little jobs such as snooping various TCP services, gathering network traffic statistics by source/destination/protocol, and for unpacking the contents of IP tunnels. They're actually pretty useful. I recommend fetching and installing the Net::Pcap module to actually gather packet data, and for writing small scripts based on packet capture, the Net::PcapUtils module is also useful. At present, decoding for the following protocols has been implemented. - Ethernet (802.3 and 802.2) - ARP - ICMP - IGMP - IP - UDP - TCP - USBMon It's pretty easy to add new protocols. Just copy one of the existing modules and figure out an unpack string which will unpack the information in the packet and store the data into fields in the namespace of the NetPacket::whatever object. More information can be found in the NetPacket(3) manpage, which is the base class module. I'd be interested in receiving bug reports, comments or any improvements (especially additional protocols) to the NetPacket modules. Tim Potter 30th July, 2001 tpot@samba.org INSTALL100644001750001750 452215141002125 14421 0ustar00yanickyanick000000000000NetPacket-1.8.0This is the Perl distribution NetPacket. Installing NetPacket is straightforward. ## Installation with cpanm If you have cpanm, you only need one line: % cpanm NetPacket If it does not have permission to install modules to the current perl, cpanm will automatically set up and install to a local::lib in your home directory. See the local::lib documentation (https://metacpan.org/pod/local::lib) for details on enabling it in your environment. ## Installing with the CPAN shell Alternatively, if your CPAN shell is set up, you should just be able to do: % cpan NetPacket ## Manual installation As a last resort, you can manually install it. If you have not already downloaded the release tarball, you can find the download link on the module's MetaCPAN page: https://metacpan.org/pod/NetPacket Untar the tarball, install configure prerequisites (see below), then build it: % perl Makefile.PL % make && make test Then install it: % make install On Windows platforms, you should use `dmake` or `nmake`, instead of `make`. If your perl is system-managed, you can create a local::lib in your home directory to install modules to. For details, see the local::lib documentation: https://metacpan.org/pod/local::lib The prerequisites of this distribution will also have to be installed manually. The prerequisites are listed in one of the files: `MYMETA.yml` or `MYMETA.json` generated by running the manual build process described above. ## Configure Prerequisites This distribution requires other modules to be installed before this distribution's installer can be run. They can be found under the "configure_requires" key of META.yml or the "{prereqs}{configure}{requires}" key of META.json. ## Other Prerequisites This distribution may require additional modules to be installed after running Makefile.PL. Look for prerequisites in the following phases: * to run make, PHASE = build * to use the module code itself, PHASE = runtime * to run tests, PHASE = test They can all be found in the "PHASE_requires" key of MYMETA.yml or the "{prereqs}{PHASE}{requires}" key of MYMETA.json. ## Documentation NetPacket documentation is available as POD. You can run `perldoc` from a shell to read the documentation: % perldoc NetPacket For more information on installing Perl modules via CPAN, please see: https://www.cpan.org/modules/INSTALL.html LICENSE100644001750001750 2156615141002125 14424 0ustar00yanickyanick000000000000NetPacket-1.8.0This software is Copyright (c) 2026, 2010, 2009, 2008 by Tim Potter and Stephanie Wehner. This is free software, licensed under: The Artistic License 2.0 (GPL Compatible) The Artistic License 2.0 Copyright (c) 2000-2006, The Perl Foundation. Everyone is permitted to copy and distribute verbatim copies of this license document, but changing it is not allowed. Preamble This license establishes the terms under which a given free software Package may be copied, modified, distributed, and/or redistributed. The intent is that the Copyright Holder maintains some artistic control over the development of that Package while still keeping the Package available as open source and free software. You are always permitted to make arrangements wholly outside of this license directly with the Copyright Holder of a given Package. If the terms of this license do not permit the full use that you propose to make of the Package, you should contact the Copyright Holder and seek a different licensing arrangement. Definitions "Copyright Holder" means the individual(s) or organization(s) named in the copyright notice for the entire Package. "Contributor" means any party that has contributed code or other material to the Package, in accordance with the Copyright Holder's procedures. "You" and "your" means any person who would like to copy, distribute, or modify the Package. "Package" means the collection of files distributed by the Copyright Holder, and derivatives of that collection and/or of those files. A given Package may consist of either the Standard Version, or a Modified Version. "Distribute" means providing a copy of the Package or making it accessible to anyone else, or in the case of a company or organization, to others outside of your company or organization. "Distributor Fee" means any fee that you charge for Distributing this Package or providing support for this Package to another party. It does not mean licensing fees. "Standard Version" refers to the Package if it has not been modified, or has been modified only in ways explicitly requested by the Copyright Holder. "Modified Version" means the Package, if it has been changed, and such changes were not explicitly requested by the Copyright Holder. "Original License" means this Artistic License as Distributed with the Standard Version of the Package, in its current version or as it may be modified by The Perl Foundation in the future. "Source" form means the source code, documentation source, and configuration files for the Package. "Compiled" form means the compiled bytecode, object code, binary, or any other form resulting from mechanical transformation or translation of the Source form. Permission for Use and Modification Without Distribution (1) You are permitted to use the Standard Version and create and use Modified Versions for any purpose without restriction, provided that you do not Distribute the Modified Version. Permissions for Redistribution of the Standard Version (2) You may Distribute verbatim copies of the Source form of the Standard Version of this Package in any medium without restriction, either gratis or for a Distributor Fee, provided that you duplicate all of the original copyright notices and associated disclaimers. At your discretion, such verbatim copies may or may not include a Compiled form of the Package. (3) You may apply any bug fixes, portability changes, and other modifications made available from the Copyright Holder. The resulting Package will still be considered the Standard Version, and as such will be subject to the Original License. Distribution of Modified Versions of the Package as Source (4) You may Distribute your Modified Version as Source (either gratis or for a Distributor Fee, and with or without a Compiled form of the Modified Version) provided that you clearly document how it differs from the Standard Version, including, but not limited to, documenting any non-standard features, executables, or modules, and provided that you do at least ONE of the following: (a) make the Modified Version available to the Copyright Holder of the Standard Version, under the Original License, so that the Copyright Holder may include your modifications in the Standard Version. (b) ensure that installation of your Modified Version does not prevent the user installing or running the Standard Version. In addition, the Modified Version must bear a name that is different from the name of the Standard Version. (c) allow anyone who receives a copy of the Modified Version to make the Source form of the Modified Version available to others under (i) the Original License or (ii) a license that permits the licensee to freely copy, modify and redistribute the Modified Version using the same licensing terms that apply to the copy that the licensee received, and requires that the Source form of the Modified Version, and of any works derived from it, be made freely available in that license fees are prohibited but Distributor Fees are allowed. Distribution of Compiled Forms of the Standard Version or Modified Versions without the Source (5) You may Distribute Compiled forms of the Standard Version without the Source, provided that you include complete instructions on how to get the Source of the Standard Version. Such instructions must be valid at the time of your distribution. If these instructions, at any time while you are carrying out such distribution, become invalid, you must provide new instructions on demand or cease further distribution. If you provide valid instructions or cease distribution within thirty days after you become aware that the instructions are invalid, then you do not forfeit any of your rights under this license. (6) You may Distribute a Modified Version in Compiled form without the Source, provided that you comply with Section 4 with respect to the Source of the Modified Version. Aggregating or Linking the Package (7) You may aggregate the Package (either the Standard Version or Modified Version) with other packages and Distribute the resulting aggregation provided that you do not charge a licensing fee for the Package. Distributor Fees are permitted, and licensing fees for other components in the aggregation are permitted. The terms of this license apply to the use and Distribution of the Standard or Modified Versions as included in the aggregation. (8) You are permitted to link Modified and Standard Versions with other works, to embed the Package in a larger work of your own, or to build stand-alone binary or bytecode versions of applications that include the Package, and Distribute the result without restriction, provided the result does not expose a direct interface to the Package. Items That are Not Considered Part of a Modified Version (9) Works (including, but not limited to, modules and scripts) that merely extend or make use of the Package, do not, by themselves, cause the Package to be a Modified Version. In addition, such works are not considered parts of the Package itself, and are not subject to the terms of this license. General Provisions (10) Any use, modification, and distribution of the Standard or Modified Versions is governed by this Artistic License. By using, modifying or distributing the Package, you accept this license. Do not use, modify, or distribute the Package, if you do not accept this license. (11) If your Modified Version has been derived from a Modified Version made by someone other than you, you are nevertheless required to ensure that your Modified Version complies with the requirements of this license. (12) This license does not grant you the right to use any trademark, service mark, tradename, or logo of the Copyright Holder. (13) This license includes the non-exclusive, worldwide, free-of-charge patent license to make, have made, use, offer to sell, sell, import and otherwise transfer the Package with respect to any patent claims licensable by the Copyright Holder that are necessarily infringed by the Package. If you institute patent litigation (including a cross-claim or counterclaim) against any party alleging that the Package constitutes direct or contributory patent infringement, then this Artistic License to you shall terminate on the date that such litigation is filed. (14) Disclaimer of Warranty: THE PACKAGE IS PROVIDED BY THE COPYRIGHT HOLDER AND CONTRIBUTORS "AS IS" AND WITHOUT ANY EXPRESS OR IMPLIED WARRANTIES. THE IMPLIED WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE, OR NON-INFRINGEMENT ARE DISCLAIMED TO THE EXTENT PERMITTED BY YOUR LOCAL LAW. UNLESS REQUIRED BY LAW, NO COPYRIGHT HOLDER OR CONTRIBUTOR WILL BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, OR CONSEQUENTIAL DAMAGES ARISING IN ANY WAY OUT OF THE USE OF THE PACKAGE, EVEN IF ADVISED OF THE POSSIBILITY OF SUCH DAMAGE. Changes100644001750001750 1244015141002125 14701 0ustar00yanickyanick000000000000NetPacket-1.8.0revision history for NetPacket 1.8.0 2026-02-04 [API CHANGES] [BUG FIXES] - Add a test for checksum calculation in ICMPv6 which also uses the same IPv6 pseudo-header as UDP and TCP (Grinnz, GH#17) - Fix IPv6 pseudo-header formation (fixes Wrong pseudoheader created for checksum calculation #16) (Grinnz, GH#17) - Fix ICMPv6 packet length used for checksum (Grinnz, GH#17) [DOCUMENTATION] [ENHANCEMENTS] - Add support for SLL and SLL2 (Linux cooked capture) (Grinnz, GH#18) [MISC] - Move to Test2 for the testing [NEW FEATURES] [STATISTICS] - code churn: 25 files changed, 749 insertions(+), 66 deletions(-) 1.7.2 2019-07-20 [DOCUMENTATION] - fix typos. (GH#14) [STATISTICS] - code churn: 7 files changed, 121 insertions(+), 42 deletions(-) 1.7.1 2019-06-08 [BUG FIXES] - fixes inverted ethernet ports (reported by sanyacomua) [STATISTICS] - code churn: 4 files changed, 140 insertions(+), 130 deletions(-) 1.7.0 2018-12-30 [ENHANCEMENTS] - Setup aliases at compile time (Nicolas R, GH#11) - add recommended Net::Pcap{,Utils} from README (Zak B. Elep, GH#12) [NEW FEATURES] - adds back basic support for IPv6. (Dan Book, GH#10) [STATISTICS] - code churn: 16 files changed, 1177 insertions(+), 48 deletions(-) 1.6.0 2015-03-13 [ENHANCEMENTS] - Clean up inheritance code (Philip Prindeville). - Add a truckload of constants (Philip Prindeville). [STATISTICS] - code churn: 12 files changed, 343 insertions(+), 220 deletions(-) 1.5.0 2014-06-15 [ENHANCEMENTS] - Addition of NetPacket::IPX. (Daniel Collins) - NetPacket::Ethernet implements 'encode'. (RT#93928, Guido Hungerbuehler) [STATISTICS] - code churn: 7 files changed, 337 insertions(+), 13 deletions(-) 1.4.4 2013-11-30 [BUG FIXES] - NetPacket::USBMon: also handle big endian perl without quad type. (GH#5, Andreas Schwab) - Typo fix in comments. (GH#6, fschlich) [STATISTICS] - code churn: 3 files changed, 13 insertions(+), 4 deletions(-) 1.4.3 2013-10-03 [BUG FIXES] - Unpack data in LittleEndian format. (GH#4, k0da) [STATISTICS] - code churn: 3 files changed, 62 insertions(+), 27 deletions(-) 1.4.2 2013-09-25 [BUG FIXES] - Dist::Zilla::Plugin::Test::Compile was causing test to potentially hang on Windows. (reported by Karen Etheridge) [MISC] - Tidy up the changelog. (GH#3, Neil Bowers) [STATISTICS] - code churn: 2 files changed, 46 insertions(+), 20 deletions(-) 1.4.1 2013-09-05 [BUG FIXES] - Test was using Errno constant and failing on some platforms. [STATISTICS] - code churn: 2 files changed, 15 insertions(+), 7 deletions(-) 1.4.0 2013-08-26 [DOCUMENTATION] - Fixing NetPacked::UDP documentation. (RT#85361, Ben Magistro) [ENHANCEMENTS] - New NetPacket::USBMon. (GH#2, lkundrak) [STATISTICS] - code churn: 8 files changed, 595 insertions(+), 16 deletions(-) 1.3.3 2013-05-15 [BUG FIXES] - Parse SACK option and fix TSecr parsing. (GH#1, Robin Lee) [STATISTICS] - code churn: 5 files changed, 46 insertions(+), 7 deletions(-) 1.3.2 2013-05-03 [BUG FIXES] - Fix NetPacket::UDP's strip. (RT#85038, reported by Stan Schwertly) [STATISTICS] - code churn: 12 files changed, 71 insertions(+), 21 deletions(-) 1.3.1 2011-11-23 [BUG FIXES] - Use of constant withotu parenthesis made test fail under 5.6.2. 1.3.0 2011-11-13 [ENHANCEMENTS] - 'parse_tcp_options()' method added to NetPacket::TCP (patch by Tom Linden) [RT#71320] 1.2.0 2011-07-26 [ENHANCEMENTS] - Add support for Ethernet VLAN (thanks to Kai Chan) 1.1.2 2011-06-20 [BUG FIXES] - Add a INSTALL file 1.1.1 2011-02-07 - Add the new Ethernet types to the export list. (thanks to Sergey, again :-) ) (RT#64799) 1.1.0 2011-01-15 - Add a few Ethernet types. (thanks to Sergey) (RT#64799) 1.0.1 2010-10-19 - Make the example verbatim in pod in NetPacket::UDP (rt#62097) 1.0.0 2010-10-17 - Remove modules NetPacket::ICMPv6, NetPacket::IPv6 and NetPacket::PFLog as the license of the patch clashes with the license of the distribution. (RT#62197) 0.43.2 2010-10-11 - Change the COPYRIGHT sections of the pods to match the Artistic 2.0 license. (RT#60954) 0.43.1 2010-06-11 - Change a test to use explicit number of tests instead of 'done_testing'. 0.43.0 2010-05-23 - Fixed UDP checksum. Thanks to Hal Finkel. (RT#56235) - Added Joel Knight's code for IPv6 support from http://www.packetmischief.ca/code/netpacket/. Thanks to Doug Farley for the bug report. (RT#57560) 0.42.0 2010-03-25 - Updated license to Artistic 2.0 - Fixed bad call to 'data()' in ICMP. Thanks to Ventz Petkov. (RT#52627) 0.41.1 2009-01-06 - Fixed bug 37931: export of ICMP_MASKREQ - Fixed UDP and TCP checksums for odd-sized packets - Fixed import from NetPacket::UDP - Fixed bug 37931: export of ICMP_MASKREQ - Added git repo and bug tracking info to META.yml 0.41.0_0 2008-12-20 - Fixed bug 18941 - NetPacket::IP includes trailing trash bytes in $ip->{data} - Fixed bug 7010 - IP flags field lost in IP::encode() - Added Build.PL - Moved history off the README file into this one (Changes) - Moved module structure to /lib - Version now gathered from NetPacket.pm - META.yml added to MANIFEST - Added myself (Yanick) as author - Switched to major.minor.revision version notation 0.04 2003-05-21 - Checksum offset fix, thanks to J. Hoagland for pointing this out. 0.03 2001-07-30 0.01 1999-04-24 - First release by TIMPOTTER t000755001750001750 015141002125 13470 5ustar00yanickyanick000000000000NetPacket-1.8.0ipx.t100644001750001750 406515141002125 14622 0ustar00yanickyanick000000000000NetPacket-1.8.0/t#!/usr/bin/perl use strict; use warnings; use Test2::Bundle::More; use NetPacket::IPX; plan tests => 13; my $packet = "" ."\xFF\xFF" # "checksum" ."\x00\x2A" # header + data length ."\x64" # Traffic Control ."\x05" # Packet type ."\x46\x35\x57\xFF" # Destination network ."\x01\x23\x45\x67\x89\xAB" # Destination node ."\xEE\xAA" # Destination socket ."\xDE\xFF\x00\x01" # Source network ."\xCD\xEF\x01\x23\x45\x67" # Source node ."\xAA\xAA" # Source socket ."\x00some \n\xFFdata"; { my $ipx = NetPacket::IPX->decode($packet); isa_ok($ipx, "NetPacket::IPX"); is($ipx->{tc}, 0x64, "NetPacket::IPX->decode() decodes the tc field"); is($ipx->{type}, 0x05, "NetPacket::IPX->decode() decodes the type field"); is($ipx->{dest_network}, "46:35:57:FF", "NetPacket::IPX->decode() decodes the destination network field"); is($ipx->{dest_node}, "01:23:45:67:89:AB", "NetPacket::IPX->decode() decodes the destination node field"); is($ipx->{dest_socket}, 0xEEAA, "NetPacket::IPX->decode() decodes the destination socket field"); is($ipx->{src_network}, "DE:FF:00:01", "NetPacket::IPX->decode() decodes the source network field"); is($ipx->{src_node}, "CD:EF:01:23:45:67", "NetPacket::IPX->decode() decodes the source node field"); is($ipx->{src_socket}, 0xAAAA, "NetPacket::IPX->decode() decodes the source socket field"); is($ipx->{data}, "\x00some \n\xFFdata", "NetPacket::IPX->decode() extracts the packet payload"); } { my $ipx = NetPacket::IPX->new( tc => 0x64, type => 0x05, dest_network => "46:35:57:fF", dest_node => "1:23:45:67:89:Ab", dest_socket => 0xEEAA, src_network => "dE:fF:0:1", src_node => "Cd:ef:1:23:45:67", src_socket => 0xAAAA, data => "\x00some \n\xFFdata", ); isa_ok($ipx, "NetPacket::IPX"); is($ipx->encode(), $packet, "NetPacket::IPX->encode() encodes the packet correctly"); } is(NetPacket::IPX::strip($packet), "\x00some \n\xFFdata", "NetPacket::IPX::strip() extracts the packet payload"); sll.t100644001750001750 247415141002125 14616 0ustar00yanickyanick000000000000NetPacket-1.8.0/tuse strict; use warnings; use Test2::Bundle::More; use NetPacket::SLL qw/ :strip :types /; use NetPacket::Ethernet qw/ :types /; use NetPacket::ARP qw/ :protos /; is SLL_TYPE_SENT_BY_US() => 4, 'imports'; is NetPacket::SLL::SLL_TYPE_UNICAST() => 0, 'with namespace'; my @test_data = ( {type => SLL_TYPE_SENT_BY_US(), htype => ARPHRD_ETHER(), src_addr => 'fedcba987654', proto => ETH_TYPE_IP(), data => "\x01\x02\x03\x04"}, ); my @datagrams = map { chomp; length($_) ? join('', map { chr hex } split /\./) : () } ; foreach my $datagram (@datagrams) { my $test = shift @test_data; my $sll = NetPacket::SLL->decode($datagram); is $sll->{type}, $test->{type}, 'type'; is $sll->{htype}, $test->{htype}, 'htype'; is lc($sll->{src_addr}), $test->{src_addr}, 'src_addr'; is $sll->{proto}, $test->{proto}, 'proto'; is $sll->{data}, $test->{data}, 'data'; is sll_strip($datagram), $test->{data}, 'strip'; my $q = NetPacket::SLL->decode($sll->encode); is $q->{type}, $sll->{type}, 'round-trip type'; is $q->{htype}, $sll->{htype}, 'round-trip htype'; is lc($q->{src_addr}), lc($sll->{src_addr}), 'round-trip src_addr'; is $q->{proto}, $sll->{proto}, 'round-trip proto'; is $q->{data}, $sll->{data}, 'round-trip data'; } done_testing; __DATA__ 00.04.00.01.00.06.FE.DC.BA.98.76.54.00.00.08.00.01.02.03.04 tcp.t100644001750001750 543515141002125 14612 0ustar00yanickyanick000000000000NetPacket-1.8.0/t use strict; use warnings; use Test2::Bundle::More; use NetPacket::Ethernet; use NetPacket::IP; use NetPacket::TCP; my $datagram = binarize( <<'END_DATAGRAM' ); 00 21 85 9a 70 4d 00 80 64 54 ba 3a 08 00 45 00 00 e4 2b 2d 40 00 74 06 0f 26 cc e8 f4 d6 0a 00 00 02 00 50 82 60 eb 9d d5 71 11 5e 81 59 80 18 fb 28 3d cf 00 00 01 01 08 0a 30 61 d4 65 05 8c 40 76 48 54 54 50 2f 31 2e 31 20 32 30 30 20 4f 4b 0d 0a 43 6f 6e 74 65 6e 74 2d 54 79 70 65 3a 20 61 70 70 6c 69 63 61 74 69 6f 6e 2f 6a 73 6f 6e 3b 20 63 68 61 72 73 65 74 3d 75 74 66 2d 38 0d 0a 53 65 72 76 65 72 3a 20 4d 69 63 72 6f 73 6f 66 74 2d 49 49 53 2f 37 2e 30 0d 0a 58 2d 50 6f 77 65 72 65 64 2d 42 79 3a 20 41 53 50 2e 4e 45 54 0d 0a 44 61 74 65 3a 20 46 72 69 2c 20 30 37 20 4d 61 79 20 32 30 31 30 20 32 32 3a 35 38 3a 32 35 20 47 4d 54 0d 0a 43 6f 6e 74 65 6e 74 2d 4c 65 6e 67 74 68 3a 20 34 0d 0a 0d 0a 34 36 32 34 END_DATAGRAM my $eth = NetPacket::Ethernet->decode( $datagram ); my $ip = NetPacket::IP->decode( $eth->{data} ); my $tcp = NetPacket::TCP->decode( $ip->{data}, $ip ); like $tcp->{data} => qr/^HTTP.*4624$/ms, 'TCP payload'; # same thing, but with noise at the end of the Eth # segment $datagram = binarize( <<'END_DATAGRAM' ); 00 21 85 9a 70 4d 00 80 64 54 ba 3a 08 00 # IP 45 00 00 e4 2b 2d 40 00 74 06 0f 26 cc e8 f4 d6 0a 00 00 02 # TCP 00 50 82 60 eb 9d d5 71 11 5e 81 59 80 18 fb 28 3d cf 00 00 01 01 08 0a 30 61 d4 65 05 8c 40 76 48 54 54 50 2f 31 2e 31 20 32 30 30 20 4f 4b 0d 0a 43 6f 6e 74 65 6e 74 2d 54 79 70 65 3a 20 61 70 70 6c 69 63 61 74 69 6f 6e 2f 6a 73 6f 6e 3b 20 63 68 61 72 73 65 74 3d 75 74 66 2d 38 0d 0a 53 65 72 76 65 72 3a 20 4d 69 63 72 6f 73 6f 66 74 2d 49 49 53 2f 37 2e 30 0d 0a 58 2d 50 6f 77 65 72 65 64 2d 42 79 3a 20 41 53 50 2e 4e 45 54 0d 0a 44 61 74 65 3a 20 46 72 69 2c 20 30 37 20 4d 61 79 20 32 30 31 30 20 32 32 3a 35 38 3a 32 35 20 47 4d 54 0d 0a 43 6f 6e 74 65 6e 74 2d 4c 65 6e 67 74 68 3a 20 34 0d 0a 0d 0a 34 36 32 34 de ad be ef END_DATAGRAM $eth = NetPacket::Ethernet->decode( $datagram ); $ip = NetPacket::IP->decode( $eth->{data} ); $tcp = NetPacket::TCP->decode( $ip->{data}, $ip ); like $tcp->{data} => qr/^HTTP.*4624$/ms, 'TCP payload'; is_deeply scalar $tcp->parse_tcp_options, { er => 93077622, ts => 811717733, }, 'options'; $datagram = binarize( <<'END_DATAGRAM'); d3 55 00 50 85 cf 98 36 00 00 00 00 a0 02 16 d0 9b 76 00 00 02 04 05 b4 04 02 08 0a 85 82 12 6d 00 00 00 00 01 03 03 04 END_DATAGRAM $tcp = NetPacket::TCP->decode( $datagram ); is_deeply scalar $tcp->parse_tcp_options, { er => 0, ts => 2239894125, mss => 1460, ws => 4, sack => 2, }, 'options'; sub binarize { my $string = shift; $string =~ s/^\s*#.*?$//mg; # remove comments return join '' => map { chr hex } split ' ', $string; } done_testing; udp.t100644001750001750 221615141002125 14606 0ustar00yanickyanick000000000000NetPacket-1.8.0/tuse strict; use warnings; use Test2::Bundle::More; use NetPacket::Ethernet; use NetPacket::IP; use NetPacket::UDP qw/ udp_strip /; my $datagram = binarize( <<'END_DATAGRAM' ); 00 90 d0 23 ed 2a 00 1c bf ca a3 d5 08 00 45 00 00 30 00 00 40 00 40 11 30 5a 0a 00 00 a5 84 b1 7b 0d eb 11 0d 96 00 1c 42 7f 00 01 00 00 21 12 a4 42 fd 95 e8 83 8a 05 28 45 6a 8e f1 e2 END_DATAGRAM my $eth = NetPacket::Ethernet->decode( $datagram ); my $ip = NetPacket::IP->decode( $eth->{data} ); my $udp = NetPacket::UDP->decode( $ip->{data}, $ip ); is unpack( "H*", $udp->{data} ) => '000100002112a442fd95e8838a0528456a8ef1e2', 'UDP payload (STUN)'; is $udp->{src_port} => 60177, 'src_port'; is $udp->{dest_port} => 3478, 'dest_port'; is $udp->{len} => 28, 'len'; is $udp->{cksum} => 17023, 'cksum'; is $udp->{src_port} => 60177, 'src_port'; is $udp->{dest_port} => 3478, 'dest_port'; is unpack( "H*", udp_strip($udp->encode($ip)) ) => '000100002112a442fd95e8838a0528456a8ef1e2', 'udp_strip()'; sub binarize { my $string = shift; $string =~ s/^\s*#.*?$//mg; # remove comments return join '' => map { chr hex } split ' ', $string; } done_testing; META.yml100644001750001750 530415141002125 14640 0ustar00yanickyanick000000000000NetPacket-1.8.0--- abstract: 'assemble/disassemble network packets at the protocol level' author: - 'Tim Potter ' - 'Stephanie Wehner ' - 'Yanick Champoux ' build_requires: ExtUtils::MakeMaker: '0' File::Spec: '0' IO::Handle: '0' IPC::Open3: '0' Test2::Bundle::More: '0' Test::More: '0' configure_requires: ExtUtils::MakeMaker: '0' dynamic_config: 0 generated_by: 'Dist::Zilla version 6.036, CPAN::Meta::Converter version 2.150010' license: artistic_2 meta-spec: url: http://module-build.sourceforge.net/META-spec-v1.4.html version: '1.4' name: NetPacket provides: NetPacket: file: lib/NetPacket.pm version: v1.8.0 NetPacket::ARP: file: lib/NetPacket/ARP.pm version: v1.8.0 NetPacket::Ethernet: file: lib/NetPacket/Ethernet.pm version: v1.8.0 NetPacket::ICMP: file: lib/NetPacket/ICMP.pm version: v1.8.0 NetPacket::ICMPv6: file: lib/NetPacket/ICMPv6.pm version: v1.8.0 NetPacket::IGMP: file: lib/NetPacket/IGMP.pm version: v1.8.0 NetPacket::IP: file: lib/NetPacket/IP.pm version: v1.8.0 NetPacket::IPX: file: lib/NetPacket/IPX.pm version: v1.8.0 NetPacket::IPv6: file: lib/NetPacket/IPv6.pm version: v1.8.0 NetPacket::SLL: file: lib/NetPacket/SLL.pm version: v1.8.0 NetPacket::SLL2: file: lib/NetPacket/SLL2.pm version: v1.8.0 NetPacket::TCP: file: lib/NetPacket/TCP.pm version: v1.8.0 NetPacket::UDP: file: lib/NetPacket/UDP.pm version: v1.8.0 NetPacket::USBMon: file: lib/NetPacket/USBMon.pm version: v1.8.0 recommends: Net::Pcap: '0' Net::PcapUtils: '0' requires: Carp: '0' Exporter: '0' Socket: '1.87' constant: '0' parent: '0' perl: v5.10.0 strict: '0' warnings: '0' resources: bugtracker: https://github.com/yanick/netpacket/issues homepage: https://github.com/yanick/netpacket repository: https://github.com/yanick/netpacket.git version: 1.8.0 x_authority: cpan:YANICK x_contributor_covenant: version: 0.02 x_contributors: - 'Andreas Schwab ' - 'Ben Magistro ' - 'Dan Book ' - 'Daniel Collins ' - 'Dinar Valeev ' - 'fschlich ' - 'Lubomir Rintel ' - 'Neil Bowers ' - 'Nicolas R ' - 'Robin Lee ' - 'Stan Schwertly ' - 'Stephanie Wehner ' - 'Tim Potter ' - 'Yanick Champoux ' - 'Zak B. Elep ' x_generated_by_perl: v5.42.0 x_serialization_backend: 'YAML::Tiny version 1.76' x_spdx_expression: Artistic-2.0 MANIFEST100644001750001750 134415141002125 14520 0ustar00yanickyanick000000000000NetPacket-1.8.0CODE_OF_CONDUCT.md CONTRIBUTING.md CONTRIBUTORS Changes INSTALL LICENSE MANIFEST META.json META.yml Makefile.PL README README.mkdn SECURITY.md SIGNATURE cpanfile doap.xml lib/NetPacket.pm lib/NetPacket/ARP.pm lib/NetPacket/Ethernet.pm lib/NetPacket/ICMP.pm lib/NetPacket/ICMPv6.pm lib/NetPacket/IGMP.pm lib/NetPacket/IP.pm lib/NetPacket/IPX.pm lib/NetPacket/IPv6.pm lib/NetPacket/SLL.pm lib/NetPacket/SLL2.pm lib/NetPacket/TCP.pm lib/NetPacket/UDP.pm lib/NetPacket/USBMon.pm t/00-compile.t t/00-report-prereqs.dd t/00-report-prereqs.t t/bug-37931.t t/checksum.t t/ethernet.t t/general.t t/icmp.t t/icmpv6.t t/ip_encode.t t/ip_trailing.t t/ipv6.t t/ipx.t t/sll.t t/sll2.t t/tcp.t t/udp-checksum.t t/udp.t t/usbmon.t xt/release/unused-vars.t icmp.t100644001750001750 157315141002125 14753 0ustar00yanickyanick000000000000NetPacket-1.8.0/tuse strict; use warnings; use Test2::Bundle::More; use NetPacket::Ethernet; use NetPacket::IP; use NetPacket::ICMP; my $datagram = binarize( <<'END_DATAGRAM' ); 00 00 00 00 00 00 00 00 00 00 00 00 08 00 45 00 00 54 00 00 40 00 40 01 3c a7 7f 00 00 01 7f 00 00 01 08 00 d8 2f b6 6f 00 00 f8 11 c9 45 ba 05 03 00 08 09 0a 0b 0c 0d 0e 0f 10 11 12 13 14 15 16 17 18 19 1a 1b 1c 1d 1e 1f 20 21 22 23 24 25 26 27 28 29 2a 2b 2c 2d 2e 2f 30 31 32 33 34 35 36 37 END_DATAGRAM my $eth = NetPacket::Ethernet->decode( $datagram ); my $ip = NetPacket::IP->decode( $eth->{data} ); my $icmp = NetPacket::ICMP->decode( $ip->{data} ); is $icmp->{cksum} => 55343, 'ICMP checksum'; # recompute the checksum $icmp->checksum; is $icmp->{cksum} => 55343, 'recomputed ICMP checksum'; sub binarize { my $string = shift; return join '' => map { chr hex } split ' ', $string; } done_testing; ipv6.t100644001750001750 1421515141002125 14724 0ustar00yanickyanick000000000000NetPacket-1.8.0/tuse strict; use warnings; use Test2::Bundle::More; use NetPacket::IPv6 qw(:protos :extheaders); use NetPacket::Ethernet; use Socket 1.87 qw(AF_INET6 inet_pton); my @test_data = ( { proto => IP_PROTO_TCP, len => 210, hop_limit => 53, src_ip => '2a02:2f0d:bff0:1:81:18:73:123', dest_ip => '2604:a880:800:a1::d9:6001' }, { proto => IP_PROTO_ICMPv6, len => 32, hop_limit => 255, src_ip => 'fe80::f890:3cff:fe6a:db7c', dest_ip => '2604:a880:800:a1::1' }, { proto => IP_PROTO_UDP, len => 56, hop_limit => 64, src_ip => '2604:a880:800:a1::d9:6001', dest_ip => '2604:a880:800:10::1:9001' }, { proto => IP_PROTO_UDP, len => 31, hop_limit => 57, src_ip => '2001:67c:6ec:224:f816:3eff:feee:9b4', dest_ip => '2604:a880:800:a1::d9:6001', extheaders => [{type => IPv6_EXTHEADER_DESTOPT, len => 0}] }, { proto => IP_PROTO_UDP, len => 80, hop_limit => 57, src_ip => '2001:67c:6ec:224:f816:3eff:feee:9b4', dest_ip => '2604:a880:800:a1::d9:6001', extheaders => [{type => IPv6_EXTHEADER_ROUTING, len => 2}] }, { proto => IP_PROTO_COMP, len => 166, hop_limit => 174, src_ip => '878e:f1f0:cdab:dcc6:232e:b88c:15c6:55ce', dest_ip => '4ab2:d018:cbf0:4462:c125:7300:d51a:42cd', extheaders => [{type => IPv6_EXTHEADER_TESTING2, len => 3}] }, { proto => IPv6_EXTHEADER_ESP, len => 198, hop_limit => 40, src_ip => '584c:2ead:4dbf:2a8f:4ef:e5e9:b823:8b33', dest_ip => 'e1c5:2c79:5ab8:701e:d885:c2d:eee9:57ef' }, ); my @datagrams = map { chomp; length($_) ? join('', map { chr hex } split /\./) : () } ; foreach my $datagram (@datagrams) { my $test = shift @test_data; my $eth = NetPacket::Ethernet->decode( $datagram ); my $ipv6 = NetPacket::IPv6->decode( $eth->{data} ); is $ipv6->{ver} => 6, 'IP version 6'; is $ipv6->{proto} => $test->{proto}, 'Right protocol'; is $ipv6->{len} => $test->{len}, 'Right payload length header'; is $ipv6->{hop_limit} => $test->{hop_limit}, 'Right hop limit'; is inet_pton(AF_INET6, $ipv6->{src_ip}), inet_pton(AF_INET6, $test->{src_ip}), 'Right source IP'; is inet_pton(AF_INET6, $ipv6->{dest_ip}), inet_pton(AF_INET6, $test->{dest_ip}), 'Right destination IP'; my $total_len = length($ipv6->{data}); if (@{$ipv6->{extheaders} || []} or @{$test->{extheaders} || []}) { is 0+@{$ipv6->{extheaders} || []}, 0+@{$test->{extheaders} || []}, 'Extension header count'; foreach my $extheader (@{$ipv6->{extheaders} || []}) { my $testheader = shift @{$test->{extheaders} || []}; is $extheader->{type}, $testheader->{type}, 'Right extension header type'; is $extheader->{len}, $testheader->{len}, 'Right extension header length header'; is length($extheader->{data}), $testheader->{len} * 8 + 6, 'Right extension header length'; $total_len += length($extheader->{data}) + 2; } } is $total_len, $test->{len}, 'Right payload size'; my $q = NetPacket::IPv6->decode( $ipv6->encode ); foreach my $key (grep { !m/^_/ } keys %$ipv6) { is_deeply $q->{$key}, $ipv6->{$key}, "Round-trip $key"; } } done_testing; __DATA__ FA.90.3C.6A.DB.7C.5C.45.27.78.FB.30.86.DD.60.8.FC.F7.0.D2.6.35.2A.2.2F.D.BF.F0.0.1.0.81.0.18.0.73.1.23.26.4.A8.80.8.0.0.A1.0.0.0.0.0.D9.60.1.1A.29.DA.E.28.54.4.7B.8A.75.17.6A.80.18.1.5F.D8.8B.0.0.1.1.8.A.13.86.D1.D6.1E.C0.E9.70.17.3.3.0.AD.FA.41.75.30.CB.7A.54.25.AD.81.41.10.C0.86.6B.A4.5D.9.EF.A6.C0.5C.A9.D8.E9.45.41.7.EE.12.C1.76.1F.5.AB.B2.48.FE.54.D4.56.42.7D.1C.F4.F.0.91.18.6E.2.90.F6.BF.41.8A.67.B2.BA.82.0.8.50.36.9E.FE.73.65.9D.3C.BA.5D.8A.89.4C.8B.AA.28.1E.75.DD.71.A6.7A.D0.1B.96.73.6B.ED.4E.87.11.AA.B9.4E.D1.F3.DB.DC.C6.E3.50.3B.7E.42.A7.83.FB.4.69.2B.2D.47.8A.BE.D9.BB.E9.FF.90.14.94.57.98.B6.F6.CD.37.7D.2B.D1.35.62.B0.4.8C.BC.27.B4.8F.DA.D0.D5.17.4D.A8.EF.63.57.3C.CF.D4.A7.64.71.D0.C7.50.AE.34.E2.65.0.F2.1D.59.15.16.8C.45.60.EE 0.0.5E.0.2.F0.FA.90.3C.6A.DB.7C.86.DD.60.0.0.0.0.20.3A.FF.FE.80.0.0.0.0.0.0.F8.90.3C.FF.FE.6A.DB.7C.26.4.A8.80.8.0.0.A1.0.0.0.0.0.0.0.1.87.0.A8.E5.0.0.0.0.26.4.A8.80.8.0.0.A1.0.0.0.0.0.0.0.1.1.1.FA.90.3C.6A.DB.7C 0.0.5E.0.2.F0.FA.90.3C.6A.DB.7C.86.DD.60.0.0.0.0.38.11.40.26.4.A8.80.8.0.0.A1.0.0.0.0.0.D9.60.1.26.4.A8.80.8.0.0.10.0.0.0.0.0.1.90.1.BB.7F.0.7B.0.38.9E.E0.23.0.9.20.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.DE.56.C0.8.71.2.98.B9.29.7C.5B.8D.B4.DE.EA.E.EB.68.E8.86.28.2.B2.2 FA.90.3C.6A.DB.7C.5C.45.27.78.FB.30.86.DD.60.0.0.0.0.1F.3C.39.20.1.6.7C.6.EC.2.24.F8.16.3E.FF.FE.EE.9.B4.26.4.A8.80.8.0.0.A1.0.0.0.0.0.D9.60.1.11.0.1.4.0.0.0.0.83.2.2B.CB.0.17.57.B5.0.0.0.0.0.1.0.0.73.74.61.74.73.D.A FA.90.3C.6A.DB.7C.5C.45.27.78.FB.30.86.DD.60.0.0.0.0.50.2B.39.20.1.6.7C.6.EC.2.24.F8.16.3E.FF.FE.EE.9.B4.26.4.A8.80.8.0.0.A1.0.0.0.0.0.D9.60.1.11.2.2.1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.83.2.0.7B.0.38.1D.D.E3.0.3.FA.0.1.0.0.0.1.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.0.DE.57.F2.58.0.0.0.0 FF.FF.FF.FF.FF.FF.1.1.1.1.1.1.86.DD.60.8D.87.94.00.A6.FE.AE.87.8E.F1.F0.CD.AB.DC.C6.23.2E.B8.8C.15.C6.55.CE.4A.B2.D0.18.CB.F0.44.62.C1.25.73.0.D5.1A.42.CD.6C.3.31.12.5C.D4.24.B4.E2.36.27.59.79.71.BE.51.CC.99.4C.80.4E.80.3D.29.AB.D3.22.E5.A.E7.C5.6A.A6.B6.58.13.31.25.EE.25.73.0.94.7A.43.35.9C.CE.AF.FA.8C.2B.DD.44.D1.98.46.43.21.8C.80.5.E8.56.AE.5B.B2.75.C4.A9.25.73.0.C8.D5.86.AB.21.8A.F5.15.DD.F2.A2.DC.E4.4B.EE.75.6D.4E.C0.A.1D.FA.4B.D8.9A.4B.71.45.CC.6F.A3.3F.C2.19.9F.A3.ED.61.96.5F.8E.28.13.E6.FB.D2.EA.B3.4A.B3.ED.AA.67.4F.47.F0.3D.8.D0.9B.7C.68.2F.8D.28.25.73.0.6.5D.32.D.79.8.71.EA.E.1D.57.77.C5.95.2A.75.17.18.C8.AB.E8.6.FD.47.E.25.73.0.81.41.99.CE.C.B2.3F.18.5E.FD.9F.E5.CB.2E.2A.90.90.3D.B8.70.40.4F.67.6E.A5.93.A6.D5.0 FF.FF.FF.FF.FF.FF.1.1.1.1.1.1.86.DD.60.7F.20.FD.00.C6.32.28.58.4C.2E.AD.4D.BF.2A.8F.4.EF.E5.E9.B8.23.8B.33.E1.C5.2C.79.5A.B8.70.1E.D8.85.C.2D.EE.E9.57.EF.B5.A8.56.F2.E9.AA.17.63.7.1E.F8.10.52.9E.8B.F5.97.7F.6C.28.1.1D.98.1.9D.37.A4.66.82.D9.9A.37.D7.B.E.8F.8.25.73.0.F.F0.8E.CD.B2.CA.75.43.DA.E4.1A.42.38.C5.B5.5B.19.40.39.20.ED.3A.8.37.71.0.25.7D.53.49.17.E9.CA.2E.CC.F5.27.3.97.6C.8.FC.F5.64.81.AD.C3.4A.C5.3C.97.44.27.F7.D2.58.63.B5.8D.9A.CE.69.E3.9.3E.40.6D.91.2C.5B.A.4F.F3.86.C0.19.BD.CA.25.73.0.2E.1E.17.2C.54.E0.5E.1A.E2.2A.3D.99.23.46.5D.AE.50.81.D7.25.75.F6.70.E8.88.53.20.5D.16.22.28.80.5D.E0.48.4F.A3.2A.A.87.FB.F5.4.22.25.73.0.8D.6E.7E.D8.DF.2B.87.87.56.76.9B.F7.BD.7E.5C.3C.A3.84.EA.8E.79.A4.F7.20.E0.82.5C.94.1E.24 sll2.t100644001750001750 255415141002125 14677 0ustar00yanickyanick000000000000NetPacket-1.8.0/tuse strict; use warnings; use Test2::Bundle::More; use NetPacket::SLL2 qw/ :strip :types /; use NetPacket::Ethernet qw/ :types /; use NetPacket::ARP qw/ :protos /; my @test_data = ( {proto => ETH_TYPE_IP(), interface => 2, htype => ARPHRD_ETHER(), type => SLL_TYPE_SENT_BY_US(), src_addr => 'fedcba987654', data => "\x01\x02\x03\x04"}, ); my @datagrams = map { chomp; length($_) ? join('', map { chr hex } split /\./) : () } ; foreach my $datagram (@datagrams) { my $test = shift @test_data; my $sll = NetPacket::SLL2->decode($datagram); is $sll->{proto}, $test->{proto}, 'proto'; is $sll->{interface}, $test->{interface}, 'interface'; is $sll->{htype}, $test->{htype}, 'htype'; is $sll->{type}, $test->{type}, 'type'; is lc($sll->{src_addr}), $test->{src_addr}, 'src_addr'; is $sll->{data}, $test->{data}, 'data'; is sll2_strip($datagram), $test->{data}, 'strip'; my $q = NetPacket::SLL2->decode($sll->encode); is $q->{proto}, $sll->{proto}, 'round-trip proto'; is $q->{interface}, $sll->{interface}, 'round-trip interface'; is $q->{htype}, $sll->{htype}, 'round-trip htype'; is $q->{type}, $sll->{type}, 'round-trip type'; is lc($q->{src_addr}), lc($sll->{src_addr}), 'round-trip src_addr'; is $q->{data}, $sll->{data}, 'round-trip data'; } done_testing; __DATA__ 08.00.00.00.00.00.00.02.00.01.04.06.FE.DC.BA.98.76.54.00.00.01.02.03.04 doap.xml100644001750001750 2463015141002125 15057 0ustar00yanickyanick000000000000NetPacket-1.8.0 NetPacket assemble/disassemble network packets at the protocol level Tim Potter Stephanie Wehner Yanick Champoux Andreas Schwab Ben Magistro Dan Book Daniel Collins Dinar Valeev fschlich Lubomir Rintel Neil Bowers Nicolas R Robin Lee Stan Schwertly Stephanie Wehner Tim Potter Yanick Champoux Zak B. Elep 0.01 1999-04-24 0.03 2001-07-30 0.04 2003-05-21 0.41.0_0 2008-12-20 0.41.1 2009-01-06 0.42.0 2010-03-25 0.43.0 2010-05-23 0.43.1 2010-06-11 0.43.2 2010-10-11 1.0.0 2010-10-17 1.0.1 2010-10-19 1.1.0 2011-01-15 1.1.1 2011-02-07 1.1.2 2011-06-20 1.2.0 2011-07-26 1.3.0 2011-11-13 1.3.1 2011-11-23 1.3.2 2013-05-03 1.3.3 2013-05-15 1.4.0 2013-08-26 1.4.1 2013-09-05 1.4.2 2013-09-25 1.4.3 2013-10-03 1.4.4 2013-11-30 1.5.0 2014-06-15 1.6.0 2015-03-13 1.7.0 2018-12-30 1.7.1 2019-06-08 1.7.2 2019-07-20 Perl cpanfile100644001750001750 166615141002125 15102 0ustar00yanickyanick000000000000NetPacket-1.8.0# This file is generated by Dist::Zilla::Plugin::CPANFile v6.036 # Do not edit this file directly. To change prereqs, edit the `dist.ini` file. requires "Carp" => "0"; requires "Exporter" => "0"; requires "Socket" => "1.87"; requires "constant" => "0"; requires "parent" => "0"; requires "perl" => "v5.10.0"; requires "strict" => "0"; requires "warnings" => "0"; recommends "Net::Pcap" => "0"; recommends "Net::PcapUtils" => "0"; on 'test' => sub { requires "ExtUtils::MakeMaker" => "0"; requires "File::Spec" => "0"; requires "IO::Handle" => "0"; requires "IPC::Open3" => "0"; requires "Test2::Bundle::More" => "0"; requires "Test::More" => "0"; }; on 'test' => sub { recommends "CPAN::Meta" => "2.120900"; }; on 'configure' => sub { requires "ExtUtils::MakeMaker" => "0"; }; on 'develop' => sub { requires "Software::Security::Policy::Individual" => "0"; requires "Test::More" => "0.96"; requires "Test::Vars" => "0"; }; META.json100644001750001750 1053115141002125 15026 0ustar00yanickyanick000000000000NetPacket-1.8.0{ "abstract" : "assemble/disassemble network packets at the protocol level", "author" : [ "Tim Potter ", "Stephanie Wehner ", "Yanick Champoux " ], "dynamic_config" : 0, "generated_by" : "Dist::Zilla version 6.036, CPAN::Meta::Converter version 2.150010", "license" : [ "artistic_2" ], "meta-spec" : { "url" : "http://search.cpan.org/perldoc?CPAN::Meta::Spec", "version" : 2 }, "name" : "NetPacket", "prereqs" : { "configure" : { "requires" : { "ExtUtils::MakeMaker" : "0" } }, "develop" : { "requires" : { "Software::Security::Policy::Individual" : "0", "Test::More" : "0.96", "Test::Vars" : "0" } }, "runtime" : { "recommends" : { "Net::Pcap" : "0", "Net::PcapUtils" : "0" }, "requires" : { "Carp" : "0", "Exporter" : "0", "Socket" : "1.87", "constant" : "0", "parent" : "0", "perl" : "v5.10.0", "strict" : "0", "warnings" : "0" } }, "test" : { "recommends" : { "CPAN::Meta" : "2.120900" }, "requires" : { "ExtUtils::MakeMaker" : "0", "File::Spec" : "0", "IO::Handle" : "0", "IPC::Open3" : "0", "Test2::Bundle::More" : "0", "Test::More" : "0" } } }, "provides" : { "NetPacket" : { "file" : "lib/NetPacket.pm", "version" : "v1.8.0" }, "NetPacket::ARP" : { "file" : "lib/NetPacket/ARP.pm", "version" : "v1.8.0" }, "NetPacket::Ethernet" : { "file" : "lib/NetPacket/Ethernet.pm", "version" : "v1.8.0" }, "NetPacket::ICMP" : { "file" : "lib/NetPacket/ICMP.pm", "version" : "v1.8.0" }, "NetPacket::ICMPv6" : { "file" : "lib/NetPacket/ICMPv6.pm", "version" : "v1.8.0" }, "NetPacket::IGMP" : { "file" : "lib/NetPacket/IGMP.pm", "version" : "v1.8.0" }, "NetPacket::IP" : { "file" : "lib/NetPacket/IP.pm", "version" : "v1.8.0" }, "NetPacket::IPX" : { "file" : "lib/NetPacket/IPX.pm", "version" : "v1.8.0" }, "NetPacket::IPv6" : { "file" : "lib/NetPacket/IPv6.pm", "version" : "v1.8.0" }, "NetPacket::SLL" : { "file" : "lib/NetPacket/SLL.pm", "version" : "v1.8.0" }, "NetPacket::SLL2" : { "file" : "lib/NetPacket/SLL2.pm", "version" : "v1.8.0" }, "NetPacket::TCP" : { "file" : "lib/NetPacket/TCP.pm", "version" : "v1.8.0" }, "NetPacket::UDP" : { "file" : "lib/NetPacket/UDP.pm", "version" : "v1.8.0" }, "NetPacket::USBMon" : { "file" : "lib/NetPacket/USBMon.pm", "version" : "v1.8.0" } }, "release_status" : "stable", "resources" : { "bugtracker" : { "web" : "https://github.com/yanick/netpacket/issues" }, "homepage" : "https://github.com/yanick/netpacket", "repository" : { "type" : "git", "url" : "https://github.com/yanick/netpacket.git", "web" : "https://github.com/yanick/netpacket" } }, "version" : "1.8.0", "x_authority" : "cpan:YANICK", "x_contributor_covenant" : { "version" : 0.02 }, "x_contributors" : [ "Andreas Schwab ", "Ben Magistro ", "Dan Book ", "Daniel Collins ", "Dinar Valeev ", "fschlich ", "Lubomir Rintel ", "Neil Bowers ", "Nicolas R ", "Robin Lee ", "Stan Schwertly ", "Stephanie Wehner ", "Tim Potter ", "Yanick Champoux ", "Zak B. Elep " ], "x_generated_by_perl" : "v5.42.0", "x_serialization_backend" : "Cpanel::JSON::XS version 4.40", "x_spdx_expression" : "Artistic-2.0" } SIGNATURE100644001750001750 1160015141002125 14667 0ustar00yanickyanick000000000000NetPacket-1.8.0This file contains message digests of all files listed in MANIFEST, signed via the Module::Signature module, version 0.93. To verify the content in this distribution, first make sure you have Module::Signature installed, then type: % cpansign -v It will check each file's integrity, as well as the signature's validity. If "==> Signature verified OK! <==" is not displayed, the distribution may already have been compromised, and you should not run its Makefile.PL or Build.PL. -----BEGIN PGP SIGNED MESSAGE----- Hash: RIPEMD160 SHA256 1ce584e728bb778854e67611226d36db40afd0c82f1f1ce88d2c6f5230ddcc51 CODE_OF_CONDUCT.md SHA256 4ba228f6524df24352dd000c1b171c8a8344e5a145e98307a01791e77937ca45 CONTRIBUTING.md SHA256 bf1bfe92c0287044d28ed8c6f3fdec99e05e071059b9768451dfacfac8cdfdb7 CONTRIBUTORS SHA256 5b2c34a1da6c36226f0a7dbfe86cc6250ced7187c7e3058e5ca8c43aa031be8a Changes SHA256 ed3d19c114408b2503a4d97a1080b2e211c76cf0c8b181e8686d67ce72baf2af INSTALL SHA256 28527602ee5a54362ed5fa80d4a6baea4fe63e154c8ba47b576bb353b3c4c0cf LICENSE SHA256 7229e1dd19eab1570bba461c255b558293d3ffe7d43530fb9b2c021ee6ebd7c7 MANIFEST SHA256 82b6542b03de7095b28c3c81e2671da66058a46a9e71d3e0c1ab7c5b6453f3ca META.json SHA256 5b39d47de56881fac39ebd4b3fa4d0dffb40a9d4b3a254a1d6f4fa23f0061cb1 META.yml SHA256 106a066faa97e525a0aad6ab865768d1a0f9f6de96d21298c8485e7ed3f94b2b Makefile.PL SHA256 b1aa8fa7ba8c94167a180f6c77d273aeea368042f86346ca4fd04de5bb5ba719 README SHA256 0aa10163d0491feccd1af6115eee7a1d445444917414bd5ff492ab645db9d3bf README.mkdn SHA256 eb6eb4db46204d8980cd60d540d740fa27051b6243677045add469dcfb87fd2c SECURITY.md SHA256 0a64ecfc0e7629e2abf7cfa9f4f6fdd4b4e0cab4b0db85bce07f080861f9234a cpanfile SHA256 89ede9d8513173cc9ac02b7dacf600149ec5afeca12f508b7b06b8a34da61338 doap.xml SHA256 1f2449e8f63e2059b0ae04d76038edc34b182ed40daa8241463798bcdf34acd2 lib/NetPacket.pm SHA256 e6d4f8a2232dfb5d92f2e4bfe2512f0b26ad61ad8b915c54eebff99c24e9fde3 lib/NetPacket/ARP.pm SHA256 3e95ba37822974b2be78ec3f361664e39b778955f4f803bb84c874b87860b363 lib/NetPacket/Ethernet.pm SHA256 07f1557b4ae7686b9eb7a505a98bbb02b524c5d13dff1d688e5f15b60aa295e2 lib/NetPacket/ICMP.pm SHA256 515c93d85d5b910c1724f469e0a3f5bf42cd9e8b03e2ce2a9d11bbdf8f686c27 lib/NetPacket/ICMPv6.pm SHA256 209fe76b9c41afdfcace0f15bd5bbe1ac55e62a837b73750d76ac1c567392c6c lib/NetPacket/IGMP.pm SHA256 b57a7d67b202e2294377f4d0a6fe40833ea5ebedaa9759d4aee64a1133a2556d lib/NetPacket/IP.pm SHA256 8625a18be83a4ebb5d4ef15a579019e3a1f0d80c08896815afee0d0da791349c lib/NetPacket/IPX.pm SHA256 0f4ec1c3a0d5619c17f3feeaa5813bc0d9e6fc1e4011fcf9e1a941e8bb1b85a7 lib/NetPacket/IPv6.pm SHA256 d03d44a4e36956d29cdf71d184f8d49455abf3d873664c4e670fad3e8b74324f lib/NetPacket/SLL.pm SHA256 e1ea28211c18b87564b7cfb311b790bc6f57f2fc890a1c745efbf5bd92202e5e lib/NetPacket/SLL2.pm SHA256 d9fe0de0546a3ef3fb662f068b729d32e57a5856263d1b61531120187fc91d71 lib/NetPacket/TCP.pm SHA256 c34481e1dab073d6b04af5af9b85cb0c2db716a2b65fd01ebfc4ee468c4e1dbf lib/NetPacket/UDP.pm SHA256 3184d7ea1b112278fe521cc7c621fa7848910d081c1f498e991ac8a7840b2f68 lib/NetPacket/USBMon.pm SHA256 49ea4af31e9be9fa5f539b2253fb88c7414d76d1063f40d38e6a85ae8c2cad5f t/00-compile.t SHA256 1538f6e80a0c90c677cd13e2b0fe8e28ec378bc068c171714054dc7a9d25bfb8 t/00-report-prereqs.dd SHA256 5996417e8ae9973f82860dcf6d5f180d285d5c4b046e0346d06ed22802a3452b t/00-report-prereqs.t SHA256 216eefee239c30c58ed96199d4ef2e34d39d6a771c0561860d5f95b34f1ce64e t/bug-37931.t SHA256 8842361a256ffb2c6db6666972810e2e28987a0408a500aa6aa791ab565033ff t/checksum.t SHA256 bac411f916c3fda7245638db47018b63973fcb81ac17966d67e328b0b9e19bb6 t/ethernet.t SHA256 66cc619b75b15905e1054bb17858872153d0aa8794ef427565b058f4837a9e49 t/general.t SHA256 90c3afb4b7c73498d9fb5cc377695ce0be9a820096142af0ccae741293a4fdba t/icmp.t SHA256 fdab168a3a2603205c1d8ebbe1fb77688ba6dd3c86e809b2f0f94d2323151b22 t/icmpv6.t SHA256 d0d2a6d517a76021be564995aae90132fd10f18ee7d72f68fee78671bcad2957 t/ip_encode.t SHA256 8698121f55a599690f8e228f619a043d0275c4c8b05b929ad1d1db71f5d21105 t/ip_trailing.t SHA256 22af0ff3f81468828444d9d2275125b884026ab4e74bf4d3e615761c53c02b57 t/ipv6.t SHA256 f6b1d569936efff9da43c6b881d746b01944219aa55aa16d4d6b337b7d195365 t/ipx.t SHA256 789e36a358c68dc84ca2f5cd5adebd85a1613a5fcdec2e0b0fbc2e2b5a246401 t/sll.t SHA256 b3790c3e1c261fb15b03dfb7c434e33bdd54940df7113772017342541dbbce9f t/sll2.t SHA256 3ea211e530e72242b4367457fd437bcfa94ef1b44b2080da42b9214ca6d79dae t/tcp.t SHA256 5b232b30546f80b1d4d256b60feab0b0faa7aeea70ccf3f6c41116ed485c5602 t/udp-checksum.t SHA256 a009bf39d90a1cd248a6af46b1afe12e34e06fe6c08e8864c451d913e9c31e79 t/udp.t SHA256 fc3b0ee40c40c394503bf3ea2cee096eccf03ca1aa9609ae389eca7ba78a504f t/usbmon.t SHA256 d34f839d8340478663bd6ae59c72760d7e1a2b7a2d4879ad1ec97db1a2271b2f xt/release/unused-vars.t -----BEGIN PGP SIGNATURE----- iF0EAREDAB0WIQS4RMr2LZlyA/IlbHHfgfB/4bALjAUCaYQEVQAKCRDfgfB/4bAL jN+MAKC6Apq5cPRmRt27YAPpIK4fOAr6GACgmeydkzDRY9TvC/MeqpvMFlsqIVE= =NvVg -----END PGP SIGNATURE----- icmpv6.t100644001750001750 505215141002125 15223 0ustar00yanickyanick000000000000NetPacket-1.8.0/tuse strict; use warnings; use Test2::Bundle::More; use NetPacket::ICMPv6 qw(:types :codes); use NetPacket::IPv6; use NetPacket::Ethernet; my @test_data = ( { type => ICMPv6_ECHOREQ, code => 0, cksum => 39252, len => 60 }, { type => ICMPv6_ECHOREPLY, code => 0, cksum => 38996, len => 60 }, { type => ICMPv6_NEIGHBORSOLICIT, code => 0, cksum => 43237, len => 28 }, { type => ICMPv6_ROUTERSOLICIT, code => 0, cksum => 21054, len => 12 }, { type => ICMPv6_NEIGHBORADVERT, code => 0, cksum => 61573, len => 20 }, ); my @datagrams = map { chomp; length($_) ? join('', map { chr hex } split /\./) : () } ; foreach my $datagram (@datagrams) { my $test = shift @test_data; my $eth = NetPacket::Ethernet->decode( $datagram ); my $ipv6 = NetPacket::IPv6->decode( $eth->{data} ); my $icmpv6 = NetPacket::ICMPv6->decode( $ipv6->{data} ); is $icmpv6->{type} => $test->{type}, 'Right message type'; is $icmpv6->{code} => $test->{code}, 'Right message code'; is $icmpv6->{cksum} => $test->{cksum}, 'Right message checksum'; is length($icmpv6->{data}) => $test->{len}, 'Right message length'; my $q = NetPacket::ICMPv6->decode( $icmpv6->encode( $ipv6 ) ); is $q->{cksum}, $test->{cksum}, 'Recalculated message checksum'; foreach my $key (grep { !m/^_/ } keys %$icmpv6) { is_deeply $q->{$key}, $icmpv6->{$key}, "Round-trip $key"; } } done_testing; __DATA__ 0.0.5E.0.2.F0.FA.90.3C.6A.DB.7C.86.DD.60.0.0.0.0.40.3A.40.26.4.A8.80.8.0.0.A1.0.0.0.0.0.D9.60.1.26.7.F8.B0.40.6.8.19.0.0.0.0.0.0.20.E.80.0.99.54.5B.D9.0.1.4E.9D.AD.5A.0.0.0.0.9.A6.7.0.0.0.0.0.10.11.12.13.14.15.16.17.18.19.1A.1B.1C.1D.1E.1F.20.21.22.23.24.25.26.27.28.29.2A.2B.2C.2D.2E.2F.30.31.32.33.34.35.36.37 FA.90.3C.6A.DB.7C.5C.45.27.78.FB.30.86.DD.60.0.0.0.0.40.3A.39.26.7.F8.B0.40.6.8.19.0.0.0.0.0.0.20.E.26.4.A8.80.8.0.0.A1.0.0.0.0.0.D9.60.1.81.0.98.54.5B.D9.0.1.4E.9D.AD.5A.0.0.0.0.9.A6.7.0.0.0.0.0.10.11.12.13.14.15.16.17.18.19.1A.1B.1C.1D.1E.1F.20.21.22.23.24.25.26.27.28.29.2A.2B.2C.2D.2E.2F.30.31.32.33.34.35.36.37 0.0.5E.0.2.F0.FA.90.3C.6A.DB.7C.86.DD.60.0.0.0.0.20.3A.FF.FE.80.0.0.0.0.0.0.F8.90.3C.FF.FE.6A.DB.7C.26.4.A8.80.8.0.0.A1.0.0.0.0.0.0.0.1.87.0.A8.E5.0.0.0.0.26.4.A8.80.8.0.0.A1.0.0.0.0.0.0.0.1.1.1.FA.90.3C.6A.DB.7C 33.33.0.0.0.2.FE.90.3C.6A.DB.7C.86.DD.60.0.0.0.0.10.3A.FF.FE.80.0.0.0.0.0.0.FC.90.3C.FF.FE.6A.DB.7C.FF.2.0.0.0.0.0.0.0.0.0.0.0.0.0.2.85.0.52.3E.0.0.0.0.1.1.FE.90.3C.6A.DB.7C 0.0.5E.0.2.F0.FA.90.3C.6A.DB.7C.86.DD.60.0.0.0.0.18.3A.FF.26.4.A8.80.8.0.0.A1.0.0.0.0.0.D9.60.1.26.4.A8.80.8.0.0.A1.0.0.0.0.0.0.0.1.88.0.F0.85.40.0.0.0.26.4.A8.80.8.0.0.A1.0.0.0.0.0.D9.60.1 usbmon.t100644001750001750 1452715141002125 15351 0ustar00yanickyanick000000000000NetPacket-1.8.0/tuse strict; use warnings; use Test2::Bundle::More; use NetPacket::USBMon qw/:ALL/; my $frame; my $usbmon; # host -> device, GET DESCRIPTOR Request DEVICE $frame = binarize( <<'END_DATAGRAM' ); 40 21 9d fa 01 88 ff ff 53 02 80 0a 03 00 00 3c 48 e4 0c 52 00 00 00 00 2f d7 06 00 8d ff ff ff 28 00 00 00 00 00 00 00 80 06 00 01 00 00 28 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 END_DATAGRAM $usbmon = NetPacket::USBMon->decode( $frame ); #is $usbmon->{id} => 0xffff8801fa9d2140; is $usbmon->{type} => 'S'; is $usbmon->{xfer_type} => USB_XFER_TYPE_CONTROL; is $usbmon->{ep}{num} => 0; is $usbmon->{ep}{dir} => 'IN'; is $usbmon->{devnum} => 10; is $usbmon->{busnum} => 3; is $usbmon->{flag_setup} => USB_FLAG_SETUP_RELEVANT; is $usbmon->{ts_sec} => 1376576584; is $usbmon->{ts_usec} => 448303; is $usbmon->{status} => -115; is $usbmon->{length} => 40; is $usbmon->{len_cap} => 0; is $usbmon->{xfer_flags} => 0x200; is $usbmon->{data} => ''; # device -> host, GET DESCRIPTOR Response DEVICE $frame = binarize( <<'END_DATAGRAM' ); 40 21 9d fa 01 88 ff ff 43 02 80 0a 03 00 2d 00 48 e4 0c 52 00 00 00 00 24 db 06 00 00 00 00 00 12 00 00 00 12 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 02 00 00 00 00 00 00 12 01 00 02 00 00 00 40 71 1b 02 30 00 01 03 04 02 01 END_DATAGRAM $usbmon = NetPacket::USBMon->decode( $frame ); is $usbmon->{type} => 'C'; is $usbmon->{xfer_type} => USB_XFER_TYPE_CONTROL; is $usbmon->{ep}{num} => 0; is $usbmon->{ep}{dir} => 'IN'; is $usbmon->{devnum} => 10; is $usbmon->{busnum} => 3; is $usbmon->{flag_setup} => USB_FLAG_SETUP_IRRELEVANT; is $usbmon->{ts_sec} => 1376576584; is $usbmon->{ts_usec} => 449316; is $usbmon->{status} => 0; is $usbmon->{length} => 18; is $usbmon->{len_cap} => 18; is $usbmon->{xfer_flags} => 512; is length $usbmon->{data} => $usbmon->{len_cap}; # host -> device, SET INTERFACE Request $frame = binarize( <<'END_DATAGRAM' ); 00 2b 9d fa 01 88 ff ff 53 02 00 0a 03 00 00 00 65 e4 0c 52 00 00 00 00 23 62 07 00 8d ff ff ff 00 00 00 00 00 00 00 00 40 0c 01 00 08 c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 END_DATAGRAM $usbmon = NetPacket::USBMon->decode( $frame ); is $usbmon->{type} => 'S'; is $usbmon->{xfer_type} => USB_XFER_TYPE_CONTROL; is $usbmon->{ep}{num} => 0; is $usbmon->{ep}{dir} => 'OUT'; is $usbmon->{devnum} => 10; is $usbmon->{busnum} => 3; is $usbmon->{flag_setup} => USB_FLAG_SETUP_RELEVANT; is $usbmon->{ts_sec} => 1376576613; is $usbmon->{ts_usec} => 483875; is $usbmon->{status} => -115; is $usbmon->{length} => 0; is $usbmon->{len_cap} => 0; is $usbmon->{xfer_flags} => 0; is $usbmon->{data} => ''; is $usbmon->{setup}{bmRequestType} => USB_TYPE_VENDOR; is $usbmon->{setup}{bRequest} => 12; is $usbmon->{setup}{wIndex} => 49160; is $usbmon->{setup}{wLength} => 0; is $usbmon->{setup}{wValue} => 1; # device -> host, SET INTERFACE Response $frame = binarize( <<'END_DATAGRAM' ); 00 2b 9d fa 01 88 ff ff 43 02 00 0a 03 00 2d 3e 65 e4 0c 52 00 00 00 00 ae 61 07 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 END_DATAGRAM $usbmon = NetPacket::USBMon->decode( $frame ); is $usbmon->{type} => 'C'; is $usbmon->{xfer_type} => USB_XFER_TYPE_CONTROL; is $usbmon->{ep}{num} => 0; is $usbmon->{ep}{dir} => 'OUT'; is $usbmon->{devnum} => 10; is $usbmon->{busnum} => 3; is $usbmon->{flag_setup} => USB_FLAG_SETUP_IRRELEVANT; is $usbmon->{ts_sec} => 1376576613; is $usbmon->{ts_usec} => 483758; is $usbmon->{status} => 0; is $usbmon->{length} => 0; is $usbmon->{len_cap} => 0; is $usbmon->{xfer_flags} => 0; is $usbmon->{data} => ''; # host -> device, URB_CONTROL out $frame = binarize( <<'END_DATAGRAM' ); 00 2b 9d fa 01 88 ff ff 53 02 00 0a 03 00 00 00 65 e4 0c 52 00 00 00 00 23 62 07 00 8d ff ff ff 00 00 00 00 00 00 00 00 40 0c 01 00 08 c0 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 END_DATAGRAM $usbmon = NetPacket::USBMon->decode( $frame ); is $usbmon->{type} => 'S'; is $usbmon->{xfer_type} => USB_XFER_TYPE_CONTROL; is $usbmon->{ep}{num} => 0; is $usbmon->{ep}{dir} => 'OUT'; is $usbmon->{devnum} => 10; is $usbmon->{busnum} => 3; is $usbmon->{flag_setup} => USB_FLAG_SETUP_RELEVANT; is $usbmon->{ts_sec} => 1376576613; is $usbmon->{ts_usec} => 483875; is $usbmon->{status} => -115; is $usbmon->{length} => 0; is $usbmon->{len_cap} => 0; is $usbmon->{xfer_flags} => 0; is $usbmon->{data} => ''; # device -> host, URB_CONTROL out $frame = binarize( <<'END_DATAGRAM' ); 00 2b 9d fa 01 88 ff ff 43 02 00 0a 03 00 2d 3e 65 e4 0c 52 00 00 00 00 1e 64 07 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 00 END_DATAGRAM $usbmon = NetPacket::USBMon->decode( $frame ); is $usbmon->{type} => 'C'; is $usbmon->{xfer_type} => USB_XFER_TYPE_CONTROL; is $usbmon->{ep}{num} => 0; is $usbmon->{ep}{dir} => 'OUT'; is $usbmon->{devnum} => 10; is $usbmon->{busnum} => 3; is $usbmon->{flag_setup} => USB_FLAG_SETUP_IRRELEVANT; is $usbmon->{ts_sec} => 1376576613; is $usbmon->{ts_usec} => 484382; is $usbmon->{status} => 0; is $usbmon->{length} => 0; is $usbmon->{len_cap} => 0; is $usbmon->{xfer_flags} => 0; is $usbmon->{data} => ''; # host -> device, URB_ISOCHRONOUS in $frame = binarize( <<'END_DATAGRAM' ); 00 ce 6b 19 01 88 ff ff 53 00 81 0a 03 00 2d 3c 65 e4 0c 52 00 00 00 00 be 16 08 00 8d ff ff ff 00 60 00 00 80 00 00 00 00 00 00 00 08 00 00 00 01 00 00 00 00 00 00 00 02 02 00 00 08 00 00 00 ee ff ff ff 00 00 00 00 00 0c 00 00 00 00 00 00 ee ff ff ff 00 0c 00 00 00 0c 00 00 00 00 00 00 ee ff ff ff 00 18 00 00 00 0c 00 00 00 00 00 00 ee ff ff ff 00 24 00 00 00 0c 00 00 00 00 00 00 ee ff ff ff 00 30 00 00 00 0c 00 00 00 00 00 00 ee ff ff ff 00 3c 00 00 00 0c 00 00 00 00 00 00 ee ff ff ff 00 48 00 00 00 0c 00 00 00 00 00 00 ee ff ff ff 00 54 00 00 00 0c 00 00 00 00 00 00 END_DATAGRAM $usbmon = NetPacket::USBMon->decode( $frame ); is $usbmon->{type} => 'S'; is $usbmon->{xfer_type} => USB_XFER_TYPE_ISO; is $usbmon->{ep}{num} => 1; is $usbmon->{ep}{dir} => 'IN'; is $usbmon->{devnum} => 10; is $usbmon->{busnum} => 3; is $usbmon->{flag_setup} => USB_FLAG_SETUP_IRRELEVANT; is $usbmon->{ts_sec} => 1376576613; is $usbmon->{ts_usec} => 530110; is $usbmon->{status} => -115; is $usbmon->{length} => 24576; is $usbmon->{len_cap} => 128; is $usbmon->{xfer_flags} => 514; is length $usbmon->{data} => $usbmon->{len_cap}; # Copied from t/tcp.t, uglified. sub binarize { return join '' => map { chr hex } split ' ', shift; } done_testing; Makefile.PL100644001750001750 311615141002125 15340 0ustar00yanickyanick000000000000NetPacket-1.8.0# This file was automatically generated by Dist::Zilla::Plugin::MakeMaker v6.036. use strict; use warnings; use 5.010000; use ExtUtils::MakeMaker; my %WriteMakefileArgs = ( "ABSTRACT" => "assemble/disassemble network packets at the protocol level", "AUTHOR" => "Tim Potter , Stephanie Wehner , Yanick Champoux ", "CONFIGURE_REQUIRES" => { "ExtUtils::MakeMaker" => 0 }, "DISTNAME" => "NetPacket", "LICENSE" => "artistic_2", "MIN_PERL_VERSION" => "5.010000", "NAME" => "NetPacket", "PREREQ_PM" => { "Carp" => 0, "Exporter" => 0, "Socket" => "1.87", "constant" => 0, "parent" => 0, "strict" => 0, "warnings" => 0 }, "TEST_REQUIRES" => { "ExtUtils::MakeMaker" => 0, "File::Spec" => 0, "IO::Handle" => 0, "IPC::Open3" => 0, "Test2::Bundle::More" => 0, "Test::More" => 0 }, "VERSION" => "1.8.0", "test" => { "TESTS" => "t/*.t" } ); my %FallbackPrereqs = ( "Carp" => 0, "Exporter" => 0, "ExtUtils::MakeMaker" => 0, "File::Spec" => 0, "IO::Handle" => 0, "IPC::Open3" => 0, "Socket" => "1.87", "Test2::Bundle::More" => 0, "Test::More" => 0, "constant" => 0, "parent" => 0, "strict" => 0, "warnings" => 0 ); unless ( eval { ExtUtils::MakeMaker->VERSION(6.63_03) } ) { delete $WriteMakefileArgs{TEST_REQUIRES}; delete $WriteMakefileArgs{BUILD_REQUIRES}; $WriteMakefileArgs{PREREQ_PM} = \%FallbackPrereqs; } delete $WriteMakefileArgs{CONFIGURE_REQUIRES} unless eval { ExtUtils::MakeMaker->VERSION(6.52) }; WriteMakefile(%WriteMakefileArgs); README.mkdn100644001750001750 660015141002125 15177 0ustar00yanickyanick000000000000NetPacket-1.8.0# NAME NetPacket - assemble/disassemble network packets at the protocol level # VERSION version 1.8.0 # SYNOPSIS ``` # NetPacket is a base class only ``` # DESCRIPTION `NetPacket` provides a base class for a cluster of modules related to decoding and encoding of network protocols. Each `NetPacket` descendent module knows how to encode and decode packets for the network protocol it implements. Consult the documentation for the module in question for protocol-specific implementation. Note that there is no inheritance in the `NetPacket::` cluster of modules other than each protocol module being a `NetPacket`. This was seen to be too restrictive as imposing inheritance relationships (for example between the IP, UDP and TCP protocols) would make things like tunneling or other unusual situations difficult. # WRITING YOUR OWN `NetPacket::` MODULE You are encouraged to write additional `NetPacket::` modules as well as improve existing ones. Contact the maintainer of the module in question with your suggestions or changes. The following sections are a list of suggestions and conventions for writing a `NetPacket::` module. ## Naming Conventions When creating a module in the `NetPacket::` namespace, it is suggested that you stick to a couple of conventions when naming packet contents. This will hopefully lead to a consistent namespace making the `NetPacket::` easier to use. Content names are all lowercase, with underscores separating multiple words. The following abbreviations are recommended: ``` Word Abbreviation -------------------------------- source src destination dest checksum cksum identifier id version ver protocol proto ``` ## Required Methods encode(), decode(), strip() ## Required Fields Every NetPacket:: object should have the following fields. - \_parent A link to the parent `NetPacket::` object in which this `NetPacket::` object is encaulated. This field is undefined if there is no parent object. - \_frame A copy of the raw data of the packet. - data This field should contain the data encapsulated in the packet (i.e any headers or trailers stripped off) or undef if the packet contains no data. Note that in this sense, "data" is taken to mean information not relevant to the particular protocol being decoded. For example, an ARP packet contains many header fields but no data. A UDP datagram, however contains header fields and a payload. # SEE ALSO Joel Knight has a patch for NetPacket for IPv6 support available at http://www.packetmischief.ca/code/netpacket/. # COPYRIGHT AND LICENSE Copyright (c) 2001 Tim Potter and Stephanie Wehner. Copyright (c) 1995,1996,1997,1998,1999 ANU and CSIRO on behalf of the participants in the CRC for Advanced Computational Systems ('ACSys'). This module is free software. You can redistribute it and/or modify it under the terms of the Artistic License 2.0. This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. # AUTHORS Tim Potter Stephanie Wehner Yanick Champoux [![endorse](http://api.coderwall.com/yanick/endorsecount.png)](http://coderwall.com/yanick) general.t100644001750001750 40315141002125 15407 0ustar00yanickyanick000000000000NetPacket-1.8.0/tuse strict; use warnings; use Test2::Bundle::More; use NetPacket::UDP; use NetPacket; use NetPacket::ARP; use NetPacket::Ethernet; use NetPacket::ICMP; use NetPacket::IGMP; use NetPacket::IP; use NetPacket::TCP; use NetPacket::USBMon; pass; done_testing; SECURITY.md100644001750001750 1010315141002125 15171 0ustar00yanickyanick000000000000NetPacket-1.8.0# Security Policy for the NetPacket distribution. Report security issues by email to Tim Potter , Stephanie Wehner , Yanick Champoux . This is the Security Policy for NetPacket. This text is based on the CPAN Security Group's Guidelines for Adding a Security Policy to Perl Distributions (version 1.3.0) https://security.metacpan.org/docs/guides/security-policy-for-authors.html # How to Report a Security Vulnerability Security vulnerabilities can be reported to the current NetPacket maintainers by email to Tim Potter , Stephanie Wehner , Yanick Champoux . Please include as many details as possible, including code samples or test cases, so that we can reproduce the issue. Check that your report does not expose any sensitive data, such as passwords, tokens, or personal information. If you would like any help with triaging the issue, or if the issue is being actively exploited, please copy the report to the CPAN Security Group (CPANSec) at . Please *do not* use the public issue reporting system on RT or GitHub issues for reporting security vulnerabilities. Please do not disclose the security vulnerability in public forums until past any proposed date for public disclosure, or it has been made public by the maintainers or CPANSec. That includes patches or pull requests. For more information, see [Report a Security Issue](https://security.metacpan.org/docs/report.html) on the CPANSec website. ## Response to Reports The maintainer(s) aim to acknowledge your security report as soon as possible. However, this project is maintained by a single person in their spare time, and they cannot guarantee a rapid response. If you have not received a response from them within 1 month, then please send a reminder to them and copy the report to CPANSec at . Please note that the initial response to your report will be an acknowledgement, with a possible query for more information. It will not necessarily include any fixes for the issue. The project maintainer(s) may forward this issue to the security contacts for other projects where we believe it is relevant. This may include embedded libraries, system libraries, prerequisite modules or downstream software that uses this software. They may also forward this issue to CPANSec. # Which Software This Policy Applies To Any security vulnerabilities in NetPacket are covered by this policy. Security vulnerabilities in versions of any libraries that are included in NetPacket are also covered by this policy. Security vulnerabilities are considered anything that allows users to execute unauthorised code, access unauthorised resources, or to have an adverse impact on accessibility or performance of a system. Security vulnerabilities in upstream software (prerequisite modules or system libraries, or in Perl), are not covered by this policy unless they affect NetPacket, or NetPacket can be used to exploit vulnerabilities in them. Security vulnerabilities in downstream software (any software that uses NetPacket, or plugins to it that are not included with the NetPacket distribution) are not covered by this policy. ## Supported Versions of NetPacket The maintainer(s) will only commit to releasing security fixes for the latest version of NetPacket. Note that the NetPacket project only supports major versions of Perl released in the past 5 years, even though NetPacket will run on older versions of Perl. If a security fix requires us to increase the minimum version of Perl that is supported, then we may do so. # Installation and Usage Issues The distribution metadata specifies minimum versions of prerequisites that are required for NetPacket to work. However, some of these prerequisites may have security vulnerabilities, and you should ensure that you are using up-to-date versions of these prerequisites. Where security vulnerabilities are known, the metadata may indicate newer versions as recommended. ## Usage Please see the software documentation for further information. CONTRIBUTORS100644001750001750 102515141002125 15243 0ustar00yanickyanick000000000000NetPacket-1.8.0 # NETPACKET CONTRIBUTORS # This is the (likely incomplete) list of people who have helped make this distribution what it is, either via code contributions, patches, bug reports, help with troubleshooting, etc. A huge 'thank you' to all of them. * Andreas Schwab * Ben Magistro * Dan Book * Daniel Collins * Dinar Valeev * fschlich * Lubomir Rintel * Neil Bowers * Nicolas R * Robin Lee * Stan Schwertly * Stephanie Wehner * Tim Potter * Yanick Champoux * Zak B. Elep checksum.t100644001750001750 135715141002125 15625 0ustar00yanickyanick000000000000NetPacket-1.8.0/tuse strict; use warnings; use Test2::Bundle::More; use NetPacket::TCP; use NetPacket::UDP; my $ip = { src_ip => '127.0.0.1', dest_ip => '192.168.0.1', }; bless $ip, 'NetPacket::IP'; my $tcp = { dest_port => 22, src_port => 13, seqnum => 1, acknum => 2, winsize => 32, urg => 0, hlen => 5, data => "DEADBEEF", }; bless $tcp, 'NetPacket::TCP'; is NetPacket::TCP::checksum( $tcp, $ip ) => 25303; $tcp->{data} = "DEADBEEF\x01"; my $odd_checksum = NetPacket::TCP::checksum( $tcp, $ip ); is $odd_checksum => 25046, 'TCP padding done correctly'; my $udp = { src_port => 13, dest_port => 14, len => 15, data => "foo", }; bless $udp, 'NetPacket::UDP'; is NetPacket::UDP::checksum( $udp, $ip ) => 60058, 'UDP padding'; done_testing; ethernet.t100644001750001750 105415141002125 15633 0ustar00yanickyanick000000000000NetPacket-1.8.0/tuse strict; use warnings; use Test2::Bundle::More; use NetPacket::Ethernet qw/ :types /; is ETH_TYPE_PPPOES() => 0x8864, 'imports'; is NetPacket::Ethernet::ETH_TYPE_IP() => 0x0800, 'with namespace'; subtest "don't invert the mac ports" => sub { my $packet = NetPacket::Ethernet->decode( NetPacket::Ethernet::encode({ src_mac => '001', dest_mac => '002', data => '', }) ); like $packet->{src_mac}, qr'001', 'src_mac'; like $packet->{dest_mac}, qr'002', 'dest_mac'; }; done_testing; bug-37931.t100644001750001750 61415141002125 15237 0ustar00yanickyanick000000000000NetPacket-1.8.0/tuse strict; use warnings; use Test2::Bundle::More; use NetPacket::ICMP ':ALL'; ok ICMP_MASKREQ(), "ICMP_MASKRED defined"; done_testing; __END__ =pod Subject: NetPacket::ICMP has an export typo on ICMP_MASKREQ I found a typo in NetPacket::ICMP: > use constant ICMP_MASKREQ => 17; This constant is exported and documented as ICMP_MASREQ, making it unusable as an exported method. =cut ip_encode.t100644001750001750 110115141002125 15733 0ustar00yanickyanick000000000000NetPacket-1.8.0/tuse strict; use warnings; use Test2::Bundle::More; use NetPacket::IP; use NetPacket::Ethernet; my $datagram = join '', map { chr } split ':', join ':' => ; my $eth = NetPacket::Ethernet->decode( $datagram ); my $ip = NetPacket::IP->decode( $eth->{data} ); is $ip->{flags} => 2; my $q = NetPacket::IP->decode( $ip->encode ); is $q->{flags} => $ip->{flags}; done_testing; __DATA__ 0:25:209:6:219:108:0:19:163:164:237:251:8:0:69:0:0:46 174:1:64:0:56:6:248:228:96:6:121:42:192:168:2:11:0:80 17:185:251:228:155:131:197:211:72:2:80:16:30:230:61:189 0:0:0:0:0:0:0:0 00-compile.t100644001750001750 331615141002125 15665 0ustar00yanickyanick000000000000NetPacket-1.8.0/tuse strict; use warnings; # this test was generated with Dist::Zilla::Plugin::Test::Compile 2.059 use Test::More; plan tests => 14 + ($ENV{AUTHOR_TESTING} ? 1 : 0); my @module_files = ( 'NetPacket.pm', 'NetPacket/ARP.pm', 'NetPacket/Ethernet.pm', 'NetPacket/ICMP.pm', 'NetPacket/ICMPv6.pm', 'NetPacket/IGMP.pm', 'NetPacket/IP.pm', 'NetPacket/IPX.pm', 'NetPacket/IPv6.pm', 'NetPacket/SLL.pm', 'NetPacket/SLL2.pm', 'NetPacket/TCP.pm', 'NetPacket/UDP.pm', 'NetPacket/USBMon.pm' ); # no fake home requested my @switches = ( -d 'blib' ? '-Mblib' : '-Ilib', ); use File::Spec; use IPC::Open3; use IO::Handle; open my $stdin, '<', File::Spec->devnull or die "can't open devnull: $!"; my @warnings; for my $lib (@module_files) { # see L my $stderr = IO::Handle->new; diag('Running: ', join(', ', map { my $str = $_; $str =~ s/'/\\'/g; q{'}.$str.q{'} } $^X, @switches, '-e', "require q[$lib]")) if $ENV{PERL_COMPILE_TEST_DEBUG}; my $pid = open3($stdin, '>&STDERR', $stderr, $^X, @switches, '-e', "require q[$lib]"); binmode $stderr, ':crlf' if $^O eq 'MSWin32'; my @_warnings = <$stderr>; waitpid($pid, 0); is($?, 0, "$lib loaded ok"); shift @_warnings if @_warnings and $_warnings[0] =~ /^Using .*\bblib/ and not eval { +require blib; blib->VERSION('1.01') }; if (@_warnings) { warn @_warnings; push @warnings, @_warnings; } } is(scalar(@warnings), 0, 'no warnings found') or diag 'got warnings: ', ( Test::More->can('explain') ? Test::More::explain(\@warnings) : join("\n", '', @warnings) ) if $ENV{AUTHOR_TESTING}; CONTRIBUTING.md100644001750001750 433515141002125 15623 0ustar00yanickyanick000000000000NetPacket-1.8.0 # Contributing to NetPacket So you want to contribute to this package? Or fork it? Or play with it, or whatever? Excellent! Here, let me try to make it easier for you. ## Dist::Zilla and branch structure This package, like many of mine, uses [Dist::Zilla](https://metacpan.org/dist/Dist-Zilla). Dist::Zilla (`dzil` to its friends) is a distribution builder that helps (tremendously) with the nitty gritty of grooming and releasing packages to CPAN. It tidies up the documentation, add boilerplate files, update versions, and... do a *bunch* of other things. Because it does so much, it can be scary for some people. But it really doesn't need to be. This repository has two core branches: * `main` -- the working branch, holding the pre-dzil-munging code. * `releases` -- contains the dzil-munged code released to CPAN. Which means that if you don't want to bother with Dist::Zilla at all, checkout `releases` and work on it. Since it's the "real" code that made it to CPAN, all it working -- the package itself, the tests, everything. And totally feel free to use this branch as a base for a PR. I'll be very grateful for the work, and I'll take on the last step of porting the patching to `main`, noooo problem. ### I'm brave, I want to be on `main` Good for you! The good news is that dzil mostly tinker with stuff the working code doesn't care about, so you probably won't have to do anything special. In most cases, tinkering with the code will look like: $ cpanm --installdeps . $ ... tinker, tinker ... $ prove -l t Now, if you want to generate the CPAN-ready tarball, or go full YANICK on things. You'll have to install both Dist::Zilla and my plugin bundle: $ cpanm Dist::Zilla Dist::Zilla::PluginBundle::YANICK and then you should be able to do all things dzilly; # generate the tarball $ dzil build # run all the tests on the final code $ dzil test Now, a honest caveat: `Dist::Zilla::PluginBundle::YANICK` is tailored to my exact needs; it does a lot, and some of it is not guaranteed to work on somebody else's system. If you try to use it and you hit something weird, just let me know, and I'll do my best to help you. Aaaand that's pretty all I think you need to get started. Good luck! :-) ip_trailing.t100644001750001750 113215141002125 16313 0ustar00yanickyanick000000000000NetPacket-1.8.0/t#!/usr/bin/perl use strict; use warnings; use Test2::Bundle::More; #use Data::Dumper; use NetPacket::IP; my $raw_packet = <decode($raw_packet); #warn Dumper $ip; is length $ip->{data}, $ip->{len}- $ip->{hlen}*4; done_testing; lib000755001750001750 015141002125 13773 5ustar00yanickyanick000000000000NetPacket-1.8.0NetPacket.pm100644001750001750 1107315141002125 16371 0ustar00yanickyanick000000000000NetPacket-1.8.0/libpackage NetPacket; our $AUTHORITY = 'cpan:YANICK'; # ABSTRACT: assemble/disassemble network packets at the protocol level $NetPacket::VERSION = '1.8.0'; use strict; use warnings; use parent 'Exporter'; our @EXPORT_OK = qw(in_cksum htons htonl ntohs ntohl); our %EXPORT_TAGS = ( ALL => \@EXPORT_OK ); # # Utility functions useful for all modules # # Calculate IP checksum sub in_cksum { my ($packet) = @_; my ($plen, $short, $num, $count, $chk); $plen = length($packet); $num = int($plen / 2); $chk = 0; $count = $plen; foreach $short (unpack("S$num", $packet)) { $chk += $short; $count = $count - 2; } if($count == 1) { $chk += unpack("C", substr($packet, $plen -1, 1)); } # add the two halves together (CKSUM_CARRY -> libnet) $chk = ($chk >> 16) + ($chk & 0xffff); return(~(($chk >> 16) + $chk) & 0xffff); } # Network/host byte order conversion routines. Network byte order is # defined as being big-endian. sub htons { my ($in) = @_; return(unpack('n*', pack('S*', $in))); } sub htonl { my ($in) = @_; return(unpack('N*', pack('L*', $in))); } sub ntohl { my ($in) = @_; return(unpack('L*', pack('N*', $in))); } sub ntohs { my ($in) = @_; return(unpack('S*', pack('n*', $in))); } # # Module initialisation # 1; __END__ =pod =head1 NAME NetPacket - assemble/disassemble network packets at the protocol level =head1 VERSION version 1.8.0 =head1 SYNOPSIS # NetPacket is a base class only =head1 DESCRIPTION C provides a base class for a cluster of modules related to decoding and encoding of network protocols. Each C descendent module knows how to encode and decode packets for the network protocol it implements. Consult the documentation for the module in question for protocol-specific implementation. Note that there is no inheritance in the C cluster of modules other than each protocol module being a C. This was seen to be too restrictive as imposing inheritance relationships (for example between the IP, UDP and TCP protocols) would make things like tunneling or other unusual situations difficult. =head1 WRITING YOUR OWN C MODULE You are encouraged to write additional C modules as well as improve existing ones. Contact the maintainer of the module in question with your suggestions or changes. The following sections are a list of suggestions and conventions for writing a C module. =head2 Naming Conventions When creating a module in the C namespace, it is suggested that you stick to a couple of conventions when naming packet contents. This will hopefully lead to a consistent namespace making the C easier to use. Content names are all lowercase, with underscores separating multiple words. The following abbreviations are recommended: Word Abbreviation -------------------------------- source src destination dest checksum cksum identifier id version ver protocol proto =head2 Required Methods encode(), decode(), strip() =head2 Required Fields Every NetPacket:: object should have the following fields. =over =item _parent A link to the parent C object in which this C object is encaulated. This field is undefined if there is no parent object. =item _frame A copy of the raw data of the packet. =item data This field should contain the data encapsulated in the packet (i.e any headers or trailers stripped off) or undef if the packet contains no data. Note that in this sense, "data" is taken to mean information not relevant to the particular protocol being decoded. For example, an ARP packet contains many header fields but no data. A UDP datagram, however contains header fields and a payload. =back =head1 SEE ALSO Joel Knight has a patch for NetPacket for IPv6 support available at http://www.packetmischief.ca/code/netpacket/. =head1 COPYRIGHT AND LICENSE Copyright (c) 2001 Tim Potter and Stephanie Wehner. Copyright (c) 1995,1996,1997,1998,1999 ANU and CSIRO on behalf of the participants in the CRC for Advanced Computational Systems ('ACSys'). This module is free software. You can redistribute it and/or modify it under the terms of the Artistic License 2.0. This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. =head1 AUTHORS Tim Potter Stephanie Wehner Yanick Champoux =cut udp-checksum.t100644001750001750 212115141002125 16401 0ustar00yanickyanick000000000000NetPacket-1.8.0/t use Test2::Bundle::More; my $data = <<'END_DATA'; 01005e2a2501003048770072080045000110000040000111cccc53a6443fef2a25017 d5a7d5a00fc7d37050000f40000010ff30f804100160000000022482ac57077827dd9 0000010ff30f804100076b65737472616c00067379736d6f6e000a4469736b4672656 52e2f6d000773000c70657263656e742d757365646640fef86073000b7061636b6574 2d74797065690000000073000b6465736372697074696f6e7300154469736b2053706 16365207374617469737469637373000d7570646174652d706572696f647100000000 000493e073000a62797465732d66726565710000002248a1800073000e726573756c7 42d6d6573736167657300077375636365737373000e6d65676162797465732d667265 6571000000000002248a END_DATA $data =~ s/\s+//g; # remove all spaces my $datagram = join "", map { chr hex } $data =~ /(..)/g; use NetPacket::Ethernet; use NetPacket::IP; use NetPacket::UDP; my $pkt = NetPacket::Ethernet->decode($datagram); my $ip_pkt = NetPacket::IP->decode( $pkt->{data} ); $pkt = NetPacket::UDP->decode( $ip_pkt->{data} ); is $pkt->{cksum} => 32055, 'original checksum'; $pkt->checksum($ip_pkt); is $pkt->{cksum} => 32055, 're-computed checksum'; done_testing; CODE_OF_CONDUCT.md100644001750001750 1214015141002125 16202 0ustar00yanickyanick000000000000NetPacket-1.8.0# Contributor Covenant Code of Conduct ## Our Pledge We as members, contributors, and leaders pledge to make participation in our community a harassment-free experience for everyone, regardless of age, body size, visible or invisible disability, ethnicity, sex characteristics, gender identity and expression, level of experience, education, socio-economic status, nationality, personal appearance, race, religion, or sexual identity and orientation. We pledge to act and interact in ways that contribute to an open, welcoming, diverse, inclusive, and healthy community. ## Our Standards Examples of behavior that contributes to a positive environment for our community include: * Demonstrating empathy and kindness toward other people * Being respectful of differing opinions, viewpoints, and experiences * Giving and gracefully accepting constructive feedback * Accepting responsibility and apologizing to those affected by our mistakes, and learning from the experience * Focusing on what is best not just for us as individuals, but for the overall community Examples of unacceptable behavior include: * The use of sexualized language or imagery, and sexual attention or advances of any kind * Trolling, insulting or derogatory comments, and personal or political attacks * Public or private harassment * Publishing others' private information, such as a physical or email address, without their explicit permission * Other conduct which could reasonably be considered inappropriate in a professional setting ## Enforcement Responsibilities Community leaders are responsible for clarifying and enforcing our standards of acceptable behavior and will take appropriate and fair corrective action in response to any behavior that they deem inappropriate, threatening, offensive, or harmful. Community leaders have the right and responsibility to remove, edit, or reject comments, commits, code, wiki edits, issues, and other contributions that are not aligned to this Code of Conduct, and will communicate reasons for moderation decisions when appropriate. ## Scope This Code of Conduct applies within all community spaces, and also applies when an individual is officially representing the community in public spaces. Examples of representing our community include using an official e-mail address, posting via an official social media account, or acting as an appointed representative at an online or offline event. ## Enforcement Instances of abusive, harassing, or otherwise unacceptable behavior may be reported to the community leaders responsible for enforcement at tpot@samba.org. All complaints will be reviewed and investigated promptly and fairly. All community leaders are obligated to respect the privacy and security of the reporter of any incident. ## Enforcement Guidelines Community leaders will follow these Community Impact Guidelines in determining the consequences for any action they deem in violation of this Code of Conduct: ### 1. Correction **Community Impact**: Use of inappropriate language or other behavior deemed unprofessional or unwelcome in the community. **Consequence**: A private, written warning from community leaders, providing clarity around the nature of the violation and an explanation of why the behavior was inappropriate. A public apology may be requested. ### 2. Warning **Community Impact**: A violation through a single incident or series of actions. **Consequence**: A warning with consequences for continued behavior. No interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, for a specified period of time. This includes avoiding interactions in community spaces as well as external channels like social media. Violating these terms may lead to a temporary or permanent ban. ### 3. Temporary Ban **Community Impact**: A serious violation of community standards, including sustained inappropriate behavior. **Consequence**: A temporary ban from any sort of interaction or public communication with the community for a specified period of time. No public or private interaction with the people involved, including unsolicited interaction with those enforcing the Code of Conduct, is allowed during this period. Violating these terms may lead to a permanent ban. ### 4. Permanent Ban **Community Impact**: Demonstrating a pattern of violation of community standards, including sustained inappropriate behavior, harassment of an individual, or aggression toward or disparagement of classes of individuals. **Consequence**: A permanent ban from any sort of public interaction within the community. ## Attribution This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 2.0, available at https://www.contributor-covenant.org/version/2/0/code_of_conduct.html. Community Impact Guidelines were inspired by [Mozilla's code of conduct enforcement ladder](https://github.com/mozilla/diversity). [homepage]: https://www.contributor-covenant.org For answers to common questions about this code of conduct, see the FAQ at https://www.contributor-covenant.org/faq. Translations are available at https://www.contributor-covenant.org/translations. NetPacket000755001750001750 015141002125 15651 5ustar00yanickyanick000000000000NetPacket-1.8.0/libIP.pm100644001750001750 3460315141002125 16705 0ustar00yanickyanick000000000000NetPacket-1.8.0/lib/NetPacketpackage NetPacket::IP; our $AUTHORITY = 'cpan:YANICK'; # ABSTRACT: Assemble and disassemble IP (Internet Protocol) packets. $NetPacket::IP::VERSION = '1.8.0'; use strict; use warnings; use parent 'NetPacket'; our @EXPORT_OK = qw(ip_strip IP_PROTO_IP IP_PROTO_ICMP IP_PROTO_IGMP IP_PROTO_IPIP IP_PROTO_TCP IP_PROTO_EGP IP_PROTO_EGP IP_PROTO_PUP IP_PROTO_UDP IP_PROTO_IDP IP_PROTO_TP IP_PROTO_DCCP IP_PROTO_IPV6 IP_PROTO_IPv6 IP_PROTO_ROUTING IP_PROTO_FRAGMENT IP_PROTO_RSVP IP_PROTO_GRE IP_PROTO_ESP IP_PROTO_AH IP_PROTO_ICMPV6 IP_PROTO_ICMPv6 IP_PROTO_NONE IP_PROTO_DSTOPTS IP_PROTO_MTP IP_PROTO_ENCAP IP_PROTO_PIM IP_PROTO_COMP IP_PROTO_SCTP IP_PROTO_UDPLITE IP_VERSION_IPv4 IP_FLAG_MOREFRAGS IP_FLAG_DONTFRAG IP_FLAG_CONGESTION IPTOS_ECN_MASK IPTOS_ECN_NOT_ECT IPTOS_ECN_ECT1 IPTOS_ECN_ECT0 IPTOS_ECN_CE IPTOS_DSCP_MASK IPTOS_DSCP_EF IPTOS_DSCP_AF11 IPTOS_DSCP_AF12 IPTOS_DSCP_AF13 IPTOS_DSCP_AF21 IPTOS_DSCP_AF22 IPTOS_DSCP_AF23 IPTOS_DSCP_AF31 IPTOS_DSCP_AF32 IPTOS_DSCP_AF33 IPTOS_DSCP_AF41 IPTOS_DSCP_AF42 IPTOS_DSCP_AF43 IPTOS_CLASS_MASK IPTOS_CLASS_DEFAULT IPTOS_CLASS_CS0 IPTOS_CLASS_CS1 IPTOS_CLASS_CS2 IPTOS_CLASS_CS3 IPTOS_CLASS_CS4 IPTOS_CLASS_CS5 IPTOS_CLASS_CS6 IPTOS_CLASS_CS7 IPTOS_PREC_MASK IPTOS_PREC_NETCONTROL IPTOS_PREC_INTERNETCONTROL IPTOS_PREC_CRITIC_ECP IPTOS_PREC_FLASHOVERRIDE IPTOS_PREC_FLASH IPTOS_PREC_IMMEDIATE IPTOS_PREC_PRIORITY IPTOS_PREC_ROUTINE MAXTTL IPDEFTTL IPFRAGTTL IPTTLDEC IP_MSS IP_MAXPACKET ); our %EXPORT_TAGS = ( ALL => [@EXPORT_OK], protos => [qw(IP_PROTO_IP IP_PROTO_ICMP IP_PROTO_IGMP IP_PROTO_IPIP IP_PROTO_TCP IP_PROTO_EGP IP_PROTO_PUP IP_PROTO_UDP IP_PROTO_IDP IP_PROTO_TP IP_PROTO_DCCP IP_PROTO_IPV6 IP_PROTO_IPv6 IP_PROTO_ROUTING IP_PROTO_FRAGMENT IP_PROTO_RSVP IP_PROTO_GRE IP_PROTO_ESP IP_PROTO_AH IP_PROTO_ICMPV6 IP_PROTO_ICMPv6 IP_PROTO_NONE IP_PROTO_DSTOPTS IP_PROTO_MTP IP_PROTO_ENCAP IP_PROTO_PIM IP_PROTO_COMP IP_PROTO_SCTP IP_PROTO_UDPLITE)], versions => [qw(IP_VERSION_IPv4)], strip => [qw(ip_strip)], flags => [qw(IP_FLAG_MOREFRAGS IP_FLAG_DONTFRAG IP_FLAG_CONGESTION)], tos => [qw(IPTOS_ECN_MASK IPTOS_ECN_NOT_ECT IPTOS_ECN_ECT1 IPTOS_ECN_ECT0 IPTOS_ECN_CE IPTOS_DSCP_MASK IPTOS_DSCP_EF IPTOS_DSCP_AF11 IPTOS_DSCP_AF12 IPTOS_DSCP_AF13 IPTOS_DSCP_AF21 IPTOS_DSCP_AF22 IPTOS_DSCP_AF23 IPTOS_DSCP_AF31 IPTOS_DSCP_AF32 IPTOS_DSCP_AF33 IPTOS_DSCP_AF41 IPTOS_DSCP_AF42 IPTOS_DSCP_AF43 IPTOS_CLASS_MASK IPTOS_CLASS_DEFAULT IPTOS_CLASS_CS0 IPTOS_CLASS_CS1 IPTOS_CLASS_CS2 IPTOS_CLASS_CS3 IPTOS_CLASS_CS4 IPTOS_CLASS_CS5 IPTOS_CLASS_CS6 IPTOS_CLASS_CS7 IPTOS_PREC_MASK IPTOS_PREC_NETCONTROL IPTOS_PREC_INTERNETCONTROL IPTOS_PREC_CRITIC_ECP IPTOS_PREC_FLASHOVERRIDE IPTOS_PREC_FLASH IPTOS_PREC_IMMEDIATE IPTOS_PREC_PRIORITY IPTOS_PREC_ROUTINE)], misc => [qw(MAXTTL IPDEFTTL IPFRAGTTL IPTTLDEC IP_MSS IP_MAXPACKET)], ); # # Partial list of IP protocol values from RFC 1700 # use constant IP_PROTO_IP => 0; # Dummy protocol for TCP use constant IP_PROTO_ICMP => 1; # Internet Control Message Protocol use constant IP_PROTO_IGMP => 2; # Internet Group Management Protocol use constant IP_PROTO_IPIP => 4; # IP in IP encapsulation use constant IP_PROTO_TCP => 6; # Transmission Control Protocol use constant IP_PROTO_EGP => 8; # Exterior Gateway Protocol use constant IP_PROTO_PUP => 12; # PUP protocol use constant IP_PROTO_UDP => 17; # User Datagram Protocol use constant IP_PROTO_IDP => 22; # XNS IDP Protocol use constant IP_PROTO_TP => 29; # SO Transport Protocol Class 4 use constant IP_PROTO_DCCP => 33; # Datagram Congestion Control Protocol use constant IP_PROTO_IPV6 => 41; # IPv6 header use constant IP_PROTO_IPv6 => 41; # IPv6 header (alias) use constant IP_PROTO_ROUTING => 43; # IPv6 routing header use constant IP_PROTO_FRAGMENT => 44; # IPv6 fragmentation header use constant IP_PROTO_RSVP => 46; # Reservation Protocol use constant IP_PROTO_GRE => 47; # General Routing Encapsulation use constant IP_PROTO_ESP => 50; # encapsulating security payload use constant IP_PROTO_AH => 51; # authentication header use constant IP_PROTO_ICMPV6 => 58; # ICMPv6 use constant IP_PROTO_ICMPv6 => 58; # ICMPv6 (alias) use constant IP_PROTO_NONE => 59; # IPv6 no next header use constant IP_PROTO_DSTOPTS => 60; # IPv6 destination options use constant IP_PROTO_MTP => 92; # Multicast Transport Protocol use constant IP_PROTO_ENCAP => 98; # Encapsulation Header use constant IP_PROTO_PIM => 103; # Protocol Independent Multicast use constant IP_PROTO_COMP => 108; # Compression Header Protocol use constant IP_PROTO_SCTP => 132; # Stream Control Transmission Protocol use constant IP_PROTO_UDPLITE => 136; # UDP-Lite protocol # # Partial list of IP version numbers from RFC 1700 # use constant IP_VERSION_IPv4 => 4; # IP version 4 # # Flag values # use constant IP_FLAG_MOREFRAGS => 1; # More fragments coming use constant IP_FLAG_DONTFRAG => 2; # Don't fragment me use constant IP_FLAG_CONGESTION => 4; # Congestion present # # ToS/DSCP values # use constant IPTOS_ECN_MASK => 0x03; use constant IPTOS_ECN_NOT_ECT => 0x00; use constant IPTOS_ECN_ECT1 => 0x01; use constant IPTOS_ECN_ECT0 => 0x02; use constant IPTOS_ECN_CE => 0x03; use constant IPTOS_DSCP_MASK => 0xfc; use constant IPTOS_DSCP_AF11 => 0x28; use constant IPTOS_DSCP_AF12 => 0x30; use constant IPTOS_DSCP_AF13 => 0x38; use constant IPTOS_DSCP_AF21 => 0x48; use constant IPTOS_DSCP_AF22 => 0x50; use constant IPTOS_DSCP_AF23 => 0x58; use constant IPTOS_DSCP_AF31 => 0x68; use constant IPTOS_DSCP_AF32 => 0x70; use constant IPTOS_DSCP_AF33 => 0x78; use constant IPTOS_DSCP_AF41 => 0x88; use constant IPTOS_DSCP_AF42 => 0x90; use constant IPTOS_DSCP_AF43 => 0x98; use constant IPTOS_DSCP_EF => 0xb8; use constant IPTOS_CLASS_MASK => 0xe0; use constant IPTOS_CLASS_CS0 => 0x00; use constant IPTOS_CLASS_CS1 => 0x20; use constant IPTOS_CLASS_CS2 => 0x40; use constant IPTOS_CLASS_CS3 => 0x60; use constant IPTOS_CLASS_CS4 => 0x80; use constant IPTOS_CLASS_CS5 => 0xa0; use constant IPTOS_CLASS_CS6 => 0xc0; use constant IPTOS_CLASS_CS7 => 0xe0; use constant IPTOS_CLASS_DEFAULT => 0x00; use constant IPTOS_PREC_MASK => 0xe0; use constant IPTOS_PREC_NETCONTROL => 0xe0; use constant IPTOS_PREC_INTERNETCONTROL => 0xc0; use constant IPTOS_PREC_CRITIC_ECP => 0x0a; use constant IPTOS_PREC_FLASHOVERRIDE => 0x80; use constant IPTOS_PREC_FLASH => 0x60; use constant IPTOS_PREC_IMMEDIATE => 0x40; use constant IPTOS_PREC_PRIORITY => 0x20; use constant IPTOS_PREC_ROUTINE => 0x00; # TTL values use constant MAXTTL => 255; use constant IPDEFTTL => 64; use constant IPFRAGTTL => 60; use constant IPTTLDEC => 1; use constant IP_MSS => 576; # Maximum IP Packet size use constant IP_MAXPACKET => 65535; # Convert 32-bit IP address to dotted quad notation sub to_dotquad { my($net) = @_ ; my($na, $nb, $nc, $nd); $na = $net >> 24 & 255; $nb = $net >> 16 & 255; $nc = $net >> 8 & 255; $nd = $net & 255; return ("$na.$nb.$nc.$nd"); } # # Decode the packet # sub decode { my $class = shift; my($pkt, $parent) = @_; my $self = {}; # Class fields $self->{_parent} = $parent; $self->{_frame} = $pkt; # Decode IP packet if (defined($pkt)) { my $tmp; ($tmp, $self->{tos},$self->{len}, $self->{id}, $self->{foffset}, $self->{ttl}, $self->{proto}, $self->{cksum}, $self->{src_ip}, $self->{dest_ip}, $self->{options}) = unpack('CCnnnCCnNNa*' , $pkt); # Extract bit fields $self->{ver} = ($tmp & 0xf0) >> 4; $self->{hlen} = $tmp & 0x0f; $self->{flags} = $self->{foffset} >> 13; $self->{foffset} = ($self->{foffset} & 0x1fff) << 3; # Decode variable length header options and remaining data in field my $olen = $self->{hlen} - 5; $olen = 0 if $olen < 0; # Check for bad hlen # Option length is number of 32 bit words $olen = $olen * 4; ($self->{options}, $self->{data}) = unpack("a" . $olen . "a*", $self->{options}); my $length = $self->{hlen}; $length = 5 if $length < 5; # precaution against bad header # truncate data to the length given by the header $self->{data} = substr $self->{data}, 0, $self->{len} - 4 * $length; # Convert 32 bit ip addresses to dotted quad notation $self->{src_ip} = to_dotquad($self->{src_ip}); $self->{dest_ip} = to_dotquad($self->{dest_ip}); } return bless $self, $class; } # # Strip header from packet and return the data contained in it # sub ip_strip { # Create ip_strip alias goto \&strip; } sub strip { my ($pkt) = @_; my $ip_obj = NetPacket::IP->decode($pkt); return $ip_obj->{data}; } # # Encode a packet # sub encode { my $self = shift; my ($hdr,$packet,$zero,$tmp,$offset); my ($src_ip, $dest_ip); # create a zero variable $zero = 0; # adjust the length of the packet $self->{len} = ($self->{hlen} * 4) + length($self->{data}); $tmp = $self->{hlen} & 0x0f; $tmp = $tmp | (($self->{ver} << 4) & 0xf0); $offset = $self->{flags} << 13; $offset = $offset | (($self->{foffset} >> 3) & 0x1fff); # convert the src and dst ip $src_ip = gethostbyname($self->{src_ip}); $dest_ip = gethostbyname($self->{dest_ip}); my $fmt = 'CCnnnCCna4a4a*'; my @pkt = ($tmp, $self->{tos},$self->{len}, $self->{id}, $offset, $self->{ttl}, $self->{proto}, $zero, $src_ip, $dest_ip); # change format and package in case of IP options if(defined $self->{options}){ $fmt = 'CCnnnCCna4a4a*a*'; push(@pkt, $self->{options}); } # construct header to calculate the checksum $hdr = pack($fmt, @pkt); $self->{cksum} = NetPacket::htons(NetPacket::in_cksum($hdr)); $pkt[7] = $self->{cksum}; # make the entire packet if(defined $self->{data}){ push(@pkt, $self->{data}); } $packet = pack($fmt, @pkt); return($packet); } # # Module initialisation # 1; # autoloaded methods go after the END token (&& pod) below =pod =head1 NAME NetPacket::IP - Assemble and disassemble IP (Internet Protocol) packets. =head1 VERSION version 1.8.0 =head1 SYNOPSIS use NetPacket::IP; $ip_obj = NetPacket::IP->decode($raw_pkt); $ip_pkt = NetPacket::IP->encode($ip_obj); $ip_data = NetPacket::IP::strip($raw_pkt); =head1 DESCRIPTION C provides a set of routines for assembling and disassembling packets using IP (Internet Protocol). =head2 Methods =over =item Cdecode([RAW PACKET])> Decode the raw packet data given and return an object containing instance data. This method will quite happily decode garbage input. It is the responsibility of the programmer to ensure valid packet data is passed to this method. =item Cencode()> Return an IP packet encoded with the instance data specified. This will infer the total length of the packet automatically from the payload length and also adjust the checksum. =back =head2 Functions =over =item C Return the encapsulated data (or payload) contained in the IP packet. This data is suitable to be used as input for other C modules. This function is equivalent to creating an object using the C constructor and returning the C field of that object. =back =head2 Instance data The instance data for the C object consists of the following fields. =over =item ver The IP version number of this packet. =item hlen The IP header length of this packet. =item flags The IP header flags for this packet. =item foffset The IP fragment offset for this packet. =item tos The type-of-service for this IP packet. =item len The length (including length of header) in bytes for this packet. =item id The identification (sequence) number for this IP packet. =item ttl The time-to-live value for this packet. =item proto The IP protocol number for this packet. =item cksum The IP checksum value for this packet. =item src_ip The source IP address for this packet in dotted-quad notation. =item dest_ip The destination IP address for this packet in dotted-quad notation. =item options Any IP options for this packet. =item data The encapsulated data (payload) for this IP packet. =back =head2 Exports =over =item default none =item exportable IP_PROTO_IP IP_PROTO_ICMP IP_PROTO_IGMP IP_PROTO_IPIP IP_PROTO_TCP IP_PROTO_UDP IP_VERSION_IPv4 =item tags The following tags group together related exportable items. =over =item C<:protos> IP_PROTO_IP IP_PROTO_ICMP IP_PROTO_IGMP IP_PROTO_IPIP IP_PROTO_TCP IP_PROTO_UDP =item C<:versions> IP_VERSION_IPv4 =item C<:strip> Import the strip function C. =item C<:ALL> All the above exportable items. =back =back =head1 EXAMPLE The following script dumps IP frames by IP address and protocol to standard output. #!/usr/bin/perl -w use strict; use Net::PcapUtils; use NetPacket::Ethernet qw(:strip); use NetPacket::IP; sub process_pkt { my ($user, $hdr, $pkt) = @_; my $ip_obj = NetPacket::IP->decode(eth_strip($pkt)); print("$ip_obj->{src_ip}:$ip_obj->{dest_ip} $ip_obj->{proto}\n"); } Net::PcapUtils::loop(\&process_pkt, FILTER => 'ip'); =head1 TODO =over =item IP option decoding - currently stored in binary form. =item Assembly of received fragments =back =head1 COPYRIGHT Copyright (c) 2001 Tim Potter and Stephanie Wehner. Copyright (c) 1995,1996,1997,1998,1999 ANU and CSIRO on behalf of the participants in the CRC for Advanced Computational Systems ('ACSys'). This module is free software. You can redistribute it and/or modify it under the terms of the Artistic License 2.0. This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. =head1 AUTHOR Tim Potter Etpot@samba.orgE Stephanie Wehner Eatrak@itsx.comE =cut __END__ # any real autoloaded methods go after this line ARP.pm100644001750001750 1335515141002125 17020 0ustar00yanickyanick000000000000NetPacket-1.8.0/lib/NetPacketpackage NetPacket::ARP; our $AUTHORITY = 'cpan:YANICK'; # ABSTRACT: Assemble and disassemble ARP (Address Resolution Protocol) packets. $NetPacket::ARP::VERSION = '1.8.0'; use strict; use warnings; use parent 'NetPacket'; our @EXPORT = qw(); # Other items we are prepared to export if requested our @EXPORT_OK = qw( arp_strip ARP_OPCODE_REQUEST ARP_OPCODE_REPLY RARP_OPCODE_REQUEST RARP_OPCODE_REPLY ARPHRD_NETROM ARPHRD_ETHER ARPHRD_EETHER ARPHRD_AX25 ARPHRD_PRONET ARPHRD_CHAOS ARPHRD_IEEE802 ARPHRD_ARCNET ARPHRD_APPLETLK ARPHRD_DLCI ARPHRD_ATM ARPHRD_METRICOM ARPHRD_IEEE1394 ARPHRD_EUI64 ARPHRD_INFINIBAND ); our %EXPORT_TAGS = ( ALL => [@EXPORT, @EXPORT_OK], opcodes => [qw(ARP_OPCODE_REQUEST ARP_OPCODE_REPLY RARP_OPCODE_REQUEST RARP_OPCODE_REPLY)], protos => [qw(ARPHRD_NETROM ARPHRD_ETHER ARPHRD_AX25 ARPHRD_PRONET ARPHRD_CHAOS ARPHRD_IEEE802 ARPHRD_ARCNET ARPHRD_APPLETLK ARPHRD_DLCI ARPHRD_ATM ARPHRD_METRICOM ARPHRD_IEEE1394 ARPHRD_EUI64 ARPHRD_INFINIBAND)], strip => [qw(arp_strip)], ); # # List of opcode values # use constant ARP_OPCODE_REQUEST => 1; use constant ARP_OPCODE_REPLY => 2; use constant RARP_OPCODE_REQUEST => 3; use constant RARP_OPCODE_REPLY => 4; # # List of hardware identifiers # use constant ARPHRD_NETROM => 0; use constant ARPHRD_ETHER => 1; use constant ARPHRD_EETHER => 2; use constant ARPHRD_AX25 => 3; use constant ARPHRD_PRONET => 4; use constant ARPHRD_CHAOS => 5; use constant ARPHRD_IEEE802 => 6; use constant ARPHRD_ARCNET => 7; use constant ARPHRD_APPLETLK => 8; use constant ARPHRD_DLCI => 15; use constant ARPHRD_ATM => 19; use constant ARPHRD_METRICOM => 23; use constant ARPHRD_IEEE1394 => 24; use constant ARPHRD_EUI64 => 27; use constant ARPHRD_INFINIBAND => 32; # # Decode the packet # sub decode { my $class = shift; my($pkt, $parent) = @_; my $self = {}; # Class fields $self->{_parent} = $parent; $self->{_frame} = $pkt; # Decode ARP packet if (defined($pkt)) { ($self->{htype}, $self->{proto}, $self->{hlen}, $self->{plen}, $self->{opcode}, $self->{sha}, $self->{spa}, $self->{tha}, $self->{tpa}) = unpack('nnCCnH12H8H12H8' , $pkt); $self->{data} = undef; } # Return a blessed object bless($self, $class); return $self; } # # Strip header from packet and return the data contained in it. ARP # packets contain no encapsulated data. # sub arp_strip { goto \&strip; } sub strip { return undef; } # # Encode a packet # sub encode { die("Not implemented"); } # Module return value 1; =pod =head1 NAME NetPacket::ARP - Assemble and disassemble ARP (Address Resolution Protocol) packets. =head1 VERSION version 1.8.0 =head1 SYNOPSIS use NetPacket::ARP; $tcp_obj = NetPacket::ARP->decode($raw_pkt); $tcp_pkt = NetPacket::ARP->encode(params...); # Not implemented =head1 DESCRIPTION C provides a set of routines for assembling and disassembling packets using ARP (Address Resolution Protocol). =head2 Methods =over =item Cdecode([RAW PACKET])> Decode the raw packet data given and return an object containing instance data. This method will quite happily decode garbage input. It is the responsibility of the programmer to ensure valid packet data is passed to this method. =item Cencode(param =E value)> Return a ARP packet encoded with the instance data specified. Not implemented. =back =head2 Functions =over =item C Return the encapsulated data (or payload) contained in the TCP packet. Since no payload data is encapulated in an ARP packet (only instance data), this function returns undef. =back =head2 Instance data The instance data for the C object consists of the following fields. =over =item htype Hardware type. =item proto Protocol type. =item hlen Header length. =item plen Protocol length. =item opcode One of the following constants: =over =item * ARP_OPCODE_REQUEST =item * ARP_OPCODE_REPLY =item * RARP_OPCODE_REQUEST =item * RARP_OPCODE_REPLY =back =item sha Source hardware address. =item spa Source protocol address. =item tha Target hardware address. =item tpa Target protocol address. =back =head2 Exports =over =item default none =item exportable none =item tags The following tags group together related exportable items. =over =item C<:ALL> All the above exportable items. =back =back =head1 EXAMPLE Print out arp requests on the local network. #!/usr/bin/perl -w use Net::PcapUtils; use NetPacket::Ethernet qw(:types); use NetPacket::ARP; sub process_pkt { my ($arg, $hdr, $pkt) = @_; my $eth_obj = NetPacket::Ethernet->decode($pkt); if ($eth_obj->{type} == ETH_TYPE_ARP) { my $arp_obj = NetPacket::ARP->decode($eth_obj->{data}, $eth_obj); print("source hw addr=$arp_obj->{sha}, " . "dest hw addr=$arp_obj->{tha}\n"); } } Net::PcapUtils::loop(\&process_pkt); =head1 TODO =over =item Implement encode() function =item Does this work for protocols other than IP? Need to read RFC. =item Example is a bit silly =back =head1 COPYRIGHT Copyright (c) 2001 Tim Potter. Copyright (c) 1995,1996,1997,1998,1999 ANU and CSIRO on behalf of the participants in the CRC for Advanced Computational Systems ('ACSys'). This module is free software. You can redistribute it and/or modify it under the terms of the Artistic License 2.0. This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. =head1 AUTHOR Tim Potter Etpot@samba.orgE =cut __END__ # any real autoloaded methods go after this line IPX.pm100644001750001750 1136015141002125 17030 0ustar00yanickyanick000000000000NetPacket-1.8.0/lib/NetPacketpackage NetPacket::IPX; our $AUTHORITY = 'cpan:YANICK'; # ABSTRACT: Assemble and disassemble IPX packets $NetPacket::IPX::VERSION = '1.8.0'; use strict; use warnings; use parent qw(NetPacket); use Carp; sub new { my ($class, %packet) = @_; foreach my $key(qw(tc type dest_network dest_node dest_socket src_network src_node src_socket data)) { croak("Missing $key argument") unless(defined($packet{$key})); } croak("Invalid tc argument") unless($packet{tc} =~ m/^\d+$/ && $packet{tc} <= 255); croak("Invalid type argument") unless($packet{type} =~ m/^\d+$/ && $packet{type} <= 255); _check_address("destination", $packet{dest_network}, $packet{dest_node}, $packet{dest_socket}); _check_address("source", $packet{src_network}, $packet{src_node}, $packet{src_socket}); return bless(\%packet, $class); } sub _check_address { my ($direction, $network, $node, $socket) = @_; my $OCTET = qr/[0-9A-F][0-9A-F]?/i; croak("Invalid $direction network") unless($network =~ m/^$OCTET(:$OCTET){3}$/); croak("Invalid $direction node") unless($node =~ m/^$OCTET(:$OCTET){5}$/); croak("Invalid $direction socket") unless($socket =~ m/^\d+$/ && $socket <= 65535); } # # Decode the packet # sub decode { my ($class, $pkt, $parent) = @_; my $self = bless({ _parent => $parent, _frame => $pkt, }, $class); if(defined($pkt)) { # Use array slices to capture the appropriate number of bytes # from each address field. my ( $checksum, $length, $tc, $type, @dst_network, @dst_node, $dst_socket, @src_network, @src_node, $src_socket, ); ( $checksum, $length, $tc, $type, @dst_network[0..3], @dst_node[0..5], $dst_socket, @src_network[0..3], @src_node[0..5], $src_socket, ) = unpack("nnCC C4C6n C4C6n", $pkt); $self->{tc} = $tc; $self->{type} = $type; $self->{dest_network} = _addr_to_string(@dst_network); $self->{dest_node} = _addr_to_string(@dst_node); $self->{dest_socket} = $dst_socket; $self->{src_network} = _addr_to_string(@src_network); $self->{src_node} = _addr_to_string(@src_node); $self->{src_socket} = $src_socket; $self->{data} = substr($pkt, 30); } return $self; } # # Strip header from packet and return the data contained in it # sub strip { my ($pkt) = @_; return NetPacket::IPX->decode($pkt)->{data}; } # # Encode a packet # sub encode { my ($self) = @_; return pack("nnCC", 0xFFFF, 30 + length($self->{data}), $self->{tc}, $self->{type}) ._addr_from_string($self->{dest_network}) ._addr_from_string($self->{dest_node}) .pack("n", $self->{dest_socket}) ._addr_from_string($self->{src_network}) ._addr_from_string($self->{src_node}) .pack("n", $self->{src_socket}) .$self->{data}; } sub _addr_to_string { my (@bytes) = @_; return join(":", map { sprintf("%02X", $_) } @bytes); } sub _addr_from_string { my ($string) = @_; return join("", map { pack("C", hex($_)) } split(m/:/, $string)); } 1; __END__ =pod =head1 NAME NetPacket::IPX - Assemble and disassemble IPX packets =head1 VERSION version 1.8.0 =head1 SYNOPSIS use NetPacket::IPX; my $ipx = NetPacket::IPX->decode($raw_pkt); my $raw_pkt = $ipx->encode(); my $ipx = NetPacket::IPX->new( tc => 0, type => 1, dest_network => "00:00:00:01", dest_node => "FF:FF:FF:FF:FF:FF", dest_socket => 1234, src_network => "00:00:00:01", src_node => "12:34:56:78:90:AB", src_socket => 5678, data => "...", ); =head1 DESCRIPTION C is a C class for encoding and decoding IPX packets. =head1 METHODS =head2 decode($raw_pkt) Decode a packet and return a C instance. =head2 encode() Return the encoded form of a C instance. =head2 new(%options) Construct a C instance with arbitrary contents. All arguments listed in the SYNOPSIS are mandatory. Throws an exception on missing/invalid arguments. =head1 INSTANCE DATA The following fields are available in a C instance: =over =item tc Traffic Control field, the number of routers an IPX packet has passed through. =item type Type field. =item dest_network Destination network number, in the format C. =item dest_node Destination node number, in the format C. =item dest_socket Destination socket number. =item src_network Source network number, in the format C. =item dest_node Source node number, in the format C. =item dest_socket Source socket number. =item data Packet payload. =back =head1 COPYRIGHT Copyright (C) 2014 Daniel Collins This module is free software. You can redistribute it and/or modify it under the same terms as Perl itself. =head1 AUTHOR Daniel Collins Esolemnwarning@solemnwarning.netE =cut SLL.pm100644001750001750 1322615141002125 17025 0ustar00yanickyanick000000000000NetPacket-1.8.0/lib/NetPacketpackage NetPacket::SLL; our $AUTHORITY = 'cpan:YANICK'; # ABSTRACT: Assemble and disassemble Linux cooked capture (SLL) packets. $NetPacket::SLL::VERSION = '1.8.0'; use strict; use warnings; use parent 'NetPacket'; my @sll_types = qw/ SLL_TYPE_UNICAST SLL_TYPE_BROADCAST SLL_TYPE_MULTICAST SLL_TYPE_SENT_TO_OTHER SLL_TYPE_SENT_BY_US /; our @EXPORT_OK = ('sll_strip', @sll_types); our %EXPORT_TAGS = ( ALL => [@EXPORT_OK], strip => [qw(sll_strip)], types => \@sll_types, ); # # SLL packet types # use constant SLL_TYPE_UNICAST => 0; use constant SLL_TYPE_BROADCAST => 1; use constant SLL_TYPE_MULTICAST => 2; use constant SLL_TYPE_SENT_TO_OTHER => 3; use constant SLL_TYPE_SENT_BY_US => 4; # # Decode the packet # sub decode { my $class = shift; my ($pkt, $parent) = @_; my $self = {}; $self->{_parent} = $parent; $self->{_frame} = $pkt; # Decode SLL packet if (defined $pkt) { ($self->{type}, $self->{htype}, my $addr_len, $self->{src_addr}, $self->{proto}, $self->{data}) = unpack('nnnH16na*', $pkt); if ($addr_len < 8) { $self->{src_addr} = substr($self->{src_addr}, 0, $addr_len * 2); } } # Return a blessed object bless($self, $class); return $self; } # # Strip header from packet and return the data contained in it # undef &sll_strip; *sll_strip = \&strip; sub strip { my ($pkt) = @_; my $sll_obj = NetPacket::SLL->decode($pkt); return $sll_obj->{data}; } # # Encode a packet # sub encode { my $self = shift; my $addr_len = int(length($self->{src_addr}) / 2); my $packet = pack('nnnH16n', $self->{type}, $self->{htype}, $addr_len, $self->{src_addr}, $self->{proto}); $packet .= $self->{data}; return $packet; } 1; __END__ =pod =head1 NAME NetPacket::SLL - Assemble and disassemble Linux cooked capture (SLL) packets. =head1 VERSION version 1.8.0 =head1 SYNOPSIS use NetPacket::SLL; my $sll_obj = NetPacket::SLL->decode($raw_pkt); my $sll_pkt = $sll_obj->encode(); my $sll_data = NetPacket::SLL::strip($raw_pkt); =head1 DESCRIPTION C provides a set of routines for assembling and disassembling packets using Linux cooked capture (libpcap SLL). Linux cooked capture is a pseudo-link-layer used by libpcap when capturing packets on the "any" device (because packets may have different link layer headers) or when the native link layer headers can't be used. See L and L for more details on the SLL protocol. =head2 Methods =over =item Cdecode([RAW PACKET])> Decode the raw packet data given and return an object containing instance data. This method will quite happily decode garbage input. It is the responsibility of the programmer to ensure valid packet data is passed to this method. =item C<$sll_obj-Eencode()> Return an SLL packet encoded with the instance data specified. =back =head2 Functions =over =item C Return the encapsulated data (or payload) contained in the SLL packet. This data is suitable to be used as input for other C modules. This function is equivalent to creating an object using the C constructor and returning the C field of that object. =back =head2 Instance data The instance data for the C object consists of the following fields. =over =item type The SLL packet type. # SLL_TYPE_UNICAST 0, if the packet was specifically sent to us by somebody else; # SLL_TYPE_BROADCAST 1, if the packet was broadcast by somebody else; # SLL_TYPE_MULTICAST 2, if the packet was multicast, but not broadcast, by somebody else; # SLL_TYPE_SENT_TO_OTHER 3, if the packet was sent to somebody else by somebody else; # SLL_TYPE_SENT_BY_US 4, if the packet was sent by us. =item htype The device type as a L. =item src_addr Up to the first 8 bytes of the source link-layer address for this packet as a hex string. =item proto The protocol type for the packet. Usually an ethernet protocol type, but the meaning depends on the device type as described at L. =item data The encapsulated data (payload) for this SLL packet. =back =head2 Exports =over =item default none =item tags The following tags group together related exportable items. =over =item C<:types> SLL_TYPE_UNICAST SLL_TYPE_BROADCAST SLL_TYPE_MULTICAST SLL_TYPE_SENT_TO_OTHER SLL_TYPE_SENT_BY_US =item C<:strip> Import the strip function C. =item C<:ALL> All the above exportable items. =back =back =head1 EXAMPLE The following script prints the source address, device type, and protocol type of each packet to standard output. #!/usr/bin/perl use strict; use warnings; use Net::PcapUtils; use NetPacket::SLL; sub process_pkt { my ($user, $hdr, $pkt) = @_; my $sll_obj = NetPacket::SLL->decode($pkt); print("$sll_obj->{src_addr} $sll_obj->{htype} $sll_obj->{proto}\n"); } Net::PcapUtils::loop(\&process_pkt); =head1 COPYRIGHT Copyright (c) 2021 Dan Book. This module is free software. You can redistribute it and/or modify it under the terms of the Artistic License 2.0. This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. =head1 AUTHOR Dan Book Edbook@cpan.orgE =cut TCP.pm100644001750001750 2620215141002125 17017 0ustar00yanickyanick000000000000NetPacket-1.8.0/lib/NetPacketpackage NetPacket::TCP; our $AUTHORITY = 'cpan:YANICK'; # ABSTRACT: Assemble and disassemble TCP (Transmission Control Protocol) packets. $NetPacket::TCP::VERSION = '1.8.0'; use strict; use warnings; use parent 'NetPacket'; # TCP Flags use constant FIN => 0x01; use constant SYN => 0x02; use constant RST => 0x04; use constant PSH => 0x08; use constant ACK => 0x10; use constant URG => 0x20; use constant ECE => 0x40; use constant CWR => 0x80; our @EXPORT = qw(FIN SYN RST PSH ACK URG ECE CWR); our @EXPORT_OK = qw(tcp_strip ); our %EXPORT_TAGS = ( ALL => [@EXPORT, @EXPORT_OK], strip => [qw(tcp_strip)], ); # # Strip header from packet and return the data contained in it # sub tcp_strip { goto \&strip; } sub strip { my ($pkt) = @_; my $tcp_obj = NetPacket::TCP->decode($pkt); return $tcp_obj->{data}; } # # Decode the packet # sub decode { my $class = shift; my($pkt, $parent) = @_; my $self = {}; # Class fields $self->{_parent} = $parent; $self->{_frame} = $pkt; # Decode TCP packet if (defined($pkt)) { my $tmp; ($self->{src_port}, $self->{dest_port}, $self->{seqnum}, $self->{acknum}, $tmp, $self->{winsize}, $self->{cksum}, $self->{urg}, $self->{options}) = unpack("nnNNnnnna*", $pkt); # Extract flags $self->{hlen} = ($tmp & 0xf000) >> 12; $self->{reserved} = ($tmp & 0x0f00) >> 8; $self->{flags} = $tmp & 0x00ff; # Decode variable length header and remaining data my $olen = $self->{hlen} - 5; $olen = 0 if $olen < 0; # Check for bad hlen # Option length is number of 32 bit words $olen *= 4; ( $self->{options}, $self->{data} ) = unpack( 'a' . $olen . 'a*', $self->{options}); } # Return a blessed object bless($self, $class); return $self; } # # Encode a packet # sub encode { my $self = shift; my ($ip) = @_; my ($packet,$tmp); # First of all, fix the checksum $self->checksum($ip); $tmp = $self->{hlen} << 12; $tmp = $tmp | (0x0f00 & ($self->{reserved} << 8)); $tmp = $tmp | (0x00ff & $self->{flags}); # Put the packet together $packet = pack('n n N N n n n n a* a*', $self->{src_port}, $self->{dest_port}, $self->{seqnum}, $self->{acknum}, $tmp, $self->{winsize}, $self->{cksum}, $self->{urg}, $self->{options},$self->{data}); return($packet); } # # TCP Checksum # sub checksum { my $self = shift; my ($ip) = @_; my ($packet,$zero,$tcplen,$tmp); my ($src_ip, $dest_ip,$proto); $zero = 0; $proto = 6; $tcplen = ($self->{hlen} * 4)+ length($self->{data}); no warnings qw/ uninitialized /; $tmp = $self->{hlen} << 12; $tmp = $tmp | (0x0f00 & ($self->{reserved} << 8)); $tmp = $tmp | (0x00ff & $self->{flags}); # Pack pseudo-header for tcp checksum if ($ip->isa('NetPacket::IPv6')) { $packet = $ip->pseudo_header($tcplen, $proto); } else { $src_ip = gethostbyname($ip->{src_ip}); $dest_ip = gethostbyname($ip->{dest_ip}); $packet = pack('a4a4nn',$src_ip,$dest_ip,$proto,$tcplen); } $packet .= pack('nnNNnnnna*a*', $self->{src_port}, $self->{dest_port}, $self->{seqnum}, $self->{acknum}, $tmp, $self->{winsize}, $zero, $self->{urg}, $self->{options},$self->{data}); # pad packet if odd-sized $packet .= "\x00" if length( $packet ) % 2; $self->{cksum} = NetPacket::htons(NetPacket::in_cksum($packet)); } sub parse_tcp_options { # # dissect tcp options header. see: # http://www.networksorcery.com/enp/protocol/tcp.htm#Options # # we create an byte array from the options header # and iterate through that. If we find an option # kind number we act accordingly (sometimes it has # a fixed length, sometimes a variable one). # once we've got the option stored, we shift the # bytes we fetched away from the byte array and # re-enter the loop. my $self = shift; my $opts = $self->{options}; my @bytes = split //, $opts; my %options; ENTRY: foreach my $byte (@bytes) { my $kind = unpack('C', $byte); if($kind == 2) { # MSS. # next byte is size, set to 4 # next 2 bytes are mss value 16 bit unsigned short $options{mss} = unpack('n', $bytes[2] . $bytes[3]); shift @bytes; shift @bytes; shift @bytes; shift @bytes; goto ENTRY; } elsif ($kind == 1) { # a noop shift @bytes; goto ENTRY; } elsif ($kind == 3) { # Windows Scale Factor # next byte is size, set to 3 # next byte is shift count, 8 bit unsigned $options{ws} = unpack('C', $bytes[2]); shift @bytes; shift @bytes; shift @bytes; goto ENTRY; } elsif ($kind == 4) { # SACK Permitted # next byte is length $options{sack} = unpack('C', $bytes[1]); shift @bytes; shift @bytes; goto ENTRY; } elsif ($kind == 5) { # SACK Blocks # next byte is length, 2 + (number of blocks * 8) # in every block, # former 4 bytes is SACK left edge, 32 bit unsigned int # latter 4 bytes is SACK right edge, 32 bit unsigned int my $block_num = (unpack('C', $bytes[1]) - 2) / 8; shift @bytes; shift @bytes; my @sack_blocks; for (1..$block_num) { push @sack_blocks, [unpack('N', join '', @bytes[0..3]), unpack('N', join '', @bytes[4..7])]; shift @bytes; shift @bytes; shift @bytes; shift @bytes; shift @bytes; shift @bytes; shift @bytes; shift @bytes; } $options{sack_blocks} = \@sack_blocks; } elsif ($kind == 8) { # timestamp # next byte is length, set to 10 # next 4 byte is timestamp, 32 bit unsigned int # next 4 byte is timestamp echo reply, 32 bit unsigned int $options{ts} = unpack('N', join '', @bytes[2..5]); $options{er} = unpack('N', join '', @bytes[6,7,8,9]); shift @bytes; shift @bytes; shift @bytes; shift @bytes; shift @bytes; shift @bytes; shift @bytes; shift @bytes; shift @bytes; shift @bytes; goto ENTRY; } } return wantarray ? %options : \%options; } # # Module initialisation # 1; # autoloaded methods go after the END token (&& pod) below __END__ =pod =head1 NAME NetPacket::TCP - Assemble and disassemble TCP (Transmission Control Protocol) packets. =head1 VERSION version 1.8.0 =head1 SYNOPSIS use NetPacket::TCP; $tcp_obj = NetPacket::TCP->decode($raw_pkt); $tcp_pkt = $tcp_obj->encode($ip_pkt); $tcp_data = NetPacket::TCP::strip($raw_pkt); =head1 DESCRIPTION C provides a set of routines for assembling and disassembling packets using TCP (Transmission Control Protocol). =head2 Methods =over =item Cdecode([RAW PACKET])> Decode the raw packet data given and return an object containing instance data. This method will quite happily decode garbage input. It is the responsibility of the programmer to ensure valid packet data is passed to this method. =item Cencode($ip_obj)> Return a TCP packet encoded with the instance data specified. Needs parts of the ip header contained in $ip_obj in order to calculate the TCP checksum. =item C<$packet-Eparse_tcp_options> Returns a hash (or a hash ref in scalar context) containing the packet's options. For now the method only recognizes well-known and widely used options (MSS, noop, windows scale factor, SACK permitted, SACK, timestamp). If the packet contains options unknown to the method, it may fail. =back =head2 Functions =over =item C Return the encapsulated data (or payload) contained in the TCP packet. This data is suitable to be used as input for other C modules. This function is equivalent to creating an object using the C constructor and returning the C field of that object. =back =head2 Instance data The instance data for the C object consists of the following fields. =over =item src_port The source TCP port for the packet. =item dest_port The destination TCP port for the packet. =item seqnum The TCP sequence number for this packet. =item acknum The TCP acknowledgement number for this packet. =item hlen The header length for this packet. =item reserved The 6-bit "reserved" space in the TCP header. =item flags Contains the urg, ack, psh, rst, syn, fin, ece and cwr flags for this packet. =item winsize The TCP window size for this packet. =item cksum The TCP checksum. =item urg The TCP urgent pointer. =item options Any TCP options for this packet in binary form. =item data The encapsulated data (payload) for this packet. =back =head2 Exports =over =item default FIN SYN RST PSH ACK URG ECE CWR Can be used to set the appropriate flag. =item exportable tcp_strip =item tags The following tags group together related exportable items. =over =item C<:strip> Import the strip function C. =item C<:ALL> All the above exportable items. =back =back =head1 EXAMPLE The following script is a primitive pop3 sniffer. #!/usr/bin/perl -w use strict; use Net::PcapUtils; use NetPacket::Ethernet qw(:strip); use NetPacket::IP qw(:strip); use NetPacket::TCP; sub process_pkt { my($arg, $hdr, $pkt) = @_; my $tcp_obj = NetPacket::TCP->decode(ip_strip(eth_strip($pkt))); if (($tcp_obj->{src_port} == 110) or ($tcp_obj->{dest_port} == 110)) { print($tcp_obj->{data}); } } Net::PcapUtils::loop(\&process_pkt, FILTER => 'tcp'); The following uses NetPacket together with Net::Divert to add a syn flag to all TCP packets passing through: #!/usr/bin/perl use Net::Divert; use NetPacket::IP qw(IP_PROTO_TCP); use NetPacket::TCP; $divobj = Net::Divert->new('yourhostname',9999); $divobj->getPackets(\&alterPacket); sub alterPacket { my($packet,$fwtag) = @_; # decode the IP header $ip_obj = NetPacket::IP->decode($packet); # check if this is a TCP packet if($ip_obj->{proto} == IP_PROTO_TCP) { # decode the TCP header $tcp_obj = NetPacket::TCP->decode($ip_obj->{data}); # set the syn flag $tcp_obj->{flags} |= SYN; # construct the new ip packet $ip_obj->{data} = $tcp_obj->encode($ip_obj); $packet = $ip_obj->encode; } # write it back out $divobj->putPacket($packet,$fwtag); } =head1 TODO =over =item Assembly of TCP fragments into a data stream =item Option processing =item Nicer processing of TCP flags =back =head1 COPYRIGHT Copyright (c) 2001 Tim Potter and Stephanie Wehner. Copyright (c) 1995,1996,1997,1998,1999 ANU and CSIRO on behalf of the participants in the CRC for Advanced Computational Systems ('ACSys'). This module is free software. You can redistribute it and/or modify it under the terms of the Artistic License 2.0. This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. =head1 AUTHOR Tim Potter Etpot@samba.orgE Stephanie Wehner Eatrak@itsx.comE =cut UDP.pm100644001750001750 1531115141002125 17020 0ustar00yanickyanick000000000000NetPacket-1.8.0/lib/NetPacketpackage NetPacket::UDP; our $AUTHORITY = 'cpan:YANICK'; # ABSTRACT: Assemble and disassemble UDP (User Datagram Protocol) packets. $NetPacket::UDP::VERSION = '1.8.0'; use strict; use warnings; use parent 'NetPacket'; use NetPacket::IP; our @EXPORT_OK = qw(udp_strip); our %EXPORT_TAGS = ( ALL => [@EXPORT_OK], strip => [qw(udp_strip)], ); # # Decode the packet # sub decode { my $class = shift; my($pkt, $parent) = @_; my $self = {}; # Class fields $self->{_parent} = $parent; $self->{_frame} = $pkt; # Decode UDP packet if (defined($pkt)) { ($self->{src_port}, $self->{dest_port}, $self->{len}, $self->{cksum}, $self->{data}) = unpack("nnnna*", $pkt); } # Return a blessed object bless($self, $class); return $self; } # # Strip header from packet and return the data contained in it # sub udp_strip { goto \&strip; } sub strip { return decode(__PACKAGE__,shift)->{data}; } # # Encode a packet # sub encode { my ($self, $ip) = @_; # Adjust the length accordingly $self->{len} = 8 + length($self->{data}); # First of all, fix the checksum $self->checksum($ip); # Put the packet together return pack("nnnna*", $self->{src_port},$self->{dest_port}, $self->{len}, $self->{cksum}, $self->{data}); } # # UDP Checksum # sub checksum { my( $self, $ip ) = @_; my $proto = NetPacket::IP::IP_PROTO_UDP; # Pack pseudo-header for udp checksum no warnings; my $packet; if ($ip->isa('NetPacket::IPv6')) { $packet = $ip->pseudo_header($self->{len}, $proto); } else { my $src_ip = gethostbyname($ip->{src_ip}); my $dest_ip = gethostbyname($ip->{dest_ip}); $packet = pack 'a4a4CCn' => # fake ip header part $src_ip, $dest_ip, 0, $proto, $self->{len}; } $packet .= pack 'nnnna*' => # proper UDP part $self->{src_port}, $self->{dest_port}, $self->{len}, 0, $self->{data}; $packet .= "\x00" if length($packet) % 2; $self->{cksum} = NetPacket::htons(NetPacket::in_cksum($packet)); } 1; __END__ =pod =head1 NAME NetPacket::UDP - Assemble and disassemble UDP (User Datagram Protocol) packets. =head1 VERSION version 1.8.0 =head1 SYNOPSIS use NetPacket::UDP; $udp_obj = NetPacket::UDP->decode($raw_pkt); $udp_pkt = $udp_obj->encode($l3_obj); $udp_data = NetPacket::UDP::strip($raw_pkt); =head1 DESCRIPTION C provides a set of routines for assembling and disassembling packets using UDP (User Datagram Protocol). =head2 Methods =over =item Cdecode([RAW PACKET])> Decode the raw packet data given and return an object containing instance data. This method will quite happily decode garbage input. It is the responsibility of the programmer to ensure valid packet data is passed to this method. =item C<$udp_packet-encode($l3_obj)> Return the encoded version of the UDP packet object. Needs part of the IP header contained (src_ip and dest_ip specifically) in $l3_obj, in order to calculate the UDP checksum. The length field will also be set automatically based on values provided. =back =head2 Functions =over =item C Return the encapsulated data (or payload) contained in the UDP packet. This data is suitable to be used as input for other C modules. This function is equivalent to creating an object using the C constructor and returning the C field of that object. =back =head2 Instance data The instance data for the C object consists of the following fields. =over =item src_port The source UDP port for the datagram. =item dest_port The destination UDP port for the datagram. =item len The length (including length of header) in bytes for this packet. =item cksum The checksum value for this packet. =item data The encapsulated data (payload) for this packet. =back =head2 IP data The IP data for the $l3_obj object consists of the following fields. Additional items may be supplied as well as passing the whole object returned by NetPacket::IP->decode but are unnecessary. =over =item src_ip The source IP for the datagram =item dest_ip The destination IP for the datagram =back =head2 Exports =over =item default none =item exportable udp_strip =item tags The following tags group together related exportable items. =over =item C<:strip> Import the strip function C. =item C<:ALL> All the above exportable items. =back =back =head1 EXAMPLE The following example prints the source IP address and port, the destination IP address and port, and the UDP packet length: #!/usr/bin/perl -w use strict; use Net::PcapUtils; use NetPacket::Ethernet qw(:strip); use NetPacket::IP; use NetPacket::UDP; sub process_pkt { my($arg, $hdr, $pkt) = @_; my $ip_obj = NetPacket::IP->decode(eth_strip($pkt)); my $udp_obj = NetPacket::UDP->decode($ip_obj->{data}); print("$ip_obj->{src_ip}:$udp_obj->{src_port} -> ", "$ip_obj->{dest_ip}:$udp_obj->{dest_port} ", "$udp_obj->{len}\n"); } Net::PcapUtils::loop(\&process_pkt, FILTER => 'udp'); The following is an example use in combination with Net::Divert to alter the payload of packets that pass through. All occurrences of foo will be replaced with bar. This example is easy to test with netcat, but otherwise makes little sense. :) Adapt to your needs: use Net::Divert; use NetPacket::IP qw(IP_PROTO_UDP); use NetPacket::UDP; $divobj = Net::Divert->new('yourhost',9999); $divobj->getPackets(\&alterPacket); sub alterPacket { my ($data, $fwtag) = @_; $ip_obj = NetPacket::IP->decode($data); if($ip_obj->{proto} == IP_PROTO_UDP) { # decode the UDP header $udp_obj = NetPacket::UDP->decode($ip_obj->{data}); # replace foo in the payload with bar $udp_obj->{data} =~ s/foo/bar/g; # re-encode the packet $ip_obj->{data} = $udp_obj->encode($udp_obj, $ip_obj); $data = $ip_obj->encode; } $divobj->putPacket($data,$fwtag); } =head1 COPYRIGHT Copyright (c) 2001 Tim Potter. Copyright (c) 1995,1996,1997,1998,1999 ANU and CSIRO on behalf of the participants in the CRC for Advanced Computational Systems ('ACSys'). This module is free software. You can redistribute it and/or modify it under the terms of the Artistic License 2.0. This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. =head1 AUTHOR Tim Potter Etpot@samba.orgE Stephanie Wehner Eatrak@itsx.comE Yanick Champoux =cut ICMP.pm100644001750001750 2240615141002125 17123 0ustar00yanickyanick000000000000NetPacket-1.8.0/lib/NetPacketpackage NetPacket::ICMP; our $AUTHORITY = 'cpan:YANICK'; # ABSTRACT: Assemble and disassemble ICMP (Internet Control Message Protocol) packets. $NetPacket::ICMP::VERSION = '1.8.0'; use strict; use warnings; use parent 'NetPacket'; our @EXPORT_OK = qw(icmp_strip icmp_infotype ICMP_ECHOREPLY ICMP_UNREACH ICMP_SOURCEQUENCH ICMP_REDIRECT ICMP_ECHO ICMP_ROUTERADVERT ICMP_ROUTERSOLICIT ICMP_TIMXCEED ICMP_PARAMPROB ICMP_TSTAMP ICMP_TSTAMPREPLY ICMP_IREQ ICMP_IREQREPLY ICMP_MASKREQ ICMP_MASKREPLY ICMP_UNREACH_NET ICMP_UNREACH_HOST ICMP_UNREACH_PROTOCOL ICMP_UNREACH_PORT ICMP_UNREACH_NEEDFRAG ICMP_UNREACH_SRCFAIL ICMP_UNREACH_NET_UNKNOWN ICMP_UNREACH_HOST_UNKNOWN ICMP_UNREACH_ISOLATED ICMP_UNREACH_NET_PROHIB ICMP_UNREACH_HOST_PROHIB ICMP_UNREACH_TOSNET ICMP_UNREACH_TOSHOST ICMP_UNREACH_FILTER_PROHIB ICMP_UNREACH_HOST_PRECEDENCE ICMP_UNREACH_PRCEDENCE_CUTOFF ICMP_REDIRECT_NET ICMP_REDIRECT_HOST ICMP_REDIRECT_TOSNET ICMP_REDIRECT_TOSHOST ICMP_TIMXCEED_INTRANS ICMP_TIMXCEED_REASS ICMP_PARAMPROB_OPTABSENT ); our %EXPORT_TAGS = ( ALL => [@EXPORT_OK], types => [qw(ICMP_ECHOREPLY ICMP_UNREACH ICMP_SOURCEQUENCH ICMP_REDIRECT ICMP_ECHO ICMP_ROUTERADVERT ICMP_ROUTERSOLICIT ICMP_TIMXCEED ICMP_PARAMPROB ICMP_TSTAMP ICMP_TSTAMPREPLY ICMP_IREQ ICMP_IREQREPLY ICMP_MASKREQ ICMP_MASKREPLY)], codes => [qw(ICMP_UNREACH_NET ICMP_UNREACH_HOST ICMP_UNREACH_PROTOCOL ICMP_UNREACH_PORT ICMP_UNREACH_NEEDFRAG ICMP_UNREACH_SRCFAIL ICMP_UNREACH_NET_UNKNOWN ICMP_UNREACH_HOST_UNKNOWN ICMP_UNREACH_ISOLATED ICMP_UNREACH_NET_PROHIB ICMP_UNREACH_HOST_PROHIB ICMP_UNREACH_TOSNET ICMP_UNREACH_TOSHOST ICMP_UNREACH_FILTER_PROHIB ICMP_UNREACH_HOST_PRECEDENCE ICMP_UNREACH_PRCEDENCE_CUTOFF ICMP_REDIRECT_NET ICMP_REDIRECT_HOST ICMP_REDIRECT_TOSNET ICMP_REDIRECT_TOSHOST ICMP_TIMXCEED_INTRANS ICMP_TIMXCEED_REASS ICMP_PARAMPROB_OPTABSENT)], strip => [qw(icmp_strip)], ); # ICMP Types use constant ICMP_ECHOREPLY => 0; use constant ICMP_UNREACH => 3; use constant ICMP_SOURCEQUENCH => 4; use constant ICMP_REDIRECT => 5; use constant ICMP_ECHO => 8; use constant ICMP_ROUTERADVERT => 9; use constant ICMP_ROUTERSOLICIT => 10; use constant ICMP_TIMXCEED => 11; use constant ICMP_PARAMPROB => 12; use constant ICMP_TSTAMP => 13; use constant ICMP_TSTAMPREPLY => 14; use constant ICMP_IREQ => 15; use constant ICMP_IREQREPLY => 16; use constant ICMP_MASKREQ => 17; use constant ICMP_MASKREPLY => 18; # Unreachable Codes use constant ICMP_UNREACH_NET => 0; use constant ICMP_UNREACH_HOST => 1; use constant ICMP_UNREACH_PROTOCOL => 2; use constant ICMP_UNREACH_PORT => 3; use constant ICMP_UNREACH_NEEDFRAG => 4; use constant ICMP_UNREACH_SRCFAIL => 5; use constant ICMP_UNREACH_NET_UNKNOWN => 6; use constant ICMP_UNREACH_HOST_UNKNOWN => 7; use constant ICMP_UNREACH_ISOLATED => 8; use constant ICMP_UNREACH_NET_PROHIB => 9; use constant ICMP_UNREACH_HOST_PROHIB => 10; use constant ICMP_UNREACH_TOSNET => 11; use constant ICMP_UNREACH_TOSHOST => 12; use constant ICMP_UNREACH_FILTER_PROHIB => 13; use constant ICMP_UNREACH_HOST_PRECEDENCE => 14; use constant ICMP_UNREACH_PRECEDENCE_CUTOFF => 15; # Redirect Codes use constant ICMP_REDIRECT_NET => 0; use constant ICMP_REDIRECT_HOST => 1; use constant ICMP_REDIRECT_TOSNET => 2; use constant ICMP_REDIRECT_TOSHOST => 3; # Time-Exceeded Codes use constant ICMP_TIMXCEED_INTRANS => 0; use constant ICMP_TIMXCEED_REASS => 1; # Parameter-Problem Codes use constant ICMP_PARAMPROB_OPTABSENT => 1; # # Test for informational types # sub icmp_infotype { my $type = shift; return ($type == ICMP_ECHOREPLY || $type == ICMP_ECHO || $type == ICMP_ROUTERADVERT || $type == ICMP_ROUTERSOLICIT || $type == ICMP_TSTAMP || $type == ICMP_TSTAMPREPLY || $type == ICMP_IREQ || $type == ICMP_IREQREPLY || $type == ICMP_MASKREQ || $type == ICMP_MASKREPLY); } # # Decode the packet # sub decode { my $class = shift; my($pkt, $parent) = @_; my $self = {}; # Class fields $self->{_parent} = $parent; $self->{_frame} = $pkt; # Decode ICMP packet if (defined($pkt)) { ($self->{type}, $self->{code}, $self->{cksum}, $self->{data}) = unpack("CCna*", $pkt); } # Return a blessed object bless($self, $class); return $self; } # # Strip a packet of its header and return the data # sub icmpstrip { goto \&strip; } sub strip { my ($pkt) = @_; my $icmp_obj = decode($pkt); return $icmp_obj->{data}; } # # Encode a packet # sub encode { my $self = shift; my ($packet); # Checksum the packet $self->checksum(); # Put the packet together $packet = pack("CCna*", $self->{type}, $self->{code}, $self->{cksum}, $self->{data}); return($packet); } # # Calculate ICMP checksum sub checksum { my $self = shift; my ($packet,$zero); # Put the packet together for checksumming $zero = 0; $packet = pack("CCna*", $self->{type}, $self->{code}, $zero, $self->{data}); $self->{cksum} = NetPacket::htons(NetPacket::in_cksum($packet)); } # # Module initialisation # 1; # autoloaded methods go after the END token (&& pod) below =pod =head1 NAME NetPacket::ICMP - Assemble and disassemble ICMP (Internet Control Message Protocol) packets. =head1 VERSION version 1.8.0 =head1 SYNOPSIS use NetPacket::ICMP; $icmp_obj = NetPacket::ICMP->decode($raw_pkt); $icmp_pkt = NetPacket::ICMP->encode(); $icmp_data = NetPacket::ICMP::strip($raw_pkt); =head1 DESCRIPTION C provides a set of routines for assembling and disassembling packets using ICMP (Internet Control Message Protocol). =head2 Methods =over =item Cdecode([RAW PACKET])> Decode the raw packet data given and return an object containing instance data. This method will quite happily decode garbage input. It is the responsibility of the programmer to ensure valid packet data is passed to this method. =item Cencode()> Return an ICMP packet encoded with the instance data specified. =back =head2 Functions =over =item C Return the encapsulated data (or payload) contained in the ICMP packet. =back =head2 Instance data The instance data for the C object consists of the following fields. =over =item type The ICMP message type of this packet. =item code The ICMP message code of this packet. =item cksum The checksum for this packet. =item data The encapsulated data (payload) for this packet. =back =head2 Exports =over =item default none =item exportable ICMP message types: ICMP_ECHOREPLY ICMP_UNREACH ICMP_SOURCEQUENCH ICMP_REDIRECT ICMP_ECHO ICMP_ROUTERADVERT ICMP_ROUTERSOLICIT ICMP_TIMXCEED ICMP_PARAMPROB ICMP_TSTAMP ICMP_TSTAMPREPLY ICMP_IREQ ICMP_IREQREPLY ICMP_MASKREQ ICMP_MASKREPLY =item tags The following tags group together related exportable items. =over =item C<:types> ICMP_ECHOREPLY ICMP_UNREACH ICMP_SOURCEQUENCH ICMP_REDIRECT ICMP_ECHO ICMP_ROUTERADVERT ICMP_ROUTERSOLICIT ICMP_TIMXCEED ICMP_PARAMPROB ICMP_TSTAMP ICMP_TSTAMPREPLY ICMP_IREQ ICMP_IREQREPLY ICMP_MASKREQ ICMP_MASKREPLY =item C<:strip> Import the strip function C. =item C<:ALL> All the above exportable items. =back =back =head1 EXAMPLE The following example prints the ICMP type, code, and checksum fields. #!/usr/bin/perl -w use strict; use Net::PcapUtils; use NetPacket::Ethernet qw(:strip); use NetPacket::IP qw(:strip); use NetPacket::ICMP; sub process_pkt { my ($user, $hdr, $pkt) = @_; my $ip_obj = NetPacket::IP->decode(eth_strip($pkt)); my $icmp_obj = NetPacket::ICMP->decode(ip_strip($ip_obj)); print("Type: $icmp_obj->{type}\n"); print("Code: $icmp_obj->{code}\n"); print("Checksum: $icmp_obj->{cksum}\n\n"); } Net::PcapUtils::loop(\&process_pkt, FILTER => 'icmp'); =head1 TODO =over =item Create constants =back =head1 COPYRIGHT Copyright (c) 2001 Tim Potter and Stephanie Wehner. Copyright (c) 1995,1996,1997,1998,1999 ANU and CSIRO on behalf of the participants in the CRC for Advanced Computational Systems ('ACSys'). This module is free software. You can redistribute it and/or modify it under the terms of the Artistic License 2.0. This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. =head1 AUTHOR Tim Potter Etpot@samba.orgE Stephanie Wehner Eatrak@itsx.comE =cut __END__ # any real autoloaded methods go after this line IGMP.pm100644001750001750 1554615141002125 17136 0ustar00yanickyanick000000000000NetPacket-1.8.0/lib/NetPacketpackage NetPacket::IGMP; our $AUTHORITY = 'cpan:YANICK'; # ABSTRACT: Assemble and disassemble IGMP (Internet Group Management Protocol) packets. $NetPacket::IGMP::VERSION = '1.8.0'; use strict; use warnings; use parent 'NetPacket'; our @EXPORT_OK = qw(igmp_strip IGMP_VERSION_RFC998 IGMP_VERSION_RFC1112 IGMP_VERSION_RFC2236 IGMP_VERSION_RFC3376 IGMP_MSG_HOST_MQUERY IGMP_MSG_HOST_MREPORT IGMP_MSG_HOST_MQUERYv2 IGMP_MSG_HOST_MREPORTv1 IGMP_MSG_HOST_MREPORTv2 IGMP_MSG_HOST_LEAVE IGMP_MSG_HOST_MREPORTv3 IGMP_IP_NO_HOSTS IGMP_IP_ALL_HOSTS IGMP_IP_ALL_ROUTERS ); our %EXPORT_TAGS = ( ALL => [@EXPORT_OK], strip => [qw(igmp_strip)], versions => [qw(IGMP_VERSION_RFC998 IGMP_VERSION_RFC1112 IGMP_VERSION_RFC2236 IGMP_VERSION_RFC3376)], msgtypes => [qw(IGMP_MSG_HOST_MQUERY IGMP_MSG_HOST_MREPORT IGMP_MSG_HOST_MQUERYv2 IGMP_MSG_HOST_MREPORTv1 IGMP_MSG_HOST_MREPORTv2 IGMP_MSG_HOST_LEAVE IGMP_MSG_HOST_MREPORTv3)], group_addrs => [qw(IGMP_IP_NO_HOSTS IGMP_IP_ALL_HOSTS IGMP_IP_ALL_ROUTERS)] ); # # Version numbers # use constant IGMP_VERSION_RFC998 => 0; # Version 0 of IGMP (obsolete) use constant IGMP_VERSION_RFC1112 => 1; # Version 1 of IGMP use constant IGMP_VERSION_RFC2236 => 2; # Version 2 of IGMP use constant IGMP_VERSION_RFC3376 => 3; # Version 3 of IGMP # # Message types # use constant IGMP_MSG_HOST_MQUERY => 1; # Host membership query use constant IGMP_MSG_HOST_MREPORT => 2; # Host membership report use constant IGMP_MSG_HOST_MQUERYv2 => 0x11; # Host membership query use constant IGMP_MSG_HOST_MREPORTv1 => 0x12; # Host membership report use constant IGMP_MSG_HOST_MREPORTv2 => 0x16; # Host membership report use constant IGMP_MSG_HOST_LEAVE => 0x17; # Leave group use constant IGMP_MSG_HOST_MREPORTv3 => 0x22; # Host membership report # # IGMP IP addresses # use constant IGMP_IP_NO_HOSTS => '224.0.0.0'; # Not assigned to anyone use constant IGMP_IP_ALL_HOSTS => '224.0.0.1'; # All hosts on local net use constant IGMP_IP_ALL_ROUTERS => '224.0.0.2'; # All routers on local net # Convert 32-bit IP address to "dotted quad" notation sub to_dotquad { my($net) = @_ ; my($na, $nb, $nc, $nd); $na = $net >> 24 & 255; $nb = $net >> 16 & 255; $nc = $net >> 8 & 255; $nd = $net & 255; return ("$na.$nb.$nc.$nd"); } # # Decode the packet # sub decode { my $class = shift; my($pkt, $parent) = @_; my $self = {}; # Class fields $self->{_parent} = $parent; $self->{_frame} = $pkt; # Decode IGMP packet if (defined($pkt)) { my $tmp; ($tmp, $self->{subtype}, $self->{cksum}, $self->{group_addr}, $self->{data}) = unpack('CCnNa*', $pkt); # Extract bit fields $self->{version} = ($tmp & 0xf0) >> 4; $self->{type} = $tmp & 0x0f; # Convert to dq notation $self->{group_addr} = to_dotquad($self->{group_addr}); } # Return a blessed object bless($self, $class); return $self; } # # Strip header from packet and return the data contained in it. IGMP # packets contain no encapsulated data. # sub igmp_strip { goto \&strip; } sub strip { return undef; } # # Encode a packet # sub encode { die("Not implemented"); } # Module return value 1; # autoloaded methods go after the END token (&& pod) below =pod =head1 NAME NetPacket::IGMP - Assemble and disassemble IGMP (Internet Group Management Protocol) packets. =head1 VERSION version 1.8.0 =head1 SYNOPSIS use NetPacket::IGMP; $igmp_obj = NetPacket::IGMP->decode($raw_pkt); $igmp_pkt = NetPacket::IGMP->encode(params...); # Not implemented $igmp_data = NetPacket::IGMP::strip($raw_pkt); =head1 DESCRIPTION C provides a set of routines for assembling and disassembling packets using IGMP (Internet Group Management Protocol). =head2 Methods =over =item Cdecode([RAW PACKET])> Decode the raw packet data given and return an object containing instance data. This method will quite happily decode garbage input. It is the responsibility of the programmer to ensure valid packet data is passed to this method. =item Cencode(param =E value)> Return an IGMP packet encoded with the instance data specified. Not implemented. =back =head2 Functions =over =item C Return the encapsulated data (or payload) contained in the IGMP packet. This function returns undef as there is no encapsulated data in an IGMP packet. =back =head2 Instance data The instance data for the C object consists of the following fields. =over =item version The IGMP version of this packet. =item type The message type for this packet. =item len The length (including length of header) in bytes for this packet. =item subtype The message subtype for this packet. =item cksum The checksum for this packet. =item group_addr The group address specified in this packet. =item data The encapsulated data (payload) for this packet. =back =head2 Exports =over =item default none =item exportable IGMP_VERSION_RFC998 IGMP_VERSION_RFC1112 IGMP_HOST_MQUERY IGMP_HOST_MREPORT IGMP_IP_NO_HOSTS IGMP_IP_ALL_HOSTS IGMP_IP_ALL_ROUTERS =item tags The following tags group together related exportable items. =over =item C<:strip> Import the strip function C. =item C<:versions> IGMP_VERSION_RFC998 IGMP_VERSION_RFC1112 =item C<:msgtypes> IGMP_HOST_MQUERY IGMP_HOST_MREPORT =item C<:group_addrs> IGMP_IP_NO_HOSTS IGMP_IP_ALL_HOSTS IGMP_IP_ALL_ROUTERS =item C<:ALL> All the above exportable items. =back =back =head1 EXAMPLE The following script dumps UDP frames by IP address and UDP port to standard output. #!/usr/bin/perl -w use strict; use Net::PcapUtils; use NetPacket::Ethernet qw(:strip); use NetPacket::IP; use NetPacket::IGMP; sub process_pkt { my($arg, $hdr, $pkt) = @_; my $ip_obj = NetPacket::IP->decode(eth_strip($pkt)); my $igmp_obj = NetPacket::IGMP->decode($ip_obj->{data}); print("$ip_obj->{src_ip} -> $ip_obj->{dest_ip} ", "$igmp_obj->{type}/$igmp_obj->{subtype} ", "$igmp_obj->{group_addr}\n"); } Net::PcapUtils::loop(\&process_pkt, FILTER => 'igmp'); =head1 TODO =over =item Implement encode() function =back =head1 COPYRIGHT Copyright (c) 2001 Tim Potter. Copyright (c) 1995,1996,1997,1998,1999 ANU and CSIRO on behalf of the participants in the CRC for Advanced Computational Systems ('ACSys'). This module is free software. You can redistribute it and/or modify it under the terms of the Artistic License 2.0. This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. =head1 AUTHOR Tim Potter Etpot@samba.orgE =cut __END__ # any real autoloaded methods go after this line IPv6.pm100644001750001750 2767415141002125 17173 0ustar00yanickyanick000000000000NetPacket-1.8.0/lib/NetPacketpackage NetPacket::IPv6; our $AUTHORITY = 'cpan:YANICK'; # ABSTRACT: Assemble and disassemble IPv6 (Internet Protocol version 6) packets. $NetPacket::IPv6::VERSION = '1.8.0'; use strict; use warnings; use parent 'NetPacket'; use NetPacket::IP qw(:protos :tos :misc); use Socket 1.87 qw(AF_INET6 inet_pton inet_ntop); our @EXPORT_OK = (qw(ipv6_strip ipv6_extheader), @{$NetPacket::IP::EXPORT_TAGS{protos}}, qw(IP_VERSION_IPv6), @{$NetPacket::IP::EXPORT_TAGS{tos}}, @{$NetPacket::IP::EXPORT_TAGS{misc}}, qw(IPv6_EXTHEADER_HOPBYHOP IPv6_EXTHEADER_ROUTING IPv6_EXTHEADER_FRAGMENT IPv6_EXTHEADER_ESP IPv6_EXTHEADER_AUTH IPv6_EXTHEADER_NONEXT IPv6_EXTHEADER_DESTOPT IPv6_EXTHEADER_MOBILITY IPv6_EXTHEADER_HOSTIDENT IPv6_EXTHEADER_SHIM6 IPv6_EXTHEADER_TESTING1 IPv6_EXTHEADER_TESTING2), ); our %EXPORT_TAGS = ( ALL => [@EXPORT_OK], protos => [@{$NetPacket::IP::EXPORT_TAGS{protos}}], versions => [qw(IP_VERSION_IPv6)], strip => [qw(ipv6_strip)], tos => [@{$NetPacket::IP::EXPORT_TAGS{tos}}], misc => [@{$NetPacket::IP::EXPORT_TAGS{misc}}], extheaders => [qw(IPv6_EXTHEADER_HOPBYHOP IPv6_EXTHEADER_ROUTING IPv6_EXTHEADER_FRAGMENT IPv6_EXTHEADER_ESP IPv6_EXTHEADER_AUTH IPv6_EXTHEADER_NONEXT IPv6_EXTHEADER_DESTOPT IPv6_EXTHEADER_MOBILITY IPv6_EXTHEADER_HOSTIDENT IPv6_EXTHEADER_SHIM6 IPv6_EXTHEADER_TESTING1 IPv6_EXTHEADER_TESTING2)], ); # # Partial list of IP version numbers from RFC 8200 # use constant IP_VERSION_IPv6 => 6; # IP version 6 # # List of IPv6 extension header types from RFC 7045 # use constant IPv6_EXTHEADER_HOPBYHOP => 0; use constant IPv6_EXTHEADER_ROUTING => 43; use constant IPv6_EXTHEADER_FRAGMENT => 44; use constant IPv6_EXTHEADER_ESP => 50; use constant IPv6_EXTHEADER_AUTH => 51; use constant IPv6_EXTHEADER_NONEXT => 59; use constant IPv6_EXTHEADER_DESTOPT => 60; use constant IPv6_EXTHEADER_MOBILITY => 135; use constant IPv6_EXTHEADER_HOSTIDENT => 139; use constant IPv6_EXTHEADER_SHIM6 => 140; use constant IPv6_EXTHEADER_TESTING1 => 253; use constant IPv6_EXTHEADER_TESTING2 => 254; # Check if the next header is an IPv6 extension header my %is_extheader = map { ($_ => 1) } IPv6_EXTHEADER_HOPBYHOP, IPv6_EXTHEADER_ROUTING, IPv6_EXTHEADER_FRAGMENT, IPv6_EXTHEADER_ESP, IPv6_EXTHEADER_AUTH, IPv6_EXTHEADER_DESTOPT, IPv6_EXTHEADER_MOBILITY, IPv6_EXTHEADER_HOSTIDENT, IPv6_EXTHEADER_SHIM6, IPv6_EXTHEADER_TESTING1, IPv6_EXTHEADER_TESTING2; sub ipv6_extheader { my($type) = @_; return !!exists $is_extheader{$type}; } # # Decode the packet # sub decode { my $class = shift; my($pkt, $parent) = @_; my $self = {}; # Class fields $self->{_parent} = $parent; $self->{_frame} = $pkt; # Decode IPv6 packet if (defined($pkt)) { (my $tmp, $self->{len}, my $next_header, $self->{hop_limit}, $self->{src_ip}, $self->{dest_ip}, $self->{data}) = unpack('NnCCa16a16a*', $pkt); # Extract bit fields $self->{ver} = ($tmp & 0xf0000000) >> 28; $self->{traffic_class} = ($tmp & 0x0ff00000) >> 20; $self->{flow_label} = $tmp & 0x000fffff; # truncate data to the length given by the header $self->{data} = substr $self->{data}, 0, $self->{len}; # Decode extension headers $self->{extheaders} = []; while (ipv6_extheader($next_header)) { my $header_type = $next_header; last if $header_type == IPv6_EXTHEADER_NONEXT or $header_type == IPv6_EXTHEADER_ESP; my %header = (type => $header_type); if ($header_type == IPv6_EXTHEADER_FRAGMENT) { ($next_header, undef, $header{data}, $self->{data}) = unpack('CCa6a*', $self->{data}); $header{len} = 0; } else { ($next_header, $header{len}, $self->{data}) = unpack('CCa*', $self->{data}); my $data_len = $header{len} * ($header_type == IPv6_EXTHEADER_AUTH ? 4 : 8) + 6; ($header{data}, $self->{data}) = unpack("a${data_len}a*", $self->{data}); } push @{$self->{extheaders}}, \%header; } $self->{proto} = $next_header; # Convert 128 bit ipv6 addresses to text format $self->{src_ip} = inet_ntop(AF_INET6, $self->{src_ip}) if length($self->{src_ip}) == 16; $self->{dest_ip} = inet_ntop(AF_INET6, $self->{dest_ip}) if length($self->{dest_ip}) == 16; } return bless $self, $class; } # # Strip header from packet and return the data contained in it # undef &ipv6_strip; # Create ip_strip alias *ipv6_strip = \&strip; sub strip { my ($pkt) = @_; my $ip_obj = NetPacket::IPv6->decode($pkt); return $ip_obj->{data}; } # # Encode a packet # sub encode { my $self = shift; # adjust the length of the packet and pack extension headers $self->{len} = 0; my $extheaders = ''; my $next_header = $self->{proto}; foreach my $header (reverse @{$self->{extheaders}}) { if ($header->{type} == IPv6_EXTHEADER_FRAGMENT) { $self->{len} += 8; $header->{data} = substr $header->{data}, 0, 6; $header->{len} = 0; $extheaders = pack('CCa6a*', $next_header, $header->{len}, $header->{data}, $extheaders); } elsif ($header->{type} == IPv6_EXTHEADER_ESP) { # Nothing can follow the encrypted ESP extension header $self->{data} = $header->{data}; $extheaders = ''; } elsif ($header->{type} == IPv6_EXTHEADER_NONEXT) { # Nothing can follow the no-next extension header $self->{data} = ''; $extheaders = ''; } else { my $data_bytes = length($header->{data}); $data_bytes = 6 if $data_bytes < 6; $self->{len} += $data_bytes + 2; $header->{len} = int(($data_bytes - 6) / ($header->{type} == IPv6_EXTHEADER_AUTH ? 4 : 8)); $extheaders = pack("CCa${data_bytes}a*", $next_header, $header->{len}, $header->{data}, $extheaders); } $next_header = $header->{type}; } $self->{len} += length($self->{data}); my $tmp = $self->{flow_label} & 0x000fffff; $tmp |= ($self->{traffic_class} << 20) & 0x0ff00000; $tmp |= ($self->{ver} << 28) & 0xf0000000; # convert the src and dst ip my $src_ip = inet_pton(AF_INET6, $self->{src_ip}); my $dest_ip = inet_pton(AF_INET6, $self->{dest_ip}); my $packet = pack('NnCCa16a16', $tmp, $self->{len}, $next_header, $self->{hop_limit}, $src_ip, $dest_ip); $packet .= $extheaders; $packet .= $self->{data} if defined $self->{data}; return $packet; } sub pseudo_header { my $self = shift; my ($length, $next_header) = @_; my $src_ip = inet_pton(AF_INET6, $self->{src_ip}); my $dest_ip = inet_pton(AF_INET6, $self->{dest_ip}); return pack('a16a16Nx3C', $src_ip, $dest_ip, $length, $next_header); } # # Module initialisation # 1; # autoloaded methods go after the END token (&& pod) below =pod =head1 NAME NetPacket::IPv6 - Assemble and disassemble IPv6 (Internet Protocol version 6) packets. =head1 VERSION version 1.8.0 =head1 SYNOPSIS use NetPacket::IPv6; $ip_obj = NetPacket::IPv6->decode($raw_pkt); $ip_pkt = NetPacket::IPv6->encode($ip_obj); $ip_data = NetPacket::IPv6::strip($raw_pkt); =head1 DESCRIPTION C provides a set of routines for assembling and disassembling packets using IPv6 (Internet Protocol version 6). =head2 Methods =over =item Cdecode([RAW PACKET])> Decode the raw packet data given and return an object containing instance data. This method will quite happily decode garbage input. It is the responsibility of the programmer to ensure valid packet data is passed to this method. =item Cencode()> Return an IPv6 packet encoded with the instance data specified. This will infer the total length of the packet automatically from the payload length and length of any extension headers. =item Cpseudo_header([PACKET LENGTH], [PROTOCOL])> Return an IPv6 "pseudo-header" suitable for computing checksums for certain upper-level protocols. =back =head2 Functions =over =item C Return the encapsulated data (or payload) contained in the IPv6 packet. This data is suitable to be used as input for other C modules. This function is equivalent to creating an object using the C constructor and returning the C field of that object. =item C Return whether the IP protocol type is an IPv6 extension header. =back =head2 Instance data The instance data for the C object consists of the following fields. =over =item ver The IP version number of this packet. =item traffic_class The traffic class of this packet, equivalent to the type-of-service field for IPv4. =item flow_label The flow label of this packet. =item len The payload length (including any extension headers) in bytes for this packet. =item proto The IP protocol number for this packet. =item hop_limit The hop limit for this packet, equivalent to the time-to-live field for IPv4. =item src_ip The source IP address for this packet in colon-separated hextet notation. =item dest_ip The destination IP address for this packet in colon-separated hextet notation. =item extheaders Array of any extension headers for this packet, as a hashref containing the fields described below. An ESP (Encapsulating Security Payload) header will not be represented here; as it and any further extension headers and the payload data will be encrypted, it will be instead represented as the packet payload data itself, with a protocol number of 50 (C). =item data The encapsulated data (payload) for this IPv6 packet. =back Extension headers may contain the following fields. =over =item type The extension header type number. =item len The extension header length, in 8-byte units, minus the first 8-byte unit. (For Authentication extension headers, this length is in 4-byte units, minus the first two 4-byte units.) =item data The remaining contents of the extension header following the next-header and length bytes. =back =head2 Exports =over =item default none =item tags The following tags group together related exportable items. =over =item C<:protos> =item C<:tos> =item C<:misc> Re-exported from L for convenience. =item C<:extheaders> IPv6_EXTHEADER_HOPBYHOP IPv6_EXTHEADER_ROUTING IPv6_EXTHEADER_FRAGMENT IPv6_EXTHEADER_ESP IPv6_EXTHEADER_AUTH IPv6_EXTHEADER_NONEXT IPv6_EXTHEADER_DESTOPT IPv6_EXTHEADER_MOBILITY IPv6_EXTHEADER_HOSTIDENT IPv6_EXTHEADER_SHIM6 IPv6_EXTHEADER_TESTING1 IPv6_EXTHEADER_TESTING2 =item C<:versions> IP_VERSION_IPv6 =item C<:strip> Import the strip function C. =item C<:ALL> All the above exportable items. =back =back =head1 EXAMPLE The following script dumps IPv6 frames by IP address and protocol to standard output. #!/usr/bin/perl -w use strict; use Net::PcapUtils; use NetPacket::Ethernet qw(:strip); use NetPacket::IPv6; sub process_pkt { my ($user, $hdr, $pkt) = @_; my $ip_obj = NetPacket::IPv6->decode(eth_strip($pkt)); print("$ip_obj->{src_ip}:$ip_obj->{dest_ip} $ip_obj->{proto}\n"); } Net::PcapUtils::loop(\&process_pkt, FILTER => 'ip6'); =head1 TODO =over =item More specific keys for well-defined extension headers. =item Parse routing extension headers to correctly compute upper-level checksums. =back =head1 COPYRIGHT Copyright (c) 2018 Dan Book. This module is free software. You can redistribute it and/or modify it under the terms of the Artistic License 2.0. This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. =head1 AUTHOR Dan Book Edbook@cpan.orgE =cut __END__ # any real autoloaded methods go after this line SLL2.pm100644001750001750 1263715141002125 17114 0ustar00yanickyanick000000000000NetPacket-1.8.0/lib/NetPacketpackage NetPacket::SLL2; our $AUTHORITY = 'cpan:YANICK'; # ABSTRACT: Assemble and disassemble Linux cooked capture (SLL2) packets. $NetPacket::SLL2::VERSION = '1.8.0'; use strict; use warnings; use parent 'NetPacket'; use NetPacket::SLL qw(:types); our @EXPORT_OK = ('sll2_strip', @{$NetPacket::SLL::EXPORT_TAGS{types}}); our %EXPORT_TAGS = ( ALL => [@EXPORT_OK], strip => [qw(sll2_strip)], types => [@{$NetPacket::SLL::EXPORT_TAGS{types}}], ); # # Decode the packet # sub decode { my $class = shift; my ($pkt, $parent) = @_; my $self = {}; $self->{_parent} = $parent; $self->{_frame} = $pkt; # Decode SLL2 packet if (defined $pkt) { ($self->{proto}, $self->{interface}, $self->{htype}, $self->{type}, my $addr_len, $self->{src_addr}, $self->{data}) = unpack('nx2NnCCH16a*', $pkt); if ($addr_len < 8) { $self->{src_addr} = substr($self->{src_addr}, 0, $addr_len * 2); } } # Return a blessed object bless($self, $class); return $self; } # # Strip header from packet and return the data contained in it # undef &sll2_strip; *sll2_strip = \&strip; sub strip { my ($pkt) = @_; my $sll_obj = NetPacket::SLL2->decode($pkt); return $sll_obj->{data}; } # # Encode a packet # sub encode { my $self = shift; my $addr_len = int(length($self->{src_addr}) / 2); my $packet = pack('nx2NnCCH16', $self->{proto}, $self->{interface}, $self->{htype}, $self->{type}, $addr_len, $self->{src_addr}); $packet .= $self->{data}; return $packet; } 1; __END__ =pod =head1 NAME NetPacket::SLL2 - Assemble and disassemble Linux cooked capture (SLL2) packets. =head1 VERSION version 1.8.0 =head1 SYNOPSIS use NetPacket::SLL2; my $sll_obj = NetPacket::SLL2->decode($raw_pkt); my $sll_pkt = $sll_obj->encode(); my $sll_data = NetPacket::SLL2::strip($raw_pkt); =head1 DESCRIPTION C provides a set of routines for assembling and disassembling packets using Linux cooked capture (libpcap SLL2). Linux cooked capture is a pseudo-link-layer used by libpcap when capturing packets on the "any" device (because packets may have different link layer headers) or when the native link layer headers can't be used. See L and L for more details on the SLL2 protocol. =head2 Methods =over =item Cdecode([RAW PACKET])> Decode the raw packet data given and return an object containing instance data. This method will quite happily decode garbage input. It is the responsibility of the programmer to ensure valid packet data is passed to this method. =item C<$sll_obj-Eencode()> Return an SLL2 packet encoded with the instance data specified. =back =head2 Functions =over =item C Return the encapsulated data (or payload) contained in the SLL2 packet. This data is suitable to be used as input for other C modules. This function is equivalent to creating an object using the C constructor and returning the C field of that object. =back =head2 Instance data The instance data for the C object consists of the following fields. =over =item proto The protocol type for the packet. Usually an ethernet protocol type, but the meaning depends on the device type as described at L. =item interface The 1-based index of the interface this packet was observed on. =item htype The device type as a L. =item type The SLL packet type. # SLL_TYPE_UNICAST 0, if the packet was specifically sent to us by somebody else; # SLL_TYPE_BROADCAST 1, if the packet was broadcast by somebody else; # SLL_TYPE_MULTICAST 2, if the packet was multicast, but not broadcast, by somebody else; # SLL_TYPE_SENT_TO_OTHER 3, if the packet was sent to somebody else by somebody else; # SLL_TYPE_SENT_BY_US 4, if the packet was sent by us. =item src_addr Up to the first 8 bytes of the source link-layer address for this packet as a hex string. =item data The encapsulated data (payload) for this SLL2 packet. =back =head2 Exports =over =item default none =item tags The following tags group together related exportable items. =over =item C<:types> Re-exported from L for convenience. =item C<:strip> Import the strip function C. =item C<:ALL> All the above exportable items. =back =back =head1 EXAMPLE The following script prints the source address, device type, and protocol type of each packet to standard output. #!/usr/bin/perl use strict; use warnings; use Net::PcapUtils; use NetPacket::SLL2; sub process_pkt { my ($user, $hdr, $pkt) = @_; my $sll_obj = NetPacket::SLL2->decode($pkt); print("$sll_obj->{src_addr} $sll_obj->{htype} $sll_obj->{proto}\n"); } Net::PcapUtils::loop(\&process_pkt); =head1 COPYRIGHT Copyright (c) 2021 Dan Book. This module is free software. You can redistribute it and/or modify it under the terms of the Artistic License 2.0. This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. =head1 AUTHOR Dan Book Edbook@cpan.orgE =cut 00-report-prereqs.t100644001750001750 1360115141002125 17245 0ustar00yanickyanick000000000000NetPacket-1.8.0/t#!perl use strict; use warnings; # This test was generated by Dist::Zilla::Plugin::Test::ReportPrereqs 0.029 use Test::More tests => 1; use ExtUtils::MakeMaker; use File::Spec; # from $version::LAX my $lax_version_re = qr/(?: undef | (?: (?:[0-9]+) (?: \. | (?:\.[0-9]+) (?:_[0-9]+)? )? | (?:\.[0-9]+) (?:_[0-9]+)? ) | (?: v (?:[0-9]+) (?: (?:\.[0-9]+)+ (?:_[0-9]+)? )? | (?:[0-9]+)? (?:\.[0-9]+){2,} (?:_[0-9]+)? ) )/x; # hide optional CPAN::Meta modules from prereq scanner # and check if they are available my $cpan_meta = "CPAN::Meta"; my $cpan_meta_pre = "CPAN::Meta::Prereqs"; my $HAS_CPAN_META = eval "require $cpan_meta; $cpan_meta->VERSION('2.120900')" && eval "require $cpan_meta_pre"; ## no critic # Verify requirements? my $DO_VERIFY_PREREQS = 1; sub _max { my $max = shift; $max = ( $_ > $max ) ? $_ : $max for @_; return $max; } sub _merge_prereqs { my ($collector, $prereqs) = @_; # CPAN::Meta::Prereqs object if (ref $collector eq $cpan_meta_pre) { return $collector->with_merged_prereqs( CPAN::Meta::Prereqs->new( $prereqs ) ); } # Raw hashrefs for my $phase ( keys %$prereqs ) { for my $type ( keys %{ $prereqs->{$phase} } ) { for my $module ( keys %{ $prereqs->{$phase}{$type} } ) { $collector->{$phase}{$type}{$module} = $prereqs->{$phase}{$type}{$module}; } } } return $collector; } my @include = qw( ); my @exclude = qw( ); # Add static prereqs to the included modules list my $static_prereqs = do './t/00-report-prereqs.dd'; # Merge all prereqs (either with ::Prereqs or a hashref) my $full_prereqs = _merge_prereqs( ( $HAS_CPAN_META ? $cpan_meta_pre->new : {} ), $static_prereqs ); # Add dynamic prereqs to the included modules list (if we can) my ($source) = grep { -f } 'MYMETA.json', 'MYMETA.yml'; my $cpan_meta_error; if ( $source && $HAS_CPAN_META && (my $meta = eval { CPAN::Meta->load_file($source) } ) ) { $full_prereqs = _merge_prereqs($full_prereqs, $meta->prereqs); } else { $cpan_meta_error = $@; # capture error from CPAN::Meta->load_file($source) $source = 'static metadata'; } my @full_reports; my @dep_errors; my $req_hash = $HAS_CPAN_META ? $full_prereqs->as_string_hash : $full_prereqs; # Add static includes into a fake section for my $mod (@include) { $req_hash->{other}{modules}{$mod} = 0; } for my $phase ( qw(configure build test runtime develop other) ) { next unless $req_hash->{$phase}; next if ($phase eq 'develop' and not $ENV{AUTHOR_TESTING}); for my $type ( qw(requires recommends suggests conflicts modules) ) { next unless $req_hash->{$phase}{$type}; my $title = ucfirst($phase).' '.ucfirst($type); my @reports = [qw/Module Want Have/]; for my $mod ( sort keys %{ $req_hash->{$phase}{$type} } ) { next if grep { $_ eq $mod } @exclude; my $want = $req_hash->{$phase}{$type}{$mod}; $want = "undef" unless defined $want; $want = "any" if !$want && $want == 0; if ($mod eq 'perl') { push @reports, ['perl', $want, $]]; next; } my $req_string = $want eq 'any' ? 'any version required' : "version '$want' required"; my $file = $mod; $file =~ s{::}{/}g; $file .= ".pm"; my ($prefix) = grep { -e File::Spec->catfile($_, $file) } @INC; if ($prefix) { my $have = MM->parse_version( File::Spec->catfile($prefix, $file) ); $have = "undef" unless defined $have; push @reports, [$mod, $want, $have]; if ( $DO_VERIFY_PREREQS && $HAS_CPAN_META && $type eq 'requires' ) { if ( $have !~ /\A$lax_version_re\z/ ) { push @dep_errors, "$mod version '$have' cannot be parsed ($req_string)"; } elsif ( ! $full_prereqs->requirements_for( $phase, $type )->accepts_module( $mod => $have ) ) { push @dep_errors, "$mod version '$have' is not in required range '$want'"; } } } else { push @reports, [$mod, $want, "missing"]; if ( $DO_VERIFY_PREREQS && $type eq 'requires' ) { push @dep_errors, "$mod is not installed ($req_string)"; } } } if ( @reports ) { push @full_reports, "=== $title ===\n\n"; my $ml = _max( map { length $_->[0] } @reports ); my $wl = _max( map { length $_->[1] } @reports ); my $hl = _max( map { length $_->[2] } @reports ); if ($type eq 'modules') { splice @reports, 1, 0, ["-" x $ml, "", "-" x $hl]; push @full_reports, map { sprintf(" %*s %*s\n", -$ml, $_->[0], $hl, $_->[2]) } @reports; } else { splice @reports, 1, 0, ["-" x $ml, "-" x $wl, "-" x $hl]; push @full_reports, map { sprintf(" %*s %*s %*s\n", -$ml, $_->[0], $wl, $_->[1], $hl, $_->[2]) } @reports; } push @full_reports, "\n"; } } } if ( @full_reports ) { diag "\nVersions for all modules listed in $source (including optional ones):\n\n", @full_reports; } if ( $cpan_meta_error || @dep_errors ) { diag "\n*** WARNING WARNING WARNING WARNING WARNING WARNING WARNING WARNING ***\n"; } if ( $cpan_meta_error ) { my ($orig_source) = grep { -f } 'MYMETA.json', 'MYMETA.yml'; diag "\nCPAN::Meta->load_file('$orig_source') failed with: $cpan_meta_error\n"; } if ( @dep_errors ) { diag join("\n", "\nThe following REQUIRED prerequisites were not satisfied:\n", @dep_errors, "\n" ); } pass('Reported prereqs'); # vim: ts=4 sts=4 sw=4 et: 00-report-prereqs.dd100644001750001750 361515141002125 17355 0ustar00yanickyanick000000000000NetPacket-1.8.0/tdo { my $x = { 'configure' => { 'requires' => { 'ExtUtils::MakeMaker' => '0' } }, 'develop' => { 'requires' => { 'Software::Security::Policy::Individual' => '0', 'Test::More' => '0.96', 'Test::Vars' => '0' } }, 'runtime' => { 'recommends' => { 'Net::Pcap' => '0', 'Net::PcapUtils' => '0' }, 'requires' => { 'Carp' => '0', 'Exporter' => '0', 'Socket' => '1.87', 'constant' => '0', 'parent' => '0', 'perl' => 'v5.10.0', 'strict' => '0', 'warnings' => '0' } }, 'test' => { 'recommends' => { 'CPAN::Meta' => '2.120900' }, 'requires' => { 'ExtUtils::MakeMaker' => '0', 'File::Spec' => '0', 'IO::Handle' => '0', 'IPC::Open3' => '0', 'Test2::Bundle::More' => '0', 'Test::More' => '0' } } }; $x; }ICMPv6.pm100644001750001750 3720715141002125 17404 0ustar00yanickyanick000000000000NetPacket-1.8.0/lib/NetPacketpackage NetPacket::ICMPv6; our $AUTHORITY = 'cpan:YANICK'; # ABSTRACT: Assemble and disassemble ICMPv6 (Internet Control Message Protocol for IPv6) packets. $NetPacket::ICMPv6::VERSION = '1.8.0'; use strict; use warnings; use parent 'NetPacket'; use NetPacket::IPv6 'IP_PROTO_ICMPv6'; our @EXPORT_OK = qw(icmpv6_strip icmpv6_infotype ICMPv6_UNREACH ICMPv6_TOOBIG ICMPv6_TIMXCEED ICMPv6_PARAMPROB ICMPv6_PRIVATEERROR1 ICMPv6_PRIVATEERROR2 ICMPv6_EXPANSIONERROR ICMPv6_ECHOREQ ICMPv6_ECHOREPLY ICMPv6_MULTICASTQUERY ICMPv6_MULTICASTREPORT ICMPv6_MULTICASTDONE ICMPv6_ROUTERSOLICIT ICMPv6_ROUTERADVERT ICMPv6_NEIGHBORSOLICIT ICMPv6_NEIGHBORADVERT ICMPv6_REDIRECT ICMPv6_ROUTERRENUMBER ICMPv6_NODEINFOQUERY ICMPv6_NODEINFOREPLY ICMPv6_INVNEIGHBORSOLICIT ICMPv6_INVNEIGHBORADVERT ICMPv6_MULTICASTREPORTV2 ICMPv6_HOMEAGENTREQUEST ICMPv6_HOMEAGENTREPLY ICMPv6_MOBILEPREFIXSOLICIT ICMPv6_MOBILEPREFIXADVERT ICMPv6_CERTPATHSOLICIT ICMPv6_CERTPATHADVERT ICMPv6_MULTICASTADVERT ICMPv6_MULTICASTSOLICIT ICMPv6_MULTICASTTERM ICMPv6_FMIPv6 ICMPv6_RPLCONTROL ICMPv6_DUPREQUEST ICMPv6_DUPCONFIRM ICMPv6_MPLCONTROL ICMPv6_EXTECHOREQ ICMPv6_EXTECHOREPLY ICMPv6_PRIVATEINFO1 ICMPv6_PRIVATEINFO2 ICMPv6_EXPANSIONINFO ICMPv6_UNREACH_NO_ROUTE ICMPv6_UNREACH_COMM_PROHIB ICMPv6_UNREACH_BEYOND_SCOPE ICMPv6_UNREACH_ADDRESS ICMPv6_UNREACH_PORT ICMPv6_UNREACH_SRC_FAIL_POLICY ICMPv6_UNREACH_REJECT_DEST ICMPv6_TIMXCEED_INTRANS ICMPv6_TIMXCEED_REASS ICMPv6_PARAMPROB_HEADER_FIELD ICMPv6_PARAMPROB_NEXT_HEADER ICMPv6_PARAMPROB_OPTION ICMPv6_ROUTERRENUMBER_COMMAND ICMPv6_ROUTERRENUMBER_RESULT ICMPv6_ROUTERRENUMBER_RESET ICMPv6_NODEINFOQUERY_IPv6 ICMPv6_NODEINFOQUERY_NAME ICMPv6_NODEINFOQUERY_IPv4 ICMPv6_NODEINFOREPLY_SUCCESS ICMPv6_NODEINFOREPLY_REFUSED ICMPv6_NODEINFOREPLY_UNKNOWN ICMPv6_RPLCONTROL_DODAG_SOLICIT ICMPv6_RPLCONTROL_DODAG_OBJECT ICMPv6_RPLCONTROL_DEST_ADVERT ICMPv6_RPLCONTROL_DEST_ACK ICMPv6_RPLCONTROL_SECURE_DODAG_SOLICIT ICMPv6_RPLCONTROL_SECURE_DODAG_OBJECT ICMPv6_RPLCONTROL_SECURE_DEST_ADVERT ICMPv6_RPLCONTROL_SECURE_DEST_ACK ICMPv6_RPLCONTROL_CONSISTENCY ICMPv6_EXTECHOREPLY_NO_ERROR ICMPv6_EXTECHOREPLY_MALFORMED ICMPv6_EXTECHOREPLY_NO_INTERFACE ICMPv6_EXTECHOREPLY_NO_ENTRY ICMPv6_EXTECHOREPLY_MULTIPLE ); our %EXPORT_TAGS = ( ALL => [@EXPORT_OK], types => [qw(ICMPv6_UNREACH ICMPv6_TOOBIG ICMPv6_TIMXCEED ICMPv6_PARAMPROB ICMPv6_PRIVATEERROR1 ICMPv6_PRIVATEERROR2 ICMPv6_EXPANSIONERROR ICMPv6_ECHOREQ ICMPv6_ECHOREPLY ICMPv6_MULTICASTQUERY ICMPv6_MULTICASTREPORT ICMPv6_MULTICASTDONE ICMPv6_ROUTERSOLICIT ICMPv6_ROUTERADVERT ICMPv6_NEIGHBORSOLICIT ICMPv6_NEIGHBORADVERT ICMPv6_REDIRECT ICMPv6_ROUTERRENUMBER ICMPv6_NODEINFOQUERY ICMPv6_NODEINFOREPLY ICMPv6_INVNEIGHBORSOLICIT ICMPv6_INVNEIGHBORADVERT ICMPv6_MULTICASTREPORTV2 ICMPv6_HOMEAGENTREQUEST ICMPv6_HOMEAGENTREPLY ICMPv6_MOBILEPREFIXSOLICIT ICMPv6_MOBILEPREFIXADVERT ICMPv6_CERTPATHSOLICIT ICMPv6_CERTPATHADVERT ICMPv6_MULTICASTADVERT ICMPv6_MULTICASTSOLICIT ICMPv6_MULTICASTTERM ICMPv6_FMIPv6 ICMPv6_RPLCONTROL ICMPv6_DUPREQUEST ICMPv6_DUPCONFIRM ICMPv6_MPLCONTROL ICMPv6_EXTECHOREQ ICMPv6_EXTECHOREPLY ICMPv6_PRIVATEINFO1 ICMPv6_PRIVATEINFO2 ICMPv6_EXPANSIONINFO)], codes => [qw(ICMPv6_UNREACH_NO_ROUTE ICMPv6_UNREACH_COMM_PROHIB ICMPv6_UNREACH_BEYOND_SCOPE ICMPv6_UNREACH_ADDRESS ICMPv6_UNREACH_PORT ICMPv6_UNREACH_SRC_FAIL_POLICY ICMPv6_UNREACH_REJECT_DEST ICMPv6_TIMXCEED_INTRANS ICMPv6_TIMXCEED_REASS ICMPv6_PARAMPROB_HEADER_FIELD ICMPv6_PARAMPROB_NEXT_HEADER ICMPv6_PARAMPROB_OPTION ICMPv6_ROUTERRENUMBER_COMMAND ICMPv6_ROUTERRENUMBER_RESULT ICMPv6_ROUTERRENUMBER_RESET ICMPv6_NODEINFOQUERY_IPv6 ICMPv6_NODEINFOQUERY_NAME ICMPv6_NODEINFOQUERY_IPv4 ICMPv6_NODEINFOREPLY_SUCCESS ICMPv6_NODEINFOREPLY_REFUSED ICMPv6_NODEINFOREPLY_UNKNOWN ICMPv6_RPLCONTROL_DODAG_SOLICIT ICMPv6_RPLCONTROL_DODAG_OBJECT ICMPv6_RPLCONTROL_DEST_ADVERT ICMPv6_RPLCONTROL_DEST_ACK ICMPv6_RPLCONTROL_SECURE_DODAG_SOLICIT ICMPv6_RPLCONTROL_SECURE_DODAG_OBJECT ICMPv6_RPLCONTROL_SECURE_DEST_ADVERT ICMPv6_RPLCONTROL_SECURE_DEST_ACK ICMPv6_RPLCONTROL_CONSISTENCY ICMPv6_EXTECHOREPLY_NO_ERROR ICMPv6_EXTECHOREPLY_MALFORMED ICMPv6_EXTECHOREPLY_NO_INTERFACE ICMPv6_EXTECHOREPLY_NO_ENTRY ICMPv6_EXTECHOREPLY_MULTIPLE)], strip => [qw(icmpv6_strip)], ); # ICMPv6 Types use constant ICMPv6_UNREACH => 1; use constant ICMPv6_TOOBIG => 2; use constant ICMPv6_TIMXCEED => 3; use constant ICMPv6_PARAMPROB => 4; use constant ICMPv6_PRIVATEERROR1 => 100; use constant ICMPv6_PRIVATEERROR2 => 101; use constant ICMPv6_EXPANSIONERROR => 127; use constant ICMPv6_ECHOREQ => 128; use constant ICMPv6_ECHOREPLY => 129; use constant ICMPv6_MULTICASTQUERY => 130; use constant ICMPv6_MULTICASTREPORT => 131; use constant ICMPv6_MULTICASTDONE => 132; use constant ICMPv6_ROUTERSOLICIT => 133; use constant ICMPv6_ROUTERADVERT => 134; use constant ICMPv6_NEIGHBORSOLICIT => 135; use constant ICMPv6_NEIGHBORADVERT => 136; use constant ICMPv6_REDIRECT => 137; use constant ICMPv6_ROUTERRENUMBER => 138; use constant ICMPv6_NODEINFOQUERY => 139; use constant ICMPv6_NODEINFOREPLY => 140; use constant ICMPv6_INVNEIGHBORSOLICIT => 141; use constant ICMPv6_INVNEIGHBORADVERT => 142; use constant ICMPv6_MULTICASTREPORTV2 => 143; use constant ICMPv6_HOMEAGENTREQUEST => 144; use constant ICMPv6_HOMEAGENTREPLY => 145; use constant ICMPv6_MOBILEPREFIXSOLICIT => 146; use constant ICMPv6_MOBILEPREFIXADVERT => 147; use constant ICMPv6_CERTPATHSOLICIT => 148; use constant ICMPv6_CERTPATHADVERT => 149; use constant ICMPv6_MULTICASTADVERT => 151; use constant ICMPv6_MULTICASTSOLICIT => 152; use constant ICMPv6_MULTICASTTERM => 153; use constant ICMPv6_FMIPv6 => 154; use constant ICMPv6_RPLCONTROL => 155; use constant ICMPv6_DUPREQUEST => 157; use constant ICMPv6_DUPCONFIRM => 158; use constant ICMPv6_MPLCONTROL => 159; use constant ICMPv6_EXTECHOREQ => 160; use constant ICMPv6_EXTECHOREPLY => 161; use constant ICMPv6_PRIVATEINFO1 => 200; use constant ICMPv6_PRIVATEINFO2 => 201; use constant ICMPv6_EXPANSIONINFO => 255; # Destination Unreachable Codes use constant ICMPv6_UNREACH_NO_ROUTE => 0; use constant ICMPv6_UNREACH_COMM_PROHIB => 1; use constant ICMPv6_UNREACH_BEYOND_SCOPE => 2; use constant ICMPv6_UNREACH_ADDRESS => 3; use constant ICMPv6_UNREACH_PORT => 4; use constant ICMPv6_UNREACH_SRC_FAIL_POLICY => 5; use constant ICMPv6_UNREACH_REJECT_DEST => 6; # Time-Exceeded Codes use constant ICMPv6_TIMXCEED_INTRANS => 0; use constant ICMPv6_TIMXCEED_REASS => 1; # Parameter-Problem Codes use constant ICMPv6_PARAMPROB_HEADER_FIELD => 0; use constant ICMPv6_PARAMPROB_NEXT_HEADER => 1; use constant ICMPv6_PARAMPROB_OPTION => 2; # Router Renumbering Codes use constant ICMPv6_ROUTERRENUMBER_COMMAND => 0; use constant ICMPv6_ROUTERRENUMBER_RESULT => 1; use constant ICMPv6_ROUTERRENUMBER_RESET => 255; # Node Information Query Codes use constant ICMPv6_NODEINFOQUERY_IPv6 => 0; use constant ICMPv6_NODEINFOQUERY_NAME => 1; use constant ICMPv6_NODEINFOQUERY_IPv4 => 2; # Node Information Reply Codes use constant ICMPv6_NODEINFOREPLY_SUCCESS => 0; use constant ICMPv6_NODEINFOREPLY_REFUSED => 1; use constant ICMPv6_NODEINFOREPLY_UNKNOWN => 2; # RPL Control Codes use constant ICMPv6_RPLCONTROL_DODAG_SOLICIT => 0x00; use constant ICMPv6_RPLCONTROL_DODAG_OBJECT => 0x01; use constant ICMPv6_RPLCONTROL_DEST_ADVERT => 0x02; use constant ICMPv6_RPLCONTROL_DEST_ACK => 0x03; use constant ICMPv6_RPLCONTROL_SECURE_DODAG_SOLICIT => 0x80; use constant ICMPv6_RPLCONTROL_SECURE_DODAG_OBJECT => 0x81; use constant ICMPv6_RPLCONTROL_SECURE_DEST_ADVERT => 0x82; use constant ICMPv6_RPLCONTROL_SECURE_DEST_ACK => 0x83; use constant ICMPv6_RPLCONTROL_CONSISTENCY => 0x8A; # Extended Echo Reply Codes use constant ICMPv6_EXTECHOREPLY_NO_ERROR => 0; use constant ICMPv6_EXTECHOREPLY_MALFORMED => 1; use constant ICMPv6_EXTECHOREPLY_NO_INTERFACE => 2; use constant ICMPv6_EXTECHOREPLY_NO_ENTRY => 3; use constant ICMPv6_EXTECHOREPLY_MULTIPLE => 4; # # Test for informational types # sub icmpv6_infotype { my $type = shift; return $type >= ICMPv6_ECHOREQ; } # # Decode the packet # sub decode { my $class = shift; my($pkt, $parent) = @_; my $self = {}; # Class fields $self->{_parent} = $parent; $self->{_frame} = $pkt; # Decode ICMPv6 packet if (defined($pkt)) { ($self->{type}, $self->{code}, $self->{cksum}, $self->{data}) = unpack("CCna*", $pkt); } # Return a blessed object bless($self, $class); return $self; } # # Strip a packet of its header and return the data # undef &icmpv6_strip; *icmpv6strip = \&strip; sub strip { my ($pkt) = @_; my $icmpv6_obj = decode($pkt); return $icmpv6_obj->{data}; } # # Encode a packet # sub encode { my $self = shift; my ($ipv6) = @_; # Checksum the packet $self->checksum($ipv6); # Put the packet together my $packet = pack("CCna*", $self->{type}, $self->{code}, $self->{cksum}, $self->{data}); return($packet); } # # Calculate ICMPv6 checksum sub checksum { my $self = shift; my ($ipv6) = @_; # Put the packet together for checksumming my $len = length($self->{data}) + 4; my $packet = $ipv6->pseudo_header($len, IP_PROTO_ICMPv6); $packet .= pack("CCna*", $self->{type}, $self->{code}, 0, $self->{data}); $self->{cksum} = NetPacket::htons(NetPacket::in_cksum($packet)); } # # Module initialisation # 1; # autoloaded methods go after the END token (&& pod) below =pod =head1 NAME NetPacket::ICMPv6 - Assemble and disassemble ICMPv6 (Internet Control Message Protocol for IPv6) packets. =head1 VERSION version 1.8.0 =head1 SYNOPSIS use NetPacket::ICMPv6; $icmpv6_obj = NetPacket::ICMPv6->decode($raw_pkt); $icmpv6_pkt = NetPacket::ICMPv6->encode($ipv6_pkt); $icmpv6_data = NetPacket::ICMPv6::strip($raw_pkt); =head1 DESCRIPTION C provides a set of routines for assembling and disassembling packets using ICMPv6 (Internet Control Message Protocol for IPv6). =head2 Methods =over =item Cdecode([RAW PACKET])> Decode the raw packet data given and return an object containing instance data. This method will quite happily decode garbage input. It is the responsibility of the programmer to ensure valid packet data is passed to this method. =item Cencode($ipv6_obj)> Return an ICMPv6 packet encoded with the instance data specified. Needs parts of the IPv6 header contained in $ipv6_obj in order to calculate the ICMPv6 checksum. =back =head2 Functions =over =item C Return the encapsulated data (or payload) contained in the ICMPv6 packet. =back =head2 Instance data The instance data for the C object consists of the following fields. =over =item type The ICMPv6 message type of this packet. =item code The ICMPv6 message code of this packet. =item cksum The checksum for this packet. =item data The encapsulated data (payload) for this packet. =back =head2 Exports =over =item default none =item exportable ICMPv6 message types: ICMPv6_UNREACH ICMPv6_TOOBIG ICMPv6_TIMXCEED ICMPv6_PARAMPROB ICMPv6_PRIVATEERROR1 ICMPv6_PRIVATEERROR2 ICMPv6_EXPANSIONERROR ICMPv6_ECHOREQ ICMPv6_ECHOREPLY ICMPv6_MULTICASTQUERY ICMPv6_MULTICASTREPORT ICMPv6_MULTICASTDONE ICMPv6_ROUTERSOLICIT ICMPv6_ROUTERADVERT ICMPv6_NEIGHBORSOLICIT ICMPv6_NEIGHBORADVERT ICMPv6_REDIRECT ICMPv6_ROUTERRENUMBER ICMPv6_NODEINFOQUERY ICMPv6_NODEINFOREPLY ICMPv6_INVNEIGHBORSOLICIT ICMPv6_INVNEIGHBORADVERT ICMPv6_MULTICASTREPORTV2 ICMPv6_HOMEAGENTREQUEST ICMPv6_HOMEAGENTREPLY ICMPv6_MOBILEPREFIXSOLICIT ICMPv6_MOBILEPREFIXADVERT ICMPv6_CERTPATHSOLICIT ICMPv6_CERTPATHADVERT ICMPv6_MULTICASTADVERT ICMPv6_MULTICASTSOLICIT ICMPv6_MULTICASTTERM ICMPv6_FMIPv6 ICMPv6_RPLCONTROL ICMPv6_DUPREQUEST ICMPv6_DUPCONFIRM ICMPv6_MPLCONTROL ICMPv6_EXTECHOREQ ICMPv6_EXTECHOREPLY ICMPv6_PRIVATEINFO1 ICMPv6_PRIVATEINFO2 ICMPv6_EXPANSIONINFO ICMPv6 message codes: ICMPv6_UNREACH_NO_ROUTE ICMPv6_UNREACH_COMM_PROHIB ICMPv6_UNREACH_BEYOND_SCOPE ICMPv6_UNREACH_ADDRESS ICMPv6_UNREACH_PORT ICMPv6_UNREACH_SRC_FAIL_POLICY ICMPv6_UNREACH_REJECT_DEST ICMPv6_TIMXCEED_INTRANS ICMPv6_TIMXCEED_REASS ICMPv6_PARAMPROB_HEADER_FIELD ICMPv6_PARAMPROB_NEXT_HEADER ICMPv6_PARAMPROB_OPTION ICMPv6_ROUTERRENUMBER_COMMAND ICMPv6_ROUTERRENUMBER_RESULT ICMPv6_ROUTERRENUMBER_RESET ICMPv6_NODEINFOQUERY_IPv6 ICMPv6_NODEINFOQUERY_NAME ICMPv6_NODEINFOQUERY_IPv4 ICMPv6_NODEINFOREPLY_SUCCESS ICMPv6_NODEINFOREPLY_REFUSED ICMPv6_NODEINFOREPLY_UNKNOWN ICMPv6_RPLCONTROL_DODAG_SOLICIT ICMPv6_RPLCONTROL_DODAG_OBJECT ICMPv6_RPLCONTROL_DEST_ADVERT ICMPv6_RPLCONTROL_DEST_ACK ICMPv6_RPLCONTROL_SECURE_DODAG_SOLICIT ICMPv6_RPLCONTROL_SECURE_DODAG_OBJECT ICMPv6_RPLCONTROL_SECURE_DEST_ADVERT ICMPv6_RPLCONTROL_SECURE_DEST_ACK ICMPv6_RPLCONTROL_CONSISTENCY ICMPv6_EXTECHOREPLY_NO_ERROR ICMPv6_EXTECHOREPLY_MALFORMED ICMPv6_EXTECHOREPLY_NO_INTERFACE ICMPv6_EXTECHOREPLY_NO_ENTRY ICMPv6_EXTECHOREPLY_MULTIPLE =item tags The following tags group together related exportable items. =over =item C<:types> =item C<:codes> =item C<:strip> Import the strip function C. =item C<:ALL> All the above exportable items. =back =back =head1 EXAMPLE The following example prints the ICMPv6 type, code, and checksum fields. #!/usr/bin/perl use strict; use warnings; use Net::PcapUtils; use NetPacket::Ethernet qw(:strip); use NetPacket::IPv6 qw(:strip); use NetPacket::ICMPv6; sub process_pkt { my ($user, $hdr, $pkt) = @_; my $icmpv6_obj = NetPacket::ICMPv6->decode(ipv6_strip(eth_strip($pkt))); print("Type: $icmpv6_obj->{type}\n"); print("Code: $icmpv6_obj->{code}\n"); print("Checksum: $icmpv6_obj->{cksum}\n\n"); } Net::PcapUtils::loop(\&process_pkt, FILTER => 'icmp6'); =head1 COPYRIGHT Copyright (c) 2018 Dan Book. This module is free software. You can redistribute it and/or modify it under the terms of the Artistic License 2.0. This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. =head1 AUTHOR Dan Book Edbook@cpan.orgE =cut __END__ # any real autoloaded methods go after this line USBMon.pm100644001750001750 1663215141002125 17502 0ustar00yanickyanick000000000000NetPacket-1.8.0/lib/NetPacketpackage NetPacket::USBMon; our $AUTHORITY = 'cpan:YANICK'; #ABSTRACT: Assemble and disassemble USB packets captured via Linux USBMon interface. $NetPacket::USBMon::VERSION = '1.8.0'; use 5.10.0; use strict; use warnings; use parent 'NetPacket'; our @EXPORT_OK = qw( USB_TYPE_SUBMISSION USB_TYPE_CALLBACK USB_TYPE_ERROR USB_XFER_TYPE_ISO USB_XFER_TYPE_INTR USB_XFER_TYPE_CONTROL USB_XFER_TYPE_BULK USB_FLAG_SETUP_IRRELEVANT USB_FLAG_SETUP_RELEVANT USB_FLAG_DATA_ERROR USB_FLAG_DATA_INCOMING USB_FLAG_DATA_OUTGOING USB_FLAG_DATA_PRESENT USB_TYPE_VENDOR ); our %EXPORT_TAGS =( ALL => \@EXPORT_OK, types => [qw(USB_TYPE_SUBMISSION USB_TYPE_CALLBACK USB_TYPE_ERROR)], xfer_types => [qw(USB_XFER_TYPE_ISO USB_XFER_TYPE_INTR USB_XFER_TYPE_CONTROL USB_XFER_TYPE_BULK)], setup_flags => [qw(USB_FLAG_SETUP_IRRELEVANT USB_FLAG_SETUP_RELEVANT)], data_flags => [qw(USB_FLAG_DATA_ERROR USB_FLAG_DATA_INCOMING USB_FLAG_DATA_OUTGOING USB_FLAG_DATA_PRESENT)], setup_types => [qw(USB_TYPE_VENDOR)], ); use constant USB_TYPE_SUBMISSION => 'S'; use constant USB_TYPE_CALLBACK => 'C'; use constant USB_TYPE_ERROR => 'E'; use constant USB_XFER_TYPE_ISO => 0; use constant USB_XFER_TYPE_INTR => 1; use constant USB_XFER_TYPE_CONTROL => 2; use constant USB_XFER_TYPE_BULK => 3; use constant USB_FLAG_SETUP_IRRELEVANT => '-'; use constant USB_FLAG_SETUP_RELEVANT => chr(0); use constant USB_FLAG_DATA_ERROR => 'E'; use constant USB_FLAG_DATA_INCOMING => '<'; use constant USB_FLAG_DATA_OUTGOING => '>'; use constant USB_FLAG_DATA_PRESENT => chr(0); use constant USB_TYPE_VENDOR => 0x40; sub decode { my $class = shift; my $packet = shift; my $parent = shift; my($id, $type, $xfer_type, $epnum, $devnum, $busnum, $flag_setup, $flag_data, $ts_sec, $ts_usec, $status, $length, $len_cap, $s, $interval, $start_frame, $xfer_flags, $ndesc, $rest) = unpack('a8CCCCS $parent, _frame => $packet, id => $id, type => chr($type), xfer_type => $xfer_type, ep => { num => ($epnum & 0x7f), dir => ($epnum & 0x80 ? 'IN' : 'OUT'), }, devnum => $devnum, busnum => $busnum, flag_setup => chr($flag_setup), flag_data => chr($flag_data), ts_sec => $ts_sec, ts_usec => $ts_usec, status => $status, length => $length, len_cap => $len_cap, interval => $interval, start_frame => $start_frame, xfer_flags => $xfer_flags, ndesc => $ndesc, }; # Setup if ($self->{flag_setup} ne USB_FLAG_SETUP_IRRELEVANT) { my $setup = {}; my $rest; ($setup->{bmRequestType}, $setup->{bRequest}, $rest) = unpack('CCa*', $s); if ($setup->{bmRequestType} & USB_TYPE_VENDOR) { ($setup->{wValue}, $setup->{wIndex}, $setup->{wLength}) = unpack('S<3', $rest); } else { # Unknown setup request; $setup->{data} = $rest; } $self->{setup} = $setup; } # Isochronous descriptors if ($self->{xfer_type} == USB_XFER_TYPE_ISO) { my $iso = {}; ($iso->{error_count}, $iso->{numdesc}) = unpack('i{iso} = $iso; } # Data warn 'Payload length mismatch' if length($rest) ne $self->{len_cap}; $self->{data} = $rest; return bless $self, $class; } 1; __END__ =pod =head1 NAME NetPacket::USBMon - Assemble and disassemble USB packets captured via Linux USBMon interface. =head1 VERSION version 1.8.0 =head1 SYNOPSIS use NetPacket::USBMon; $usb = NetPacket::USBMon->decode($raw_pkt); =head1 DESCRIPTION C is a L decoder of USB packets captured via Linux USBMon interface. =head2 Methods =over =item Cdecode([RAW PACKET])> Decode a USB packet. =back =head2 Instance data The instance data for the C object consists of the following fields. =over =item id An in-kernel address of the USB Request Block (URB). Stays the same for the transaction submission and completion. Might be truncatted when reading a 64-bit capture with 32-bit file. =item type URB type. Character 'S', 'C' or 'E', for constants USB_TYPE_SUBMISSION, USB_TYPE_CALLBACK or USB_TYPE_ERROR. =item xfer_type Transfer type. USB_XFER_TYPE_ISO, USB_XFER_TYPE_INTR, USB_XFER_TYPE_CONTROL or USB_XFER_TYPE_BULK. =item ep Endpoint identification. =over 8 =item num Endpoint number. =item dir Transfer direction. "IN" or "OUT". =back =item devnum Device address. =item busnum Bus number. =item flag_setup Indicates whether setup is present and makes sense. =item flag_data Indicates whether data is present and makes sense. =item ts_sec Timestamp seconds since epoch. Subject to truncation with 32-bit Perl, which should be fine until 2038. =item ts_usec Timestamp microseconds. =item status URB status. Negative errno. =item length Length of data (submitted or actual). =item len_cap Delivered length =item setup Only present for packets with setup_flag turned on. Some contents are dependent on actual request type. =over 8 =item bmRequestType =item bRequest =item wValue =item wIndex =item wLength =back =item iso Only present for isochronous transfers. =over 8 =item error_count =item numdesc =back =item interval Isochronous packet response rate. =item start_frame Only applicable to isochronous transfers. =item xfer_flags A copy of URB's transfer_flags. =item ndesc Actual number of isochronous descriptors. =item data Packet payload. =back =head2 Exports =over =item default none =item exportable USB_TYPE_SUBMISSION, USB_TYPE_CALLBACK, USB_TYPE_ERROR, USB_XFER_TYPE_ISO, USB_XFER_TYPE_INTR, USB_XFER_TYPE_CONTROL, USB_XFER_TYPE_BULK, USB_FLAG_SETUP_IRRELEVANT, USB_FLAG_SETUP_RELEVANT, USB_FLAG_DATA_ERROR, USB_FLAG_DATA_INCOMING, USB_FLAG_DATA_OUTGOING, USB_FLAG_DATA_PRESENT, USB_TYPE_VENDOR =item tags The following tags group together related exportable items. =over =item C<:types> USB_TYPE_SUBMISSION, USB_TYPE_CALLBACK, USB_TYPE_ERROR =item C<:xfer_types> USB_XFER_TYPE_ISO, USB_XFER_TYPE_INTR, USB_XFER_TYPE_CONTROL, USB_XFER_TYPE_BULK =item C<:setup_flags> USB_FLAG_SETUP_IRRELEVANT, USB_FLAG_SETUP_RELEVANT =item C<:data_flags> USB_FLAG_DATA_ERROR, USB_FLAG_DATA_INCOMING, USB_FLAG_DATA_OUTGOING, USB_FLAG_DATA_PRESENT =item C<:setup_types> USB_TYPE_VENDOR =item C<:ALL> All the above exportable items. =back =back =head1 COPYRIGHT Copyright (c) 2013 Lubomir Rintel. This module is free software. You can redistribute it and/or modify it under the same terms as Perl itself. =head1 AUTHOR Lubomir Rintel Elkundrak@v3.skE =cut release000755001750001750 015141002125 15300 5ustar00yanickyanick000000000000NetPacket-1.8.0/xtunused-vars.t100644001750001750 14215141002125 20056 0ustar00yanickyanick000000000000NetPacket-1.8.0/xt/releaseuse Test::More 0.96 tests => 1; use Test::Vars; subtest 'unused vars' => sub { all_vars_ok(); }; Ethernet.pm100644001750001750 1457015141002125 20154 0ustar00yanickyanick000000000000NetPacket-1.8.0/lib/NetPacketpackage NetPacket::Ethernet; our $AUTHORITY = 'cpan:YANICK'; # ABSTRACT: Assemble and disassemble ethernet packets. $NetPacket::Ethernet::VERSION = '1.8.0'; use strict; use warnings; use parent 'NetPacket'; my @eth_types = qw/ ETH_TYPE_IP ETH_TYPE_ARP ETH_TYPE_APPLETALK ETH_TYPE_RARP ETH_TYPE_SNMP ETH_TYPE_IPv6 ETH_TYPE_PPP ETH_TYPE_802_1Q ETH_TYPE_IPX ETH_TYPE_PPPOED ETH_TYPE_PPPOES /; our @EXPORT_OK = ( 'eth_strip', 'ETH_HLEN', @eth_types ); our %EXPORT_TAGS = ( ALL => [@EXPORT_OK], strip => [qw(eth_strip)], types => \@eth_types, ); # # Partial list of ethernet protocol types from # http://www.isi.edu/in-notes/iana/assignments/ethernet-numbers # use constant ETH_TYPE_IP => 0x0800; use constant ETH_TYPE_ARP => 0x0806; use constant ETH_TYPE_APPLETALK => 0x809b; use constant ETH_TYPE_RARP => 0x8035; use constant ETH_TYPE_SNMP => 0x814c; use constant ETH_TYPE_IPv6 => 0x86dd; use constant ETH_TYPE_PPP => 0x880b; use constant ETH_TYPE_802_1Q => 0x8100; use constant ETH_TYPE_IPX => 0x8137; use constant ETH_TYPE_PPPOED => 0x8863; use constant ETH_TYPE_PPPOES => 0x8864; use constant ETH_HLEN => 6; # # VLAN Tag field masks # use constant VLAN_MASK_PCP => 0xE000; use constant VLAN_MASK_CFI => 0x1000; use constant VLAN_MASK_VID => 0x0FFF; # # Decode the packet # sub decode { my $class = shift; my($pkt, $parent) = @_; my $self = {}; # Class fields $self->{_parent} = $parent; $self->{_frame} = $pkt; # Decode ethernet packet if (defined($pkt)) { my($sm_lo, $sm_hi, $dm_lo, $dm_hi, $tcid); ($dm_hi, $dm_lo, $sm_hi, $sm_lo, $self->{type}) = unpack('NnNnn' , $pkt); # Check for 802.1Q VLAN tag and unpack to account for 4-byte offset if ($self->{type} == ETH_TYPE_802_1Q) { $self->{tpid} = ETH_TYPE_802_1Q; ( $tcid, $self->{type}, $self->{data} ) = unpack('x14nna*' , $pkt); # Break down VLAN tag TCI into: PCP, CFI, VID $self->{pcp} = $tcid & VLAN_MASK_PCP >> 13; $self->{cfi} = $tcid & VLAN_MASK_CFI >> 12; $self->{vid} = $tcid & VLAN_MASK_VID; } else { ( $self->{data} ) = unpack('x14a*' , $pkt); } # Convert MAC addresses to hex string to avoid representation problems $self->{src_mac} = sprintf "%08x%04x", $sm_hi, $sm_lo; $self->{dest_mac} = sprintf "%08x%04x", $dm_hi, $dm_lo; } # Return a blessed object bless($self, $class); return $self; } # # Strip header from packet and return the data contained in it # sub eth_strip { goto \&strip; } sub strip { my ($pkt) = @_; my $eth_obj = NetPacket::Ethernet->decode($pkt); return $eth_obj->{data}; } sub encode { my ($self) = shift; my @mac = map { $self->{$_} } qw/ dest_mac src_mac /; s/://g for @mac; return pack 'H12H12n a*', @mac, 0x0800, $self->{data}; } 1; =pod =head1 NAME NetPacket::Ethernet - Assemble and disassemble ethernet packets. =head1 VERSION version 1.8.0 =head1 SYNOPSIS use NetPacket::Ethernet; $eth_obj = NetPacket::Ethernet->decode($raw_pkt); $eth_pkt = NetPacket::Ethernet->encode(params...); # Not implemented $eth_data = NetPacket::Ethernet::strip($raw_pkt); =head1 DESCRIPTION C provides a set of routines for assembling and disassembling packets using the Ethernet protocol. =head2 Methods =over =item Cdecode([RAW PACKET])> Decode the raw packet data given and return an object containing instance data. This method will quite happily decode garbage input. It is the responsibility of the programmer to ensure valid packet data is passed to this method. =item Cencode(param =E value)> Return an ethernet packet encoded with the instance data specified. Not implemented. =back =head2 Functions =over =item C Return the encapsulated data (or payload) contained in the ethernet packet. This data is suitable to be used as input for other C modules. This function is equivalent to creating an object using the C constructor and returning the C field of that object. =back =head2 Instance data The instance data for the C object consists of the following fields. =over =item src_mac The source MAC address for the ethernet packet as a hex string. =item dest_mac The destination MAC address for the ethernet packet as a hex string. =item type The protocol type for the ethernet packet. =item data The payload for the ethernet packet. =back =head2 Exports =over =item default none =item exportable ETH_TYPE_IP ETH_TYPE_ARP ETH_TYPE_APPLETALK ETH_TYPE_SNMP ETH_TYPE_IPv6 ETH_TYPE_PPP =item tags The following tags group together related exportable items. =over =item C<:types> ETH_TYPE_IP ETH_TYPE_ARP ETH_TYPE_APPLETALK ETH_TYPE_SNMP ETH_TYPE_IPv6 ETH_TYPE_PPP =item C<:strip> Import the strip function C which is an alias for C =item C<:ALL> All the above exportable items. =back =back =head1 EXAMPLE The following script dumps ethernet frames by mac address and protocol to standard output. #!/usr/bin/perl -w use strict; use Net::PcapUtils; use NetPacket::Ethernet; sub process_pkt { my($arg, $hdr, $pkt) = @_; my $eth_obj = NetPacket::Ethernet->decode($pkt); print("$eth_obj->{src_mac}:$eth_obj->{dest_mac} $eth_obj->{type}\n"); } Net::PcapUtils::loop(\&process_pkt); =head1 TODO =over =item Implement C function =back =head1 COPYRIGHT Copyright (c) 2001 Tim Potter and Stephanie Wehner. Copyright (c) 1995,1996,1997,1998,1999 ANU and CSIRO on behalf of the participants in the CRC for Advanced Computational Systems ('ACSys'). This module is free software. You can redistribute it and/or modify it under the terms of the Artistic License 2.0. This program is distributed in the hope that it will be useful, but without any warranty; without even the implied warranty of merchantability or fitness for a particular purpose. =head1 AUTHOR Tim Potter Etpot@samba.orgE =cut __END__ # any real autoloaded methods go after this line