java java中的原始套接字

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/14873243/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me): StackOverFlow

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-10-31 17:42:22  来源:igfitidea点击:

Raw socket in java

javasocketsraw-sockets

提问by Nikhil

I am pretty new to java socket programming. I had already gone thorugh that java only deals with Internet Domain Sockets and it will support UDP and TCP and Raw IP Protocols. I want to know that is java support Raw Sockets without using any third party applications? If it is possible can anyone help me with a small example? Any small advice will be very greatful!

我对 Java 套接字编程很陌生。我已经知道 java 只处理 Internet 域套接字,它将支持 UDP 和 TCP 以及原始 IP 协议。我想知道 java 是否支持原始套接字而不使用任何第三方应用程序?如果可能的话,谁能帮我举个小例子?任何小建议都会非常有用!

采纳答案by Audrius Meskauskas

The only really available support for raw socketsin Java standard library seems the InetAddress.isReachable()that may do ICMP ping if permitted. This is really not much and probably even not really a raw socket, just one more protocol.

Java 标准库中对原始套接字唯一真正可用的支持似乎是InetAddress.isReachable(),如果允许,它可以执行 ICMP ping。这真的不多,甚至可能不是真正的原始套接字,只是一个协议。

For other types of raw communication I would recommend to use Berkley sockets under Linux(root rights required) through some JNI - based wrapper.

对于其他类型的原始通信,我建议通过一些基于 JNI 的包装器在 Linux 下使用Berkley 套接字(需要 root 权限)。