NetPacket::IPv6 - Assemble and disassemble IPv6 (Internet Protocol version 6) packets.
version 1.7.2
use NetPacket::IPv6; $ip_obj = NetPacket::IPv6->decode($raw_pkt); $ip_pkt = NetPacket::IPv6->encode($ip_obj); $ip_data = NetPacket::IPv6::strip($raw_pkt);
NetPacket::IPv6 provides a set of routines for assembling and disassembling packets using IPv6 (Internet Protocol version 6).
NetPacket::IPv6
NetPacket::IPv6->decode([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.
NetPacket::IPv6->encode()
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.
NetPacket::IPv6->pseudo_header([PACKET LENGTH], [PROTOCOL])
Return an IPv6 "pseudo-header" suitable for computing checksums for certain upper-level protocols.
NetPacket::IPv6::strip([RAW PACKET])
Return the encapsulated data (or payload) contained in the IPv6 packet. This data is suitable to be used as input for other NetPacket::* modules.
NetPacket::*
This function is equivalent to creating an object using the decode() constructor and returning the data field of that object.
decode()
data
NetPacket::IPv6::ipv6_extheader([TYPE])
Return whether the IP protocol type is an IPv6 extension header.
The instance data for the NetPacket::IPv6 object consists of the following fields.
The IP version number of this packet.
The traffic class of this packet, equivalent to the type-of-service field for IPv4.
The flow label of this packet.
The payload length (including any extension headers) in bytes for this packet.
The IP protocol number for this packet.
The hop limit for this packet, equivalent to the time-to-live field for IPv4.
The source IP address for this packet in colon-separated hextet notation.
The destination IP address for this packet in colon-separated hextet notation.
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 (IPv6_EXTHEADER_ESP).
IPv6_EXTHEADER_ESP
The encapsulated data (payload) for this IPv6 packet.
Extension headers may contain the following fields.
The extension header type number.
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.)
The remaining contents of the extension header following the next-header and length bytes.
none
The following tags group together related exportable items.
:protos
:tos
:misc
Re-exported from NetPacket::IP for convenience.
: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
:versions
IP_VERSION_IPv6
:strip
Import the strip function ipv6_strip.
ipv6_strip
:ALL
All the above exportable items.
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');
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.
Dan Book <dbook@cpan.org>
To install NetPacket, copy and paste the appropriate command in to your terminal.
cpanm
cpanm NetPacket
CPAN shell
perl -MCPAN -e shell install NetPacket
For more information on module installation, please visit the detailed CPAN module installation guide.