做RAW socket编程涉及Java最好的方法 [英] Best way to do RAW socket programming involving Java

查看:2233
本文介绍了做RAW socket编程涉及Java最好的方法的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个使用ICMP的原始套接字做平一些现有的C code,我需要在Java中使用code作为Java不支持ICMP包。当我包裹code JNI中并调用它的C code未能获得做当套接字:

I have some existing C code that uses ICMP raw sockets to do Ping and I need to use this code in Java as Java does not support ICMP packages. When I wrap the code in JNI and call it, the C code fails to obtain the socket when doing:

插座(AF_INET,SOCK_RAW,1);

socket(AF_INET, SOCK_RAW, 1);

我想,Java已经下降了一些特权,禁用从Java过程中使用原始套接字的。这是我必须找到一个解决方案。

I guess that Java has dropped some privileges that disables the use of raw socket from the Java process. This I must find a solution to.

我观察到以下内容:


  • 如果我写了一个C程序,并通过运行时分叉code可打开插座调用从Java。

  • 如果我从Eclipse中运行这个本地code它也运行很好。我想这来自于Eclipse已经从开始的eclipse.exe,而不是从java.exe的事实。

这意味着,我可以选择这两种策略中的一个解决我的问题,但我都不喜欢。有没有我能得到的Java接受了JNI code为打开此套接字其他方法吗?

This means that I could solve my problem by choosing one of these two strategies, but I like neither. Are there any other ways that I could get Java to accept that the JNI code is opening this socket?

编辑:
我越考虑这个问题,我想,它必须是Windows 7相关的问题与正在如何启动的Java。

The more I look into this problem I figure that it must be a windows 7 related issue with how Java is being started.

它还看来,如果你得到Windows行为或者如果你在其他平台比Windows的方法InetAddress.isReachable()可以作为很好。

It also appears that if you get windows to behave or if you are on some other platform than Windows the method InetAddress.isReachable() could be used as well.

推荐答案

也许使用现有的Java本地接口的lib?然后,你不必担心编码JNI库。

Maybe use an existing Java native socket lib? Then you don't have to worry about coding the JNI lib.

请参阅: http://www.savarese.com/software/rocksaw/

这篇关于做RAW socket编程涉及Java最好的方法的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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