Repository navigation
feat(socket): Addrinfo + Socket.getaddrinfo + sockaddr pack/unpack - #199
Merged
Merged
Conversation
Extend rbgo's socket transport (require "socket") with the name-resolution and address utilities the connected/datagram socket work (#173/#192) deferred, all backed by Go's net package (no cgo): - Socket.getaddrinfo(host, port[, family, socktype, protocol, flags]) -> MRI's [afamily, port, host, addr, pfamily, socktype, protocol] tuples, resolved through net.Resolver with no reverse lookup (hermetic). - Addrinfo value class: .tcp / .udp / .ip / .getaddrinfo / .new (packed sockaddr String or [afamily, port, host, addr] array), plus ip_address / ip_port / afamily / pfamily / socktype / protocol / ipv4? / ipv6? / to_sockaddr / inspect. - sockaddr pack/unpack: Socket.pack_sockaddr_in / sockaddr_in / unpack_sockaddr_in (IPv4 + IPv6) and pack_sockaddr_un / sockaddr_un / unpack_sockaddr_un (AF_UNIX, non-Windows; NotImplementedError stubs on Windows, mirroring the UNIXSocket transport). The sockaddr layout is the Linux one (no BSD sa_len byte): the family field is host native byte order (a C sa_family_t) while port and address are network byte order, so the [port, host] round-trip is byte-exact on every arch. Verified on big-endian s390x under emulation. Tests exercise the whole surface through the rbgo engine against loopback-resolvable inputs (127.0.0.1 / ::1 / localhost); the resolver and service-name port lookup are driven through injectable seams (resolveIPs / lookupPort) so the suite never touches live DNS. 100% coverage of the new code, including every error and platform arm. Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Extends rbgo's socket transport (
require "socket") with the name-resolution and address utilities the connected/datagram socket work (#173 / #192) deferred, all backed by Go'snetpackage (CGO=0).Surface
Socket.getaddrinfo(host, port[, family, socktype, protocol, flags])→ array of MRI-shape tuples[afamily_string, port, host, addr, pfamily, socktype, protocol], resolved throughnet.Resolver. No reverse lookup (host == numeric addr), keeping results hermetic.family/socktypeaccept an Integer (Socket::AF_INET), a Symbol (:INET), or a String ("AF_INET"); a numericportString is parsed and a service-name String is looked up.Addrinfovalue class:Addrinfo.tcp(host, port)/.udp(host, port)/.ip(host)/.getaddrinfo(...)/.new(sockaddr[, family, socktype, protocol])—sockaddris either a packed sockaddr String or a[afamily, port, host, addr]array (MRI accepts both).ip_address/ip_port/afamily/pfamily/socktype/protocol/ipv4?/ipv6?/to_sockaddr(aliasto_s) /inspect(#<Addrinfo: 127.0.0.1:8080 TCP>, IPv6 bracketed).sockaddr pack/unpack:
Socket.pack_sockaddr_in(port, host)/sockaddr_inandSocket.unpack_sockaddr_in(sa)→[port, host](IPv4 + IPv6).Socket.pack_sockaddr_un(path)/sockaddr_unandSocket.unpack_sockaddr_un(sa)— AF_UNIX, non-Windows only; the Windows build installsNotImplementedErrorstubs, mirroring the UNIXSocket transport.Endianness
The sockaddr layout is the Linux one (no BSD
sa_lenbyte): the family field is written in the host's native byte order (a Csa_family_tis a host-endian short) while the port and address are network byte order, exactly the C semantics.packandunpackshare the native order for the family field, so the[port, host]round-trip is byte-exact on every arch. Verified on big-endian s390x under emulation.Testing
The whole surface is exercised through the rbgo engine against loopback-resolvable inputs (
127.0.0.1/::1/localhost). The resolver and service-name port lookup are reached only for non-numeric inputs and are driven through injectable seams (resolveIPs/lookupPort), so the suite never touches live DNS. 100% coverage of the new code, including every error and platform arm.Confined to
internal/vm/socket*.go(+ oneclassOfcase inobject_model.go).🤖 Generated with Claude Code