4 Replies - 666 Views - Last Post: 19 December 2011 - 02:23 PM Rate Topic: -----

#1 pgfdbug  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 63
  • Joined: 14-April 08

Packet Buffer and Loop

Posted 17 December 2011 - 04:52 PM

I have run into a problem and I cant seem to find any good documentation on a beginners level for a solution. I need to make it so my program reads several small packets into one packet. I found some info on jnetpcap but its a little above my head. The program is below. Any input is very much appreciated.

package prealert;

import org.apache.log4j.Logger;
import org.apache.log4j.PropertyConfigurator;

import jpcap.JpcapCaptor;
import jpcap.NetworkInterface;

public class Listener {

	private NetworkInterface[] devices;
	private NetworkInterface deviceName;
	private Reciever reciever;
	private JpcapCaptor jpcap;
	private Logger log;


	public Listener() {
		PropertyConfigurator.configure("log4j.properties");
		log = Logger.getRootLogger();
		log.debug("Log4j has been initialized");
		devices = JpcapCaptor.getDeviceList();
		for (int i = 0; i < devices.length; i++) {
			log.info(devices[i].description);
		}
		deviceName = devices[0];
		reciever = new Reciever();
		try {
			jpcap = JpcapCaptor.openDevice(deviceName, 2000, true, 100);
		} catch (Exception e) {
			log.error("Error with JPcapCreation", e);
		}
		reciever.jpcap = jpcap;
		reciever.start();
		new SetBoard(SetBoard.DEFAULT).start();
	}

	public static void main(String args[]) {
			new Listener();
	}
}

This post has been edited by pgfdbug: 17 December 2011 - 04:54 PM


Is This A Good Question/Topic? 0
  • +

Replies To: Packet Buffer and Loop

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8329
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Packet Buffer and Loop

Posted 17 December 2011 - 05:03 PM

What not use the standard API BufferedInputStream that has a read() method that receives as parameter a buffer and, what interest you, and offset in the buffer where to put the newly arrived data ?
Was This Post Helpful? 1
  • +
  • -

#3 pgfdbug  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 63
  • Joined: 14-April 08

Re: Packet Buffer and Loop

Posted 17 December 2011 - 05:48 PM

Wouldn't BufferInputStream give me the same problem. It would look at the packet and pass it on. Every packet will vary in size and timing, in some cases 2 small packets will give me everything I need in others it may take 15 packets. This is where Im running into my problems.
Was This Post Helpful? 0
  • +
  • -

#4 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8329
  • View blog
  • Posts: 31,857
  • Joined: 06-March 08

Re: Packet Buffer and Loop

Posted 17 December 2011 - 05:56 PM

That is why you specify the offset in your read() method
You start with an offset of 0 and add to it the length of the last received packet
Was This Post Helpful? 1
  • +
  • -

#5 pgfdbug  Icon User is offline

  • D.I.C Head

Reputation: -2
  • View blog
  • Posts: 63
  • Joined: 14-April 08

Re: Packet Buffer and Loop

Posted 19 December 2011 - 02:23 PM

Thank you for the suggestions it has def. given me a place to start and build from. I may just move to a different class and collect the incoming packets after they have been turned to strings.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1