Skip to content

Fix: register CFSocket and correct its address accessors - #154

Open
DTW-Thalion wants to merge 1 commit into
gnustep:masterfrom
DTW-Thalion:fix-cfsocket-init-address
Open

Fix: register CFSocket and correct its address accessors#154
DTW-Thalion wants to merge 1 commit into
gnustep:masterfrom
DTW-Thalion:fix-cfsocket-init-address

Conversation

@DTW-Thalion

Copy link
Copy Markdown
Contributor

CFInitialize did not call CFSocketInitialize, so the socket type was never registered. CFSocketGetTypeID returned zero and every attempt to create a socket failed, which left the whole class unusable. This adds the missing registration.

CFSocketCopyAddress and CFSocketCopyPeerAddress passed an uninitialised length to getsockname and getpeername. They now set it to the size of the address buffer, hold the result in a sockaddr_storage, and cache the address only when the call succeeds. CFSocketCopyPeerAddress also read and stored the local _address field rather than _peerAddress, so it returned the local address; it now uses the peer field, which leaves an unconnected socket with no peer address.

Tests/CFSocket/basic.m and peeraddr.m cover creation, the native handle, validity, socket flags, the context, binding to a loopback address and the peer address, against values taken from Apple CoreFoundation. Both fail before this change and pass after.

CFInitialize did not call CFSocketInitialize, so the socket type was
never registered.  CFSocketGetTypeID returned zero and every attempt to
create a socket failed.  Add the missing registration.

CFSocketCopyAddress and CFSocketCopyPeerAddress passed an uninitialised
length to getsockname and getpeername.  Set it to the size of the
address buffer, hold the result in a sockaddr_storage, and cache the
address only when the call succeeds.  CFSocketCopyPeerAddress also read
and stored the local _address field rather than _peerAddress, so it
returned the local address; it now uses the peer field, which leaves an
unconnected socket with no peer address.
@DTW-Thalion
DTW-Thalion force-pushed the fix-cfsocket-init-address branch from e6caffc to 15a3a23 Compare July 24, 2026 15:22
@DTW-Thalion DTW-Thalion reopened this Jul 24, 2026
@DTW-Thalion DTW-Thalion reopened this Jul 27, 2026
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Development

Successfully merging this pull request may close these issues.

1 participant