July 2009

PDF Convert

Mark Traveling

I will be traveling for next few days. I'll try and answer simple questions when time permits. I will be back early part of next week.

Mark Traveling

I will be traveling for the next 6 days. I'll be checking periodically here but I won't have access to my lab. For simple usage matters I'm sure other are willing to step up and answer in the forums, but anything more serious will have to wait until I return next tuesday.

Problems with packet.getFrameNumber()?

Hi,

I have an app that's similar in structure to the new nextEx() example, that basically creates a list containing information on all/each of the packets in a PCAP file. Per the nextEx() example, among the information output is the output from packet.getFrameNumber().

I have another app that, when given a frame number, is suppose to search through the original PCAP file, find the packet with a matching frame number, then dump out more detailed info on that packet.

The problem that I'm having is that when the 2nd app is run, it can't find the packet with the matching frame number. It appears that the frame numbers output from the 1st app are completely different from the frame numbers?

What does packet.getFrameNumber() actually do? Is it getting some number that is actually in the PCAP file, or is it just an incrementing number or something like that, that jNetPcap is keeping track of?

What I really need is something, some number that is constant, that I can use to reference/identify/locate a given packet within a PCAP Sad...

BTW, it may be that I missed it, but I've been looking through the Javadocs, and I don't see a getFrameNumber() method in PcapPacket. I just found getFrameNumber() in JPacket, but I'm not using JPacket (at least, I don't think I am).

Thanks,
Jim

crash dump analysis

hi,

I'm looking at a crash
while running an application with DDD attached to the Java process
on exiting pcap loop (stop the capture).

What might be a reason for such a crash?

Thank you

JScanner.scan throwing IllegalArgumentException when scanning JMemoryPacket

Since updating from r795, I am now getting an exception when scanning a packet created with JMemoryPacket(byte[]).

Exception in thread "Thread-16" java.lang.IllegalArgumentException: wirelen < buffer len
at org.jnetpcap.packet.JScanner.scan(Native Method)
at org.jnetpcap.packet.JScanner.scan(JScanner.java:357)
at org.jnetpcap.packet.JScanner.scan(JScanner.java:335)

The problem appears that scan now expects that the "wirelen" of the packet to have been set. I do not see a way to specify the wire length of the packet, either from the constructor or from a setter.

Looking at the two forms of the JMemoryPacket constructors, JMemoryPacket(byte[] buffer) and JMemoryPacket(int id, byte[] buffer), the later is setting "wirelen" [header.setWirelen(buffer.length);]. Is that line simply missing from the other constructor?

Build jnetpcap-1.3.b0006 available

Latest snapshot of the development trunk is available for download from distribution server:

https://sourceforge.net/projects/jnetpcap/files/

The latest build fixes numerous bugs and adds support for Ubuntu and RHEL linuxes. The builds were also released with both the official packaging such as RPM/DEB and in compressed tar format.

Build 1.3.b0005 was a private build and differs only slightly with 1.3.b0006.

Build changes and new platforms

An update on builds for those interested.

I've been steadily improving the build scripts over last couple of releases. This is mainly due to the fact that we have a lot more platforms getting ready for support coming. With that in mind, the build scripts now determine the pre-installed "libcap" package version on the build system and appropriately set a global def macro LIBPCAP_VERSION. This is then used to determine support for certain libpcap functions. Not all functions were introduced into libpcap all at the same, but steadily over the many releases of that library.

This allows jNetPcap to be compiled on systems with libpcap version 0.8.0 or higher. If ever needed we could even make the compatiblity level lower then that, but I don't see any need for it at this time. However if we ever needed to support an older OS such as RHEL 2 or 3, then it would actually be quiet trivial to disable certain functions and provide Pcap.is*Supported accessors just like jNetPcap provides support for Pcap.isSendPacketSupported and few others.

This weekend we ported to Redhat Enterprise Linux 4 and jNetPcap already compiled on ubuntu platforms with just a tiny whimper. So I'm also going to release RHEL4 and ubuntu with this next release.

Over next quarter (2 - 3 months):

I will work on OpenSolaris 2009 and Solaris 10 which are ready to be ported.

After Solaris its is FreeBSD and I'm also working on OpenDarwin and OSX10.5 (Leopard). BSD port should make port to OSX/Darwin fairely straight forward.

