Not a beginner submission, but they seem few and far between now so here's a little Java solution. Functions you say? Functions (or methods) aplenty here!
I've left all classes in the default package to make compiling it easier without a Java IDE. I suppose I could have used java.net.InetAddress to format the IP address but I was writing the MAC address formatter anyway. Note the .bin filenames need to be passed on the command line -- it doesn't check and display a usage message.
Here's a compile and test run:
Code:
$ ls
ARPPacket.java Driver.java EthernetFrame.java NetDump.java reply.bin request.bin
$ javac *.java
$ java Driver request.bin
request.bin
Ethernet Header
---------------
Source MAC Address: ca:01:33:65:00:08
Destination MAC Address: ff:ff:ff:ff:ff:ff
Ethernet Frame Type: 0x0806
ARP Packet
----------
Hardware Type: 0x0001
Protocol Type: 0x0800
Hardware Size: 0x06
Protocol Size: 0x04
Opcode: 0x0001
Sender MAC Address: ca:01:33:65:00:08
Sender IP Address: 192.168.1.1
Target MAC Address: 00:00:00:00:00:00
Target IP Address: 192.168.1.2
Bookmarks