1Net::Packet::Frame(3) User Contributed Perl DocumentationNet::Packet::Frame(3)
2
3
4
6 Net::Packet::Frame - object encapsulator for Net::Packet layers
7
9 require Net::Packet::Frame;
10
11 # Because we passed a layer 3 object, a Net::Packet::DescL3 object
12 # will be created automatically, by default. See Net::Packet::Env
13 # regarding changing this behaviour. Same for Net::Packet::Dump.
14 my $frame = Net::Packet::Frame->new(
15 l3 => $ipv4, # Net::Packet::IPv4 object
16 l4 => $tcp, # Net::Packet::TCP object
17 # (here, a SYN request, for example)
18 );
19
20 # Without retries
21 $frame->send;
22 sleep(3);
23 if (my $reply = $frame->recv) {
24 print $reply->l3->print."\n";
25 print $reply->l4->print."\n";
26 }
27
28 # Or with retries
29 for (1..3) {
30 $frame->reSend;
31
32 until ($Env->dump->timeout) {
33 if (my $reply = $frame->recv) {
34 print $reply->l3->print."\n";
35 print $reply->l4->print."\n";
36 last;
37 }
38 }
39 }
40
42 In Net::Packet, each sent and/or received frame is parsed and converted
43 into a Net::Packet::Frame object. Basically, it encapsulates various
44 layers (2, 3, 4 and 7) into an object, making it easy to get or set
45 information about it.
46
47 When you create a frame object, a Net::Packet::Desc object is created
48 if none is found in the default $Env object (from Net::Packet module),
49 and a Net::Packet::Dump object is also created if none is found in this
50 same $Env object. You can change this beheaviour, see Net::Packet::Env.
51
52 Two new invocation method exist, one with attributes passing, another
53 with raw attribute. This second method is usually used internally, in
54 order to unpack received frame into all corresponding layers.
55
57 env Stores the Net::Packet::Env object. The default is to use $Env from
58 Net::Packet. So, you can send/recv frames to/from different envi‐
59 ronements.
60
61 raw Pass this attribute when you want to decode a raw string captured
62 from network. Usually used internally.
63
64 padding
65 In Ethernet world, a frame should be at least 60 bytes in length.
66 So when you send frames at layer 2, a padding is added in order to
67 achieve this length, avoiding a local memory leak to network. Also,
68 when you receive a frame from network, this attribute is filled
69 with what have been used to pad it. This padding feature currently
70 works for IPv4 and ARP frames.
71
72 l2 Stores a layer 2 object. See Net::Packet for layer 2 classes hier‐
73 archy.
74
75 l3 Stores a layer 3 object. See Net::Packet for layer 3 classes hier‐
76 archy.
77
78 l4 Stores a layer 4 object. See Net::Packet for layer 4 classes hier‐
79 archy.
80
81 l7 Stores a layer 7 object. See Net::Packet::Layer7.
82
83 reply
84 When recv method has been called on a frame object, and a corre‐
85 sponding reply has been catched, a pointer is stored in this
86 attribute.
87
88 timestamp
89 When a frame is packed/unpacked, the happening time is stored here.
90
91 encapsulate
92 Give the type of the first encapsulated layer. It is a requirement
93 to parse a user provided raw string.
94
96 new Object constructor. If a $Env-desc> object does not exists, one is
97 created by analyzing attributes (so, either one of
98 Net::Packet::DescL2, Net::Packet::DescL3. Net::Packet::DescL4 can‐
99 not be created automatically for now). The same behaviour is true
100 for $Env-dump> object. You can change this default creation behav‐
101 iour, see Net::Packet::Env. Default values:
102
103 timestamp: gettimeofday(),
104
105 env: $Env
106
107 getLengthFromL7
108 getLengthFromL4
109 getLengthFromL3
110 getLengthFromL2
111 Returns the raw length in bytes from specified layer.
112
113 getLength
114 Alias for getLengthFromL3.
115
116 unpack
117 Unpacks the raw string from network into various layers. Returns 1
118 on success, undef on failure.
119
120 pack
121 Packs various layers into the raw string to send to network.
122 Returns 1 on success, undef on failure.
123
124 send
125 On the first send invocation in your program, the previously cre‐
126 ated Net::Packet::Dump object is started (if available). That is,
127 packet capturing is run. The timestamp attribute is set to the
128 sending time. The env attribute is used to know where to send this
129 frame.
130
131 reSend
132 Will call send method if no frame has been recv'd, that is the
133 reply attribute is undef.
134
135 getFilter
136 Will return a string which is a pcap filter, and corresponding to
137 what you should receive compared with the frame request.
138
139 recv
140 Searches framesSorted or frames from Net::Packet::Dump for a match‐
141 ing response. If a reply has already been received (that is reply
142 attribute is already set), undef is returned. It no reply is
143 received, return undef, else the Net::Packet::Frame response.
144
145 print
146 Just returns a string in a human readable format describing
147 attributes found in the layer.
148
149 dump
150 Just returns a string in hexadecimal format which is how the layer
151 appears on the network.
152
153 isEth
154 isRaw
155 isNull
156 isSll
157 isPpp
158 isArp
159 isIpv4
160 isIpv6
161 isIp - either IPv4 or IPv6
162 isPpplcp
163 isVlan
164 isPppoe
165 isLlc
166 isTcp
167 isUdp
168 isIcmpv4
169 isIcmp - currently only ICMPv4
170 isCdp
171 isStp
172 isOspf
173 isIgmpv4
174 is7 Returns 1 if the Net::Packet::Frame is of specified layer, 0 other‐
175 wise.
176
178 Patrice <GomoR> Auffret
179
181 Copyright (c) 2004-2006, Patrice <GomoR> Auffret
182
183 You may distribute this module under the terms of the Artistic license.
184 See LICENSE.Artistic file in the source distribution archive.
185
187 NetPacket, Net::RawIP, Net::RawSock
188
189
190
191perl v5.8.8 2006-11-23 Net::Packet::Frame(3)