Skip to content

fix: resolve_hostname endianness on little-endian MIPS#21

Merged
AndrewAltimit merged 1 commit intomainfrom
fix/resolve-hostname-endianness
Mar 7, 2026
Merged

fix: resolve_hostname endianness on little-endian MIPS#21
AndrewAltimit merged 1 commit intomainfrom
fix/resolve-hostname-endianness

Conversation

@AndrewAltimit
Copy link
Owner

Summary

  • resolve_hostname used to_be_bytes() on the u32 IP returned by sceNetResolverStartNtoA, which double-swaps the bytes on little-endian MIPS (PSP Allegrex)
  • The resolver stores the IP in network byte order (big-endian) in memory. Reading it as a u32 on LE gives a byte-swapped value. to_be_bytes() swaps again, reversing the IP (e.g. 207.241.224.2 becomes 2.224.241.207)
  • Fix: to_ne_bytes() returns the raw memory bytes, which are already in the correct network order

Verified on hardware

  • Before fix: all TLS connections failed (connecting to reversed IPs)
  • After fix: DNS resolves correctly, TCP connects to archive.org CDN nodes succeed

Test plan

  • Verified correct IP resolution on PSP hardware (archive.org -> 207.241.224.2)
  • TCP connections to resolved IPs succeed
  • No regression on HTTP streaming (channels using HTTP CDN still work)

Generated with Claude Code

Co-Authored-By: Claude Opus 4.6 noreply@anthropic.com

sceNetResolverStartNtoA stores the IP in network byte order (big-endian)
in memory. On little-endian MIPS (PSP), reading the in_addr as a u32
gives a byte-swapped value. Using to_be_bytes() then double-swaps,
producing reversed IPs (e.g., 207.241.224.2 becomes 2.224.241.207).

to_ne_bytes() returns the raw memory bytes, which are already in the
correct network byte order for sockaddr_in.

Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
@github-actions
Copy link

github-actions bot commented Mar 7, 2026

Gemini AI Code Review

Issues (if any)

(none)

Previous Issues (for incremental reviews)

(none)

Suggestions (if any)

(none)

Notes

  • Fixes an IP address byte-reversal bug occurring on little-endian MIPS (Allegrex).
  • to_ne_bytes() correctly retrieves the raw network-order bytes from memory, avoiding the reversal that to_be_bytes() introduced when operating on the u32 register value.
  • The added documentation accurately explains the interaction between the PSP OS memory layout and the CPU's endianness.

Reaction


Generated by Gemini AI (gemini-3-flash-preview). Supplementary to human reviews.

@AndrewAltimit
Copy link
Owner Author

Review Response Agent (Iteration 1)

Status: No changes needed

Fixed Issues

  • (none — no issues were raised)

Ignored Issues

  • (none)

Deferred to Human

  • (none)

Notes

  • Gemini's review confirmed the to_be_bytes()to_ne_bytes() fix is correct and the added documentation accurately explains the endianness behavior. No actionable feedback was provided.

The agent reviewed feedback but determined no code changes were required.

@AndrewAltimit AndrewAltimit merged commit 4370415 into main Mar 7, 2026
7 checks passed
@AndrewAltimit AndrewAltimit deleted the fix/resolve-hostname-endianness branch March 7, 2026 20:12
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