Skip to Main Content

Java Programming

Announcement

For appeals, questions and feedback about Oracle Forums, please email oracle-forums-moderators_us@oracle.com. Technical questions should be asked in the appropriate category. Thank you!

Reading hex files

807591Mar 27 2008 — edited Mar 27 2008
Hi, im having trouble reading a hex file in java. I want my program to search through the file and look for IP and ARP packets and then print out there values and their correpsonding bytes (ip, headerlen, id, checksum, etc) I have some code for it but its not quite working. Could some one please give me some tips on how to improve my code. Cheers:
private void getPacketData() throws IOException
	{	
		System.out.println("Packet Data information: ");
		String line = "";
		String[] values = null;
		InputStream src = new FileInputStream("C:/Users/Andrew/workspace/tcpdump_text_file");

		BufferedReader reader = new BufferedReader(new InputStreamReader(src));
		
		while(src.read() != -1)
		{
			for(int i = 0; i < 20; i++) {
				line = reader.readLine();
				values = line.split("");
				if(values.length > 5 && values[4].matches("0800"))
				{
					System.out.println("IP packet"); showbytes(2, src);
				}
				else if(values.length > 5 && values[4].matches("0806"))
				{
					System.out.println("ARP packet"); showbytes(2, src);
				}
				else {
					showbytes(2, src);
				}
			}
		}
Comments
Locked Post
New comments cannot be posted to this locked post.
Post Details
Locked on Apr 24 2008
Added on Mar 27 2008
13 comments
1,238 views