Lastly, I've placed a large order for duplicate servers in AMD64bit architecture. The AMD port will be compatible with intel 64 arch. Since the number of supported platforms is growing rapidly, the build scripts will be changed to allow multi-platform network builds to be done from centralized location. This will be a separate jnetpcap module dedicated for master builds.

Capturing RTP Streams.

Hi,

I'm looking to write a packet capture routine to do the following;

1. Read Packets from 2-3 network interfaces;

2. Look for a specific pattern (e.g SIP (ACK))

3. Dump the specific UDP stream (RTP) to file i.e. from a specific src/dst port and src/dstIP.

The ideas is to be able to capture stimulations RTP streams on the network based on analysing passing traffic.

Is this possible with jNetpcap?

All the Best,

Shadi

Pcap.nextEx

Here is an example that demonstrates how to use Pcap.nextEx method. The example uses various peering methods, Libpcap DLT to jNetPcap protocol ID mapping, initiating a new PcapPacket object and invoking the scanner on a newly created packet.
Download Source from SVN:


package org.jnetpcap.examples;

import org.jnetpcap.Pcap;
import org.jnetpcap.PcapHeader;
import org.jnetpcap.nio.JBuffer;
import org.jnetpcap.nio.JMemory;
import org.jnetpcap.packet.JRegistry;
import org.jnetpcap.packet.PcapPacket;
import org.jnetpcap.packet.format.FormatUtils;
import org.jnetpcap.protocol.lan.Ethernet;
import org.jnetpcap.protocol.network.Ip4;

/**
 * This example opens up a capture file found in jNetPcap's installation
 * directory for of the "source" distribution package and iterates over every
 * packet. The example also demonstrates how to property peer
 * PcapHeader, JBuffer and initialize a new
 * PcapPacket object which will contain a copy of the peered
 * packet and header data. The libpcap provide header and data are stored in
 * libpcap private memory buffer, which will be overriden with each iteration of
 * the loop. Therefore we use the constructor in PcapPacket to
 * allocate new memory to store header and packet buffer data and perform the
 * copy. The we
 * 
 * @author Mark Bednarczyk
 * @author Sly Technologies, Inc.
 */
public class NextExExample {

	/**
	 * Start of our example.
	 * 
	 * @param args
	 *          ignored
	 */
	public static void main(String[] args) {
		final String FILE_NAME = "tests/test-l2tp.pcap";
		StringBuilder errbuf = new StringBuilder(); // For any error msgs

		/***************************************************************************

1.5.1.1 - RHEL

Compiling on Red Hat Enterprise version, requires few extra step in order to install the neccessary build environment.

In addtion Red Hat Enterprise Linux version 4 uses fairely old version of libpcap (version 0.8.3) which is below standard requirements of jNetPcap installations. However in order to provide support on these still common platforms in production environments, RHEL installations have a lower requirement for libpcap. Libpcap versions below 0.9.7 do not provide support for 2 functions: pcap_injet and pcap_sendpacket. These functions are ommitted from jNetPcap API. When using jNetPcap API, you can check if these 2 functions are supported with methods: Pcap.isPacketInjectSupported() and Pcap.isPacketSendSupported().

The following packages and their dependencies need to be installed for a build environment neccessary to compile jNetPcap software:

redhat> uname -a

Linux localhost.localdomain 2.6.9-89.ELsmp #1 SMP Mon Apr 20 10:34:33 EDT 2009 i686 i686 i386 GNU/Linux

redhat> rpm -q libpcap jdk gcc-c++ ant ant-nodeps subversion junit rpm-devel

libpcap-0.8.3-12.el4_6.1
jdk-1.6.0_02-fcs
gcc-c++-3.4.6-11
ant-1.6.5-4jpp
ant-nodeps-1.6.5-4jpp
subversion-1.1.4-2.ent
junit-3.8.2-4jpp
rpm-devel-4.3.3-32_nonptl

Some of these packages are not easy to aquire for red-hat platforms. The rpms can be either downloaded manually or using an installer such as yum.

Installing Sun's java JDK

You have to download the linux distribution manually from http://java.sun.com. The self extracting and installing package is very easy to install.

If there is already a java environment installed you need to setup alternatives to Sun's JDK.


alternatives --install /usr/bin/java java /usr/java/latest/bin/java 1
alternatives --install /usr/bin/javah javah /usr/java/latest/bin/javah 1