Skip to content

Commit a9d0c3f

Browse files
committed
Fix UDPSocket#bind to specify family and socktype when resolving address
* Otherwise, bind() fails with EAFNOSUPPORT because getaddrinfo() does not return good values (an IPv6 address in this case, even though the UDPSocket was created with AF_INET, which is IPv4).
1 parent ec974a9 commit a9d0c3f

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

lib/truffle/socket/udp_socket.rb

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -39,7 +39,8 @@ def initialize(family = Socket::AF_INET)
3939
end
4040

4141
def bind(host, port)
42-
addr = Socket.sockaddr_in(port.to_i, host)
42+
addr = Truffle::Socket::Foreign.pack_sockaddr_in(
43+
host, port.to_i, @family, Socket::SOCK_DGRAM, 0)
4344
status = Truffle::Socket::Foreign.bind(descriptor, addr)
4445

4546
Errno.handle('bind(2)') if status < 0
@@ -48,8 +49,8 @@ def bind(host, port)
4849
end
4950

5051
def connect(host, port)
51-
sockaddr = Truffle::Socket::Foreign
52-
.pack_sockaddr_in(host, port.to_i, @family, Socket::SOCK_DGRAM, 0)
52+
sockaddr = Truffle::Socket::Foreign.pack_sockaddr_in(
53+
host, port.to_i, @family, Socket::SOCK_DGRAM, 0)
5354

5455
status = Truffle::Socket::Foreign.connect(descriptor, sockaddr)
5556

0 commit comments

Comments
 (0)