End of Life Ruby 3.1 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
class method
Addrinfo.ip
Addrinfo.ip(host) => addrinfo
ext/socket/raddrinfo.c
View on GitHub ↗
static VALUE
addrinfo_s_ip(VALUE self, VALUE host)
{
VALUE ret;
rb_addrinfo_t *rai;
ret = addrinfo_firstonly_new(host, Qnil,
INT2NUM(PF_UNSPEC), INT2FIX(0), INT2FIX(0), INT2FIX(0));
rai = get_addrinfo(ret);
rai->socktype = 0;
rai->protocol = 0;
return ret;
}
returns an addrinfo object for IP address.
The port, socktype, protocol of the result is filled by zero. So, it is not appropriate to create a socket.
Example
Addrinfo.ip("localhost") #=> #<Addrinfo: 127.0.0.1 (localhost)>