Usage questions

18 replies [Last post]
Mark Bednarczyk
Mark Bednarczyk's picture
Offline
Joined: 03/22/2008

Post any questions about the API and its usage.

Sly Technologies, Inc.
R&D

omoser
Offline
Joined: 10/10/2008
64Bit environments

Hello

I'm trying to evalute jNetPcap for a university project. When building it from svn source on my amd64 machine, I get the following error:

jnetpcap_utils.cpp:56: Error: cast from 'void*' to 'jint' loses precision

The prebuilt shared library is compiled on a 32bit machine so I cannot use it. Since I'm not a C expert, do you have a hint how to solve this problem?

bye

Oliver

Mark Bednarczyk
Mark Bednarczyk's picture
Offline
Joined: 03/22/2008
Here is the line that

Here is the line that generates that error:
jlong lp = (jlong) (jint) ptr;

Its just a matter of semantics how the PTR is stored in java object. A long should be enough store the ptr value. I haven't compiled this code on a 64bit machine yet, so I can't say with certainty what needs to be done.

I do have a AMD64 machine available and I will release the 64 bit version at some point.

If you did fix this or had encountered issues trying to fix this that are 64bit specific please let me know as it will be helpful.

This will probably require a best cast then what I have implemented or #ifdef _64BIT to try something out. As far as I know 64bit address pointers are still 64 bits wide.

Sly Technologies, Inc.
R&D

Mark Bednarczyk
Mark Bednarczyk's picture
Offline
Joined: 03/22/2008
Change the cast to

Change the cast to UINT_PTR

jlong lp = (UINT_PTR) ptr;

I did a little bit of research and using u_long cast is not portable between 32bit and 64bit machines. I've updated the JNI code appropriately now and it shouldn't give any more trouble between hardware arch types.

I updated the fix in SVN. This fix will released in version 1.2 - no 64bit official support though Sad But it should help you compile it on 64 bit without getting that error.

Sly Technologies, Inc.
R&D

Mark Bednarczyk
Mark Bednarczyk's picture
Offline
Joined: 03/22/2008
Here is the full updated

Here is the full updated functions that does the native pointer to java long conversion back and forth. Just to be correct here:

jlong toLong(void *ptr) {
#ifndef WIN32
	jlong lp = (intptr_t) ptr;
#else
	jlong lp = (UINT_PTR) ptr;
#endif

	return lp;
}

void *toPtr(jlong lp) {
	
#ifndef WIN32
	void *ptr = (void *) ((intptr_t) lp);
#else
	void *ptr = (void *) ((UINT_PTR) lp);
#endif
	return ptr;
}

This should fix any compatibility issues between bus widths. These 2 utility methods are used by all methods to convert back and forth so everything in jNetPcap DLLs relies on them Smile Easy fix. Thanks for pointing that out omoser Smile

Sly Technologies, Inc.
R&D

angelo
Offline
Joined: 10/23/2008
Example

Hi everibody, i'm evaluating jnetpcap for a small project (an high performance capturer),i'm interested in using this library if there is the possibility to tune the circular kernel buffer (i mean the WinpCap buffer which is 1MB size by default) in order to avoid packets loss in case of an high bitrate burst. is it possible? what's the maximum size this buffer can be set?
is there any opensource project (or example) that uses jnetpcap I can start learning from?
Thanks in advance.
Angelo

Mark Bednarczyk
Mark Bednarczyk's picture
Offline
Joined: 03/22/2008
On win32 platform you can use

On win32 platform you can use WinPcap.setMinToCopy(int) and WinPcap.setBuff(int)which will increase the buffer size to something bigger. If you need to hold on to the packets for longer than that, you need to copy the buffer to new location. I would suggest using direct byte buffer which allows you do native copy from libpcap buffer.

Sly Technologies, Inc.
R&D

angelo
Offline
Joined: 10/23/2008
On win32 platform you can use...

Ok then I will use java.nio and fileChannels with direct buffers to copy the buffer stuff fastly.
Does anybody know about any opensource project which use jnetpcap?(apart from jnetstream) i could not find any project in sourceforge.
thanks.

ArtPetroff
Offline
Joined: 11/28/2008
method getHardwareAddress()

Exception in thread "AWT-EventQueue-0" java.lang.UnsatisfiedLinkError: org.jnetpcap.PcapUtils.getHardwareAddress(Ljava/lang/String;)[B
at org.jnetpcap.PcapUtils.getHardwareAddress(Native Method)

It might that I need some .dll? but I don't know which. Could you help me, please?

PS Sorry for my bad english.

Mark Bednarczyk
Mark Bednarczyk's picture
Offline
Joined: 03/22/2008
On win32

You are missing the jnetpcap.dll file from your PATH variable.

Include the folder where jnetpcap.dll resides in your PATH variable (set in c:\autoexec.bat or your favorates IDE's launch environmental settings) and that would be in the jnetpcap-1.2.rc1 directory once you unzip. Or copy jnetpcap.dll to c:\windows\system32 directory. You don't need to include the dll directory in the path if you copy to system32 folder.

Sly Technologies, Inc.
R&D

ArtPetroff
Offline
Joined: 11/28/2008
Thanks

I've forgot to copy new version of jnetpcap.dll to \system32\ and was trying to work with v1.1.
head like a sieve)

Mark Bednarczyk
Mark Bednarczyk's picture
Offline
Joined: 03/22/2008
You are welcome. Easy to do.

You are welcome. Easy to do. I need to setup a win32 installer. Something on the todo list.

Sly Technologies, Inc.
R&D

jmeros
Offline
Joined: 12/16/2008
Using Wireshark/Ethereal dlls for decoding packets

Hi all,

I started to take a look on jNP some days ago and read the documentation to analyse the possibility of using it on a small project. I need to decode some network messages (SIP and some other private protocols) and make some statistics about this messages. I would not like to implement everything from scratch, so I realized that I already have Wireshark/Ethereal dlls that do this work of decoding the messages.
Somebody has an idea if would be possible to integrate this dlls with jNP?

Thanks in advance,
Jader

Mark Bednarczyk
Mark Bednarczyk's picture
Offline
Joined: 03/22/2008
Very interesting concept.

Very interesting concept. None the less you would still need java header files for each of those protocols. That's something wireshark can't provide. I don't know how compatible the jNP scanner structures are with wireshark, but I will take a look when I get a chance.

jNetPcap was released with an initial, small list of protocols. I have about 60 other protocol defs written in NPL (http://jnetstream.com) and will port those over to jNetPcap. SIP is included. So very quickly after I get the final 1.2 release done, I will be adding a lot more protocols. There are also user's already ready to contribute as well.

Sly Technologies, Inc.
R&D

rmoh6630
Offline
Joined: 09/07/2009
Can't find dependent libraries

Mark B. wrote:
You are missing the jnetpcap.dll file from your PATH variable.

Include the folder where jnetpcap.dll resides in your PATH variable (set in c:\autoexec.bat or your favorates IDE's launch environmental settings) and that would be in the jnetpcap-1.2.rc1 directory once you unzip. Or copy jnetpcap.dll to c:\windows\system32 directory. You don't need to include the dll directory in the path if you copy to system32 folder.

Hi Mark,

I have pasted the dll into the system32 folder. I am using Eclipse and trying to compile however, I get the following error once I try to run the application:

Exception in thread "main" java.lang.UnsatisfiedLinkError: C:\...\jnetpcap-1.3.b0001-milestone1\jnetpcap.dll: Can't find dependent libraries
at java.lang.ClassLoader$NativeLibrary.load(Native Method)
at java.lang.ClassLoader.loadLibrary0(Unknown Source)
at java.lang.ClassLoader.loadLibrary(Unknown Source)
at java.lang.Runtime.loadLibrary0(Unknown Source)
at java.lang.System.loadLibrary(Unknown Source)
at org.jnetpcap.Pcap.(Pcap.java:366)
at homeagent.PcapTester.main(PcapTester.java:25)

I actually included the library in the build path for the above error. Pasting the dll into system32 gives me the same error.
Any ideas why this is happening?

Cheers,
Riyaz
University of Sydney

Mark Bednarczyk
Mark Bednarczyk's picture
Offline
Joined: 03/22/2008
Alternative is to setup a

[Deleted by admin]

Superseded by the following instructions:
http://jnetpcap.com/eclipse

Sly Technologies, Inc.
R&D

Mark Bednarczyk
Mark Bednarczyk's picture
Offline
Joined: 03/22/2008
I created a userguide

I created a userguide section on how to properly add jnetpcap to your eclipse's build path:

http://jnetpcap.com/eclipse

Sly Technologies, Inc.
R&D

rmoh6630
Offline
Joined: 09/07/2009
Perfect

Thanks a bunch, that guide has worked a charm.

Cheers,
Riyaz
University of Sydney

ilker
Offline
Joined: 03/26/2010
dll for amd-64 & windows

I do not have access to a 64-bit development environment at the moment. Can anyone (compiled successfully) (probably omoser) please provide jnetpcap.dll for amd 64 on windows?

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.