logstash-plugins / logstash-output-udp

Apache License 2.0
7 stars 10 forks source link

not support ipv6 ERROR: Address family not supported by protocol #14

Open runbean opened 1 year ago

runbean commented 1 year ago

in logstash-output-udp-3.2.0/lib/logstash/outputs/udp.rb @socket = UDPSocket.new not support ipv6

def register
    @socket = UDPSocket.new

    @codec.on_event do |event, payload|
      port = event.sprintf(@port)
      begin
        port = Integer(port)
      rescue => e # ArgumentError (invalid value for Integer(): "foo")
        logger.error("Failed to resolve port, dropping event", port: @port, event: event.to_hash, message: e.message)
      else
        socket_send(payload, port)
      end
    end
end
selenith commented 1 month ago

Hi, I've the same issue. I've done the following little patch in my servers.

In the register function, replace :

@socket = UDPSocket.new

by :

    addr_test = IPSocket.getaddress(@host)
    if IPAddr.new(addr_test).ipv6?
       @socket = UDPSocket.new(Socket::AF_INET6)
    elsif IPAddr.new(addr_test).ipv4?
       @socket = UDPSocket.new(Socket::AF_INET)
    end

It work with ipv6, ipv4, hostname with IPv6 and/or IPv4 resolution.