1NetPacket::Ethernet(3)User Contributed Perl DocumentationNetPacket::Ethernet(3)
2
3
4
6 NetPacket::Ethernet - Assemble and disassemble ethernet packets.
7
9 version 1.7.2
10
12 use NetPacket::Ethernet;
13
14 $eth_obj = NetPacket::Ethernet->decode($raw_pkt);
15 $eth_pkt = NetPacket::Ethernet->encode(params...); # Not implemented
16 $eth_data = NetPacket::Ethernet::strip($raw_pkt);
17
19 "NetPacket::Ethernet" provides a set of routines for assembling and
20 disassembling packets using the Ethernet protocol.
21
22 Methods
23 "NetPacket::Ethernet->decode([RAW PACKET])"
24 Decode the raw packet data given and return an object containing
25 instance data. This method will quite happily decode garbage
26 input. It is the responsibility of the programmer to ensure valid
27 packet data is passed to this method.
28
29 "NetPacket::Ethernet->encode(param => value)"
30 Return an ethernet packet encoded with the instance data specified.
31 Not implemented.
32
33 Functions
34 "NetPacket::Ethernet::strip([RAW PACKET])"
35 Return the encapsulated data (or payload) contained in the ethernet
36 packet. This data is suitable to be used as input for other
37 "NetPacket::*" modules.
38
39 This function is equivalent to creating an object using the
40 "decode()" constructor and returning the "data" field of that
41 object.
42
43 Instance data
44 The instance data for the "NetPacket::Ethernet" object consists of the
45 following fields.
46
47 src_mac
48 The source MAC address for the ethernet packet as a hex string.
49
50 dest_mac
51 The destination MAC address for the ethernet packet as a hex
52 string.
53
54 type
55 The protocol type for the ethernet packet.
56
57 data
58 The payload for the ethernet packet.
59
60 Exports
61 default
62 none
63
64 exportable
65 ETH_TYPE_IP ETH_TYPE_ARP ETH_TYPE_APPLETALK ETH_TYPE_SNMP
66 ETH_TYPE_IPv6 ETH_TYPE_PPP
67
68 tags
69 The following tags group together related exportable items.
70
71 ":types"
72 ETH_TYPE_IP ETH_TYPE_ARP ETH_TYPE_APPLETALK ETH_TYPE_SNMP
73 ETH_TYPE_IPv6 ETH_TYPE_PPP
74
75 ":strip"
76 Import the strip function "eth_strip" which is an alias for
77 "NetPacket::Ethernet::strip"
78
79 ":ALL"
80 All the above exportable items.
81
83 The following script dumps ethernet frames by mac address and protocol
84 to standard output.
85
86 #!/usr/bin/perl -w
87
88 use strict;
89 use Net::PcapUtils;
90 use NetPacket::Ethernet;
91
92 sub process_pkt {
93 my($arg, $hdr, $pkt) = @_;
94
95 my $eth_obj = NetPacket::Ethernet->decode($pkt);
96 print("$eth_obj->{src_mac}:$eth_obj->{dest_mac} $eth_obj->{type}\n");
97 }
98
99 Net::PcapUtils::loop(\&process_pkt);
100
102 Implement "encode()" function
103
105 Copyright (c) 2001 Tim Potter and Stephanie Wehner.
106
107 Copyright (c) 1995,1996,1997,1998,1999 ANU and CSIRO on behalf of the
108 participants in the CRC for Advanced Computational Systems ('ACSys').
109
110 This module is free software. You can redistribute it and/or modify it
111 under the terms of the Artistic License 2.0.
112
113 This program is distributed in the hope that it will be useful, but
114 without any warranty; without even the implied warranty of
115 merchantability or fitness for a particular purpose.
116
118 Tim Potter <tpot@samba.org>
119
120
121
122perl v5.30.0 2019-07-26 NetPacket::Ethernet(3)