1NetPacket::IP(3)      User Contributed Perl Documentation     NetPacket::IP(3)
2
3
4

NAME

6       NetPacket::IP - Assemble and disassemble IP (Internet Protocol)
7       packets.
8

VERSION

10       version 1.7.2
11

SYNOPSIS

13         use NetPacket::IP;
14
15         $ip_obj = NetPacket::IP->decode($raw_pkt);
16         $ip_pkt = NetPacket::IP->encode($ip_obj);
17         $ip_data = NetPacket::IP::strip($raw_pkt);
18

DESCRIPTION

20       "NetPacket::IP" provides a set of routines for assembling and
21       disassembling packets using IP (Internet Protocol).
22
23   Methods
24       "NetPacket::IP->decode([RAW PACKET])"
25           Decode the raw packet data given and return an object containing
26           instance data.  This method will quite happily decode garbage
27           input.  It is the responsibility of the programmer to ensure valid
28           packet data is passed to this method.
29
30       "NetPacket::IP->encode()"
31           Return an IP packet encoded with the instance data specified. This
32           will infer the total length of the packet automatically from the
33           payload length and also adjust the checksum.
34
35   Functions
36       "NetPacket::IP::strip([RAW PACKET])"
37           Return the encapsulated data (or payload) contained in the IP
38           packet.  This data is suitable to be used as input for other
39           "NetPacket::*" modules.
40
41           This function is equivalent to creating an object using the
42           "decode()" constructor and returning the "data" field of that
43           object.
44
45   Instance data
46       The instance data for the "NetPacket::IP" object consists of the
47       following fields.
48
49       ver The IP version number of this packet.
50
51       hlen
52           The IP header length of this packet.
53
54       flags
55           The IP header flags for this packet.
56
57       foffset
58           The IP fragment offset for this packet.
59
60       tos The type-of-service for this IP packet.
61
62       len The length (including length of header) in bytes for this packet.
63
64       id  The identification (sequence) number for this IP packet.
65
66       ttl The time-to-live value for this packet.
67
68       proto
69           The IP protocol number for this packet.
70
71       cksum
72           The IP checksum value for this packet.
73
74       src_ip
75           The source IP address for this packet in dotted-quad notation.
76
77       dest_ip
78           The destination IP address for this packet in dotted-quad notation.
79
80       options
81           Any IP options for this packet.
82
83       data
84           The encapsulated data (payload) for this IP packet.
85
86   Exports
87       default
88           none
89
90       exportable
91           IP_PROTO_IP IP_PROTO_ICMP IP_PROTO_IGMP IP_PROTO_IPIP IP_PROTO_TCP
92           IP_PROTO_UDP IP_VERSION_IPv4
93
94       tags
95           The following tags group together related exportable items.
96
97           ":protos"
98               IP_PROTO_IP IP_PROTO_ICMP IP_PROTO_IGMP IP_PROTO_IPIP
99               IP_PROTO_TCP IP_PROTO_UDP
100
101           ":versions"
102               IP_VERSION_IPv4
103
104           ":strip"
105               Import the strip function "ip_strip".
106
107           ":ALL"
108               All the above exportable items.
109

EXAMPLE

111       The following script dumps IP frames by IP address and protocol to
112       standard output.
113
114         #!/usr/bin/perl -w
115
116         use strict;
117         use Net::PcapUtils;
118         use NetPacket::Ethernet qw(:strip);
119         use NetPacket::IP;
120
121         sub process_pkt {
122             my ($user, $hdr, $pkt) = @_;
123
124             my $ip_obj = NetPacket::IP->decode(eth_strip($pkt));
125             print("$ip_obj->{src_ip}:$ip_obj->{dest_ip} $ip_obj->{proto}\n");
126         }
127
128         Net::PcapUtils::loop(\&process_pkt, FILTER => 'ip');
129

TODO

131       IP option decoding - currently stored in binary form.
132       Assembly of received fragments
133
135       Copyright (c) 2001 Tim Potter and Stephanie Wehner.
136
137       Copyright (c) 1995,1996,1997,1998,1999 ANU and CSIRO on behalf of the
138       participants in the CRC for Advanced Computational Systems ('ACSys').
139
140       This module is free software.  You can redistribute it and/or modify it
141       under the terms of the Artistic License 2.0.
142
143       This program is distributed in the hope that it will be useful, but
144       without any warranty; without even the implied warranty of
145       merchantability or fitness for a particular purpose.
146

AUTHOR

148       Tim Potter <tpot@samba.org>
149
150       Stephanie Wehner <atrak@itsx.com>
151
152
153
154perl v5.30.1                      2020-01-30                  NetPacket::IP(3)
Impressum