End of Life Ruby 3.2 has reached end of life and gets no more fixes. Switch to Ruby 4.0 →
instance method
Addrinfo#ip_address
addrinfo.ip_address => string
ext/socket/raddrinfo.c
View on GitHub ↗
static VALUE
addrinfo_ip_address(VALUE self)
{
rb_addrinfo_t *rai = get_addrinfo(self);
int family = ai_get_afamily(rai);
VALUE vflags;
VALUE ret;
if (!IS_IP_FAMILY(family))
rb_raise(rb_eSocket, "need IPv4 or IPv6 address");
vflags = INT2NUM(NI_NUMERICHOST|NI_NUMERICSERV);
ret = addrinfo_getnameinfo(1, &vflags, self);
return rb_ary_entry(ret, 0);
}
Returns the IP address as a string.
Example
Addrinfo.tcp("127.0.0.1", 80).ip_address #=> "127.0.0.1" Addrinfo.tcp("::1", 80).ip_address #=> "::1"