您的位置:首页 > 运维架构 > Linux

How to Install JPCap on Linux

2009-04-27 20:18 1311 查看
Jes s e Caulfield

Key Bridge LLC

March 29, 2008

In this tutorial I will de scribe how to ins tall JPCap from source code on Linux (Ubunty 7.10 or Debian

4.0).

JPCap is an open - source Java library released u n de r the GNU LGPL and de signed to enable the

capt uring an d sen ding ne twork packet s in Java. JPCap is developed by Keita Fujii an d the Univer sity

of California and Irvine.

The JPCap home page is h t t p: / / n e t research.ics.uci.edu / kf ujii / jpcap / d oc /

JPCap is a Java Native Library Implement ation (JNI) of the po p ular libpcap library an d sho uld therefor

work on any OS which su p por t s libpcap. libpcap is a user - level packet capture library tha t provides a

commo n, sys tem- indepe n de nt API for low- level network mo ni toring. libpcap is also ope n - source

sof tware developed an d maint ained by TCPDump.org.

We will use JPCap and libpcap on the Linux operating sys tem but the both libraries work on Microsof t

Windows (WinPcap), Linux, FreeBSD, an d Mac OS X.

JPCap su p por t s the following types of network da ta:

Layer 2: Ethernet Datagrams

Layer 3: IPv4 & Ipv6 ARP/RARP

TCP, UDP an d ICMPv4.

JPCap recogni zes the packet types enume rated above but can capt ure any type of ne twork t raffic as a

raw packet (i.e., as an ins tance of the Packet clas s) which contains the Packet's whole da t a. This

feature allows Java a p plications to analyze any packet type.

Step 1: Preparing the System

Following are ins t r uctions to ins tall JPCap on a f resh ins tallation of Ubuntu 7.10 of Debian 4.0.

Ins tall the neces sary developme nt sof tware packages to create a u s able developme nt environme nt:

Ins tall the GNU compiler an d basic libraries

% su do a pt - get ins tall build - es sential

Ins tall the linux pca p library

% su do a pt - get ins tall libpcap0.8

Ins tall the Java SDK from Sun

% su do a pt - get ins tall s un - java6 - sdk

Download the JPCap source and ext ract it into your working directory

ht t p: / / n e t research.ics.uci.edu / kfujii / j pcap / j pcap - 0.7.tar.gz

ht tp: / /KeyBridgeGlobal.com Page 1

Key Bridge LLC

Step 2: Building & Installing the JPCap JNI library

In a terminal window, navigate to the [jpcap] / s rc / c directory. For example:

~ / j pcap - 0.7 / s rc / c

[IMPORTANT] Edit the J***A_DIR Makefile ent ry to point to your version of jni.h

You can find it quickly with the following comma n d:

$ find / u s r - name jni.h

/ u s r / lib / jvm/ j ava - 6 - s un - 1.6.0.03 / include / jni.h

The Makefile sho uld then rea d

J***A_DIR = / u s r / lib / jvm/ j ava - 6 - su n - 1.6.0.03

In the terminal window u n der the [jpcap] / s rc / c di rectory type make to create the share d library

$ make

This will create the file 'libjpcap.so'.

Copy 'libjpcap.so' your sys tem' s Java JNI library directory

'[Java - di r] / j re / lib / < a rch >' where < a rch > is either 'i386' or 'sparc'.

For my ins tallation, this was / u s r / lib / jvm/ j ava - 6 - su n / j re / lib /i386

Another option is to copy the library to the directory where your ap plication is locate d.

Step 3: Building and Installing the JPCap JAR file

In a terminal window, nagivate to the [jpcap] / s rc / j ava directory. For example:

~ / j pcap - 0.7 / s rc / java

There should be one sub directory name d 'jpcap'

Compile all of the .java files in the 'jpcap' and 'jpcap / p acket' di rectories.

$ find . - name "*.java" - exec javac {} / ;

You may see the following er ror for IPPacket.java - ignore it.

"Note: . /jpcap / p acket /IPPacket.java uses u nchecked or u ns afe operations."

Create the JAR file

jar - cf jpcap.jar jpcap

Confirm the content s of your JAR file with the following comma n d:

jar - tvf jpcap.jar

Copy the new jpcap.jar file to your Java extentions di rectory

$ cp jpcap.jar '[Java - dir] / j re /lib / ext /

For my ins tallation, this was / u s r / lib / jvm/ j ava - 6 - su n / j re / lib / ext

Another option is to copy the JAR file to your ap plication' s di rectory an d ad d it to your

CLASSPATH.

You are now rea dy to begin using the JPCAP Java Native Interface Library.

ht
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: