Skip to content

musl compatibility in net_open_tcp2#30

Open
dirtslayer wants to merge 1 commit intocheusov:masterfrom
dirtslayer:musl-tcp
Open

musl compatibility in net_open_tcp2#30
dirtslayer wants to merge 1 commit intocheusov:masterfrom
dirtslayer:musl-tcp

Conversation

@dirtslayer
Copy link

Ensure musl compatibility in net_open_tcp2

This PR ensures musl compatibility in net_open_tcp2 by removing multi‑socket
return paths.

The packages required to compile on Alpine are build-base git mk-configure
mk-configure-dev libmaa-dev zlib-dev musl-dev

Changes to net_server.c/net_open_tcp2

  1. rtmp renamed to ai

  2. getaddrinfo() now uses:

    • ai_family = AF_UNSPEC
    • ai_flags = AI_ADDRCONFIG | AI_V4MAPPED
    • This avoids musl’s EAI_ADDRFAMILY error when an IPv4 literal
      (e.g., "10.x.x.x") is passed with AF_INET6.
  3. Added detailed debug logging so socket selection and fallback
    behavior are visible when running with -d.

  4. Dual‑stack attempt (IPv6 with IPV6_V6ONLY=0) is still tried,
    but, we fall back to separate IPv4 and IPv6 attempts.

  5. dictd cannot safely handle multiple listening
    sockets. The original code returned two sockets when dual‑stack
    failed. This version ALWAYS returns exactly ONE socket:

    • Prefer IPv4 if available
    • Otherwise use IPv6
    • Any unused socket is closed immediately.

Result:

  • No BUS ERROR crashes on Alpine/musl
  • No out‑of‑bounds access in dictd’s main loop
  • No use‑after‑free of the socket array
  • avoids dual‑socket return values
  • preserves dictd’s original single‑listener design while remaining compatible
    with IPv4 and IPv6

Testing:

./dictd -d nodetach -c /etc/dictd/dictd.conf --listen-to 0.0.0.0 --address-family 4
./dictd -d nodetach -c /etc/dictd/dictd.conf --listen-to localhost --address-family 4
./dictd -d nodetach -c /etc/dictd/dictd.conf --listen-to 127.0.0.1 --address-family 4
./dictd -d nodetach -c /etc/dictd/dictd.conf --listen-to :: --address-family 6
./dictd -d nodetach -c /etc/dictd/dictd.conf --listen-to ::1 --address-family 6

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