dianjifzm commented on issue #13743:
URL: https://github.com/apache/dubbo/issues/13743#issuecomment-1928864277

   > Will `InetAddress.getLocalHost()` return null in your environment?
   
   是的。
   仅在M2芯片,macOS 14.2.1 (mac mini) 会复现。
   普通用户权限会一直返回false,root用户可以正常返回。
   
   我尝试在Linux,inter 芯片的Mac,以及windows 11 上,都无法复现。
   
   可以用如下代码验证
   ```
   public static void main(String[] args) throws Exception {
       InetAddress address = InetAddress.getByName("192.168.2.4"); // 
这你需要改成自己的IP地址
       System.out.println(address.getHostName() + " " + 
address.isReachable(1000));
   }
   ```
   
   根本原因是InetAddress.isReachable的native实现有缺陷。
   普通用户发送ICMP报文需要一些特殊操作
   参考macOS ping的源码
   ```
   if (getuid())
        s = socket(AF_INET, SOCK_DGRAM, IPPROTO_ICMP);
   else
        s = socket(AF_INET, SOCK_RAW, IPPROTO_ICMP);  
        
   ```
   jdk 中只是如下方式实现,所以有的环境就会出错。
   socket(AF_INET, SOCK_DGRAM, IPPROTO_ICMP);
   


-- 
This is an automated message from the Apache Git Service.
To respond to the message, please log on to GitHub and use the
URL above to go to the specific comment.

To unsubscribe, e-mail: notifications-unsubscr...@dubbo.apache.org

For queries about this service, please contact Infrastructure at:
us...@infra.apache.org


---------------------------------------------------------------------
To unsubscribe, e-mail: notifications-unsubscr...@dubbo.apache.org
For additional commands, e-mail: notifications-h...@dubbo.apache.org

Reply via email to