Skip to content

configure.ac: look for the socket functions in libnetwork too - #73

Open
duncanmcqueen wants to merge 1 commit into
ingelabs:masterfrom
duncanmcqueen:fix-libnetwork
Open

duncanmcqueen wants to merge 1 commit into
ingelabs:masterfrom
duncanmcqueen:fix-libnetwork

Conversation

@duncanmcqueen

@duncanmcqueen duncanmcqueen commented Oct 14, 2026 •

Copy link
Copy Markdown
Contributor

Split from #60.

Problem and fix

On Haiku, the socket functions (socket, connect, inet_pton, gethostbyname and the others) and h_errno (__h_errno) are in libnetwork, not in libroot (the C library). configure.ac looks for inet_pton in the C library and in libnsl only. Thus on Haiku:

  • configure does not find inet_pton and the other socket functions.
  • The JNI libraries (libjavanio.so, libjavanet.so) do not link with libnetwork. They compile, but they do not load: Symbol not found. Each program stops at the start, because the VM cannot load libjavanio.so.

Now AC_SEARCH_LIBS for inet_pton also looks in libnetwork.

How to reproduce

On Haiku, with #74 and #75 (without them, master does not build on Haiku):

../configure --enable-jni ...
grep -n "containing inet_pton" config.log
make && make install
readelf -d <prefix>/lib/classpath/libjavanio.so | grep NEEDED

Then run this program:

javac NetBasics.java
java NetBasics
NetBasics.java
import java.io.*;
import java.net.*;
import java.util.*;

/**
 * Basic network operations: resolve a host name, list the network
 * interfaces, and connect a socket to a server socket on the loopback
 * interface. Each one loads Classpath's java-net JNI library.
 */
public class NetBasics
{
  public static void main(String[] args) throws Exception
  {
    try
      {
        System.out.println("resolve: " + InetAddress.getByName("localhost"));
        for (Enumeration<NetworkInterface> e =
               NetworkInterface.getNetworkInterfaces(); e.hasMoreElements(); )
          {
            NetworkInterface i = e.nextElement();
            System.out.println("interface: " + i.getName() + " up="
                               + i.isUp() + " loopback=" + i.isLoopback());
          }
        ServerSocket ss = new ServerSocket(0, 1, InetAddress.getByName("127.0.0.1"));
        Socket c = new Socket("127.0.0.1", ss.getLocalPort());
        Socket s = ss.accept();
        c.getOutputStream().write(42);
        int b = s.getInputStream().read();
        System.out.println((b == 42 ? "PASS" : "FAIL") + ": socket byte = " + b);
        System.exit(b == 42 ? 0 : 1);
      }
    catch (Throwable t)
      {
        System.out.println("FAIL: " + t);
        t.printStackTrace(System.out);
        System.exit(1);
      }
  }
}

Results

Haiku R1/beta6 x86_64 (hrev59866), javac from OpenJDK 8, Kaffe 1.1.10-pre. I ran autoreconf on Linux (autoconf 2.73, automake 1.19) and built on Haiku out of tree with --enable-jni --disable-examples --disable-plugin --disable-gjdoc --disable-gtk-peer --disable-gconf-peer --disable-alsa --disable-dssi.

Before (master with #74, #75, and #62, #64 and #65 for Kaffe):
checking for library containing inet_pton... no
libjavanio.so NEEDED: [libiconv.so.2] [libroot.so]
dlopen(libjavanio.so): Symbol not found
  (undefined, and defined in libnetwork.so: __h_errno accept bind connect gethostbyaddr
   gethostbyname getpeername getsockname getsockopt listen recv recvfrom send sendto
   setsockopt shutdown socket)
Kaffe:
java/lang/UnsatisfiedLinkError: Native library `javanio' not found (as file `libjavanio.so' in class loader null) ...
   at java.lang.ClassLoader.getSystemClassLoader (ClassLoader.java:799)
Abort

After (also with this pull request):
checking for library containing inet_pton... -lnetwork
libjavanio.so NEEDED: [libiconv.so.2] [libnetwork.so] [libroot.so]
dlopen(libjavanio.so): loaded
resolve: localhost/127.0.0.1
interface: /dev/net/ipro1000/0 up=true loopback=false
interface: loop up=true loopback=true
PASS: socket byte = 42

Platforms

Specific to Haiku (and BeOS, which also has libnetwork). AC_SEARCH_LIBS tries the libraries only when the function is not in the C library. On Linux, configure gives checking for library containing inet_pton... none required and checking how many arguments gethostbyname_r() takes... six, so it does not add -lnetwork on Linux.

AI assistance

An AI model (Claude Code, by Anthropic) wrote this change, the test and this text. The repository owner directed the work and checked the results. Please review it as you review other contributions.

🤖 Generated with Claude Code

Haiku has inet_pton(), the other socket functions and h_errno in
libnetwork. Without it, the JNI libraries fail to load (undefined
__h_errno) and configure does not find the socket functions.

Co-Authored-By: Claude Opus 5.5 <noreply@anthropic.com>
Signed-off-by: duncanmcqueen <206344294+duncanmcqueen@users.noreply.github.com>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant