android使用pcap库 [英] android use pcap library

查看:291
本文介绍了android使用pcap库的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个Android应用程序的一般问题,我需要在我的Android应用程序中使用一些pcap功能。因为java不提供原始数据包注入和低层编程的可能性(据我所知,请纠正我,如果我错了)所以我正在寻找替代方案。到目前为止,我发现了以下内容:

I have a general question according an android app, I need to use some pcap functionality in my android app. Because java does not give the possibility in raw packet injections and low layer programming (as far as I know, pls correct me if I'm wrong) so I was looking for an alternative. So far I found the following:


  • ANDROID NDK

  • JNETPCAP

我应该使用的任何建议或其他任何人都有其他建议吗?

Any suggestions which one I should use or does anyone have other suggestions?

推荐答案

JNI解决方案

你需要包装你需要的调用和逻辑cp或C ++中的libpcap和通过 JNI公开底层函数 (Java Native Interface) 因此您的应用程序可以用Java调用本机代码。

You need to wrap the calls and the logic you need out of libpcap in C or C++ and expose the underlying functions through JNI (Java Native Interface) so your application can call native code in Java.

文档on JNI 在互联网上非常完整,有很多关于这个主题的教程,例如这个

The documentation on JNI is pretty complete on internet, a lot of tutorials exists on this subject such as this one.

如果你想在JNI中轻松包装本机代码,你可以使用 Swig ,允许您自动生成e基于C / C ++本机头的JNI代码。

If you want to easily wrap native code in JNI you can use Swig which allow you to automatically generate JNI code based on your C/C++ native headers.

获取的JNI代码应使用Android NDK编译为动态库( 。所以)。该库将放在 libs / 下的应用程序包中。然后,您可以调用 System.loadLibrary(path_to_you_dynamic_library)来加载库中包含的所有符号,并在Java中使用它们。

The obtained JNI code should be compiled using the Android NDK as a dynamic library (.so). This library is to be placed in your application package under libs/. You can then invoke System.loadLibrary(path_to_you_dynamic_library) to load all the symbols contained in the library and use them in Java.

使用第三方库

如果您在弄清楚如何使用JNI时害怕头痛,可以看一下在这个为您工作的库中,提供了一个API来操作Java中的原始套接字。

If you're afraid of getting headaches while figuring out how to use JNI, you can look at this library which does the hard work for you, and provides an API to manipulate raw sockets in Java.

http://www.savarese.com/software/rocksaw/

这篇关于android使用pcap库的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