Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Allow connections to IPv6 addresses #280

Merged
merged 1 commit into from
Jul 21, 2023
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
4 changes: 3 additions & 1 deletion lib/datadog/statsd/udp_connection.rb
Original file line number Diff line number Diff line change
Expand Up @@ -29,7 +29,9 @@ def close
def connect
close if @socket

@socket = UDPSocket.new
family = Addrinfo.udp(host, port).afamily

@socket = UDPSocket.new(family)
@socket.connect(host, port)
end

Expand Down
28 changes: 28 additions & 0 deletions spec/statsd/udp_connection_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -71,6 +71,34 @@
instance_double(Datadog::Statsd::Telemetry, sent: true, dropped_writer: true)
end

context 'using an IPv6 address' do
let(:host) { '2001:db8::dead:beef' }

it 'connects to an IPv6 host with the right address family' do
expect(UDPSocket)
.to receive(:new)
.with(Socket::AF_INET6)

subject.write('test')
end

it 'connects to the right host and port' do
expect(udp_socket)
.to receive(:connect)
.with('2001:db8::dead:beef', 4567)

subject.write('test')
end
end

it 'connects to an IPv4 host with the right address family' do
expect(UDPSocket)
.to receive(:new)
.with(Socket::AF_INET)

subject.write('test')
end

it 'connects to the right host and port' do
expect(udp_socket)
.to receive(:connect)
Expand Down