0

I was trying to find the implementation of a private method of the Inet4AddressImpl class of the java.net package. I tried both grepcode and the src.zip available in my jdk directory.

The method whose implementation I am looking for in the aforementioned class:

private native boolean isReachable0(byte[] addr, int timeout, byte[] ifaddr, int ttl) throws IOException;

So being a native code I assume it's implementation would be OS dependent. So I just want to know if and where can I find its implementation and of other native methods for that matter !
Thanks

ps_
  • 97
  • 2
  • 12
  • Possible duplicate of [Where to find source code for java.lang native methods?](http://stackoverflow.com/questions/2292629/where-to-find-source-code-for-java-lang-native-methods) – Chai T. Rex Jan 15 '17 at 03:28
  • Actually that one might have been helpful but the download link in the accepted answer doesn't seem to work. I even tried searching the oracle site for jdk sources but that wasn't quite helpful either, couldn't exactly find what I was looking for. Openjdk source seems to be an alternative as other SO questions have suggested (haven't yet tried that out personally though) but I thought it'd be better to ask a question here. – ps_ Jan 15 '17 at 03:52

2 Answers2

1

Searching the OpenJDK Mercurial Repository online is indeed always a bit difficult. There are some mirrors of the JDK source code on GitHub, which has a far better search functionality - for example:

https://github.com/openjdk-mirror/jdk7u-jdk/search?utf8=%E2%9C%93&q=isReachable0

Quite often you can "guess" from parts of the paths of the result where you have to look in the original OpenJDK repo, here, this would be

http://hg.openjdk.java.net/jdk8/jdk8/jdk/file/82b276590b85/src/windows/native/java/net/Inet4AddressImpl.c#l416

(for Windows - other implementations can be found by browsing into the corresponding paths of the respective OS)

Marco13
  • 53,703
  • 9
  • 80
  • 159
0

You can find this source code file in src.zip file inside jdk folder.

E.g. For Windows, you can find it as shown in this screenshot. enter image description here

I see that you are looking for the source code of the method isreachable0 specifically. I just checked the source code of the class inet4address and its parent class inetaddress on Windows. None of them contains this method. The parent class inetaddress contains another method isreachable but it has a different signature. I think this method, if at all, is available in JDK in only certain platforms.

VHS
  • 9,534
  • 3
  • 19
  • 43
  • Yes I have done that as I even mentioned but was unable to find what I was looking for. – ps_ Jan 15 '17 at 03:34
  • @PSuniq. Oh I see that you are looking for the source code of the method `isreachable0` specifically. I just checked the source code of the class `inet4address` and its parent class `inetaddress` on Windows. None of them contains this method. The parent class inetaddress contains another method `isreachable` but it has a different signature. What platform are you doing your development? I think this method, if at all, is available in only certain platforms. – VHS Jan 15 '17 at 03:46
  • I am using windows. I think it'd be available on all the platforms that have the native capabilities to support its requirements. Being a native method, it's implementation should obviously be platform dependent. – ps_ Jan 15 '17 at 03:54
  • What you say is ok for Java methods, but not for native ones which are written in like C or C++. – Paul Stelian Dec 18 '17 at 20:56