perl - How do I modify the destination MAC address in a packet? -
I have a question about a very basic thing in Perl, but I can not find an efficient solution. / P>
Here is a bit of context before I use etc and when I am in my function which process packets (used by pcap_loop
), then I The $ packet
scalar is available in which my entire packet (Ethernet header + IP header + Tcp / udp header + payload).
What do I want to do to replace the first 6 bytes of this $ packet
(Ethernet Destination) $ packet
that I Pcap_sendpacket
by using a user defined destination MAC address (passed as a command line argument for example), such as 00:11: 22: 33: 44: 55
. Therefore, I can split the user defined address (using split
) to get every 6 parts of a destination defined address, and call it hex
I can change the hex using the function, but now I want to modify the first bytes of my packet to replace it with these hex
ed bytes. How should I proceed?
I thought using some combination (.) I think this solution is dirty.
I was thinking in C (because I did some time ago, but I have to do this in Perl), once I have my " u_char packet []
" I had to do memcpy
of the ethernet address provided by my user, in the first 6 bytes of my packet []
and it worked.
The function is used to make a bit vector in the form of a scalar value.
Use strict; Use warnings; My $ packet; # Set the packet something ... my $ address = '00: 11: 22: 33: 44: 55 '; My @bytes = map {hex} partition (/: /, $ address); For my $ i (0 .. $ # bytes) {vec ($ packet, $ i, 8) = $ bytes [$ i]; }
Comments
Post a Comment