Skip to content

libSceNet: sceNetListen on an unbound TCP socket fails with EINVAL on Windows; FreeBSD binds the wildcard address and succeeds; fix branch ready #5339

Closed as not planned

Description

@husseinkad

sceNetListen on a TCP socket the guest never bound fails with EINVAL on Windows, because Winsock requires a bound socket before listen. FreeBSD 11.4 tcp_usr_listen calls in_pcbbind when the socket has no local port (inp_lport == 0), which binds the wildcard address with an ephemeral port, so the call succeeds. A server that calls listen first and then reads the port with getsockname (a common way to get a free port) works on the console and fails here.

Fix branch: https://github.com/husseinkad/AnyPS5/tree/fix/net-listen-autobind (two commits on a recent main: the change and a correction from review; libSceNet/Export.cpp and tests/GuestSceNet.cpp with CheckListenWithoutBind for IPv4 and IPv6 and CheckListenAfterRefusedConnect). sceNetListen now binds the wildcard address of the socket's family first, unless the socket was already bound or already has a local port. The first version bound unconditionally and broke a case that worked on main: after a refused TCP connect, Winsock keeps an automatic local port, the extra bind failed with WSAEINVAL, and listen returned EINVAL where main (and FreeBSD) return 0.

Checks:

  • The new tests fail on main (abort), and CheckListenAfterRefusedConnect fails on the first version of the branch; both pass on the final head, 6 of 6 runs; guest_sce_net and the datagram tests pass.
  • Probed through the guest exports against main, IPv4 and IPv6: a fresh TCP socket now listens (main EINVAL), 50 concurrent listeners each got a distinct nonzero ephemeral port, and connect and accept to the auto-bound port work. Matches FreeBSD: a second listen returns 0, listen on a UDP socket returns EOPNOTSUPP, listen after a failed bind (EADDRNOTAVAIL or EADDRINUSE) returns 0, and backlogs 0, -1, 1, 128, INT_MAX and INT_MIN all return 0. listen on a connected or accepted socket returns EINVAL (main returned 0 or EBADF).
  • Two independent reviews found nothing wrong in the final version. check_conventions.py is clean; pr_overlap.py finds only test-file overlap with fix(libSceNet): dissolve a datagram association on connect to AF_UNSPEC #4669 and fix(libSceNet): report SO_ERROR from sceNetGetsockopt #4988 (same insertion points; their Export.cpp hunks are in sceNetConnect and sceNetGetsockopt).

Not covered: the Linux behaviour was read, not run (the host listen already auto-binds there). Only Windows was built and run.

AI-assisted: yes

Activity

  1. oneandonlydean commented on Oct 14, 2026

    @oneandonlydean
    Collaborator

    Closing: no title is known to reach this, and functions are only changed when a title needs them. If a title stops on or misbehaves because of it on current main, comment here with the title ID and the log line.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions