Question

When doing data, addr = @socket.recvfrom(1500), the addr array contains Array: ["AF_INET", port, "resolved-name-or-ip", "ip"]

How can I disable resolving on UDPSocket? The documentation for ruby UDPSocket is bit poor.

Was it helpful?

Solution 2

Ok. I found it.

I'll document this here so someone might get lucky and find it.

To disable automatic lookups, put this in your code:

BasicSocket.do_not_reverse_lookup = true

before you create the socket. It does the trick.

OTHER TIPS

In the documentation, you can see in the connect method the rsock_addrinfo method called .

This method calls getaddrinfo.

So I don't see a work around, you have to call another connect method.

Maybe can you add some codelines for a better understanding? I'm afraid you can't.

static VALUE

udp_connect(sock, host, port)
VALUE sock, host, port;
{
rb_io_t *fptr;
struct udp_arg arg;
VALUE ret;

rb_secure(3);

arg.res = sock_addrinfo(host, port, SOCK_DGRAM, 0);

GetOpenFile(sock, fptr);
arg.fd = fileno(fptr->f);
ret = rb_ensure(udp_connect_internal, (VALUE)&arg,
                RUBY_METHOD_FUNC(freeaddrinfo), (VALUE)arg.res);
if (!ret) rb_sys_fail("connect(2)");
return INT2FIX(0);
}

Source: http://ruby-doc.org/stdlib-1.8.7/libdoc/socket/rdoc/UDPSocket.html

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top