Skip to content

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

Merged
guillerodriguez merged 1 commit into
ingelabs:masterfrom
duncanmcqueen:fix-libnetwork
Oct 15, 2026
Merged

guillerodriguez merged 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. (BeOS has the socket functions in libnet, and BONE has them in libsocket and libbind.) 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

@guillerodriguez

Copy link
Copy Markdown
Contributor

Thank you. I have two questions.

  • The PR description mention BeOS also has libnetwork, can you confirm that? I think BeOS used libnet.so instead
  • Do you get the same results if you just use ./configure LIBS=-lnetwork ?

@duncanmcqueen

Copy link
Copy Markdown
Contributor Author

Thank you for the questions.

1. BeOS. You are correct, and my description is wrong. BeOS R5 has the socket functions in libnet.so. BONE has them in libsocket.so and libbind.so. libnetwork.so is only on Haiku. Haiku's own libnetwork/init.cpp uses these library names to find R5 binaries and BONE binaries. Gnulib's socketlib.m4 says the same: "Haiku has most socket functions in libnetwork. BeOS has most socket functions in libnet." I removed "and BeOS" from the description. This change is specific to Haiku. I did not test BeOS, so I did not add net to the list.

2. ./configure LIBS=-lnetwork. Yes, the results are the same. I built master with #74 and #75 (no change to configure.ac) on Haiku R1/beta6 (hrev60228), with the same options and LIBS=-lnetwork:

checking for library containing inet_pton... none required
checking for inet_pton... yes
libjavanio.so NEEDED: [libiconv.so.2] [libnetwork.so] [libroot.so]
libjavanet.so NEEDED: [libnetwork.so] [libroot.so]
dlopen(libjavanio.so), dlopen(libjavanet.so): loaded
include/config.h: identical to the build with this pull request
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

Thus this pull request does not add a new function. It only removes the need to know about LIBS=-lnetwork. Without it, configure completes without an error, and the libraries fail only at run time (Symbol not found). If you prefer, I can close this pull request and add the LIBS=-lnetwork note to INSTALL or to the Haiku peer documentation (#61).

@guillerodriguez

Copy link
Copy Markdown
Contributor

Thanks for the clarification.

If you prefer, I can close this pull request and add the LIBS=-lnetwork note to INSTALL or to the Haiku peer documentation

No, this is a trivial change and harmless on other systems so I think we can just take this and make life easier for everyone :-)

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>
@duncanmcqueen

Copy link
Copy Markdown
Contributor Author

Works for me!

@guillerodriguez
guillerodriguez merged commit bdde0a6 into ingelabs:master Oct 15, 2026
3 checks passed
@duncanmcqueen
duncanmcqueen deleted the fix-libnetwork branch October 15, 2026 14:11
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.

2 participants