Class: Socket::Ifaddr
Relationships & Source Files | |
Super Chains via Extension / Inclusion / Inheritance | |
Class Chain:
self,
::Data
|
|
Instance Chain:
self,
::Data
|
|
Inherits: | Data |
Defined in: | ext/socket/ifaddr.c |
Overview
Ifaddr
represents a result of getifaddrs() function.
Instance Method Summary
-
#addr ⇒ addrinfo
Returns the address of ifaddr.
-
#broadaddr ⇒ addrinfo
Returns the broadcast address of ifaddr.
-
#dstaddr ⇒ addrinfo
Returns the destination address of ifaddr.
-
#flags ⇒ Integer
Returns the flags of ifaddr.
-
#ifindex ⇒ Integer
Returns the interface index of ifaddr.
-
#inspect ⇒ String
Returns a string to show contents of ifaddr.
-
#name ⇒ String
Returns the interface name of ifaddr.
-
#netmask ⇒ addrinfo
Returns the netmask address of ifaddr.
-
#vhid ⇒ Integer
Returns the vhid address of ifaddr.
Instance Method Details
#addr ⇒ addrinfo
Returns the address of ifaddr. nil is returned if address is not available in ifaddr.
# File 'ext/socket/ifaddr.c', line 197
static VALUE ifaddr_addr(VALUE self) { struct ifaddrs *ifa = get_ifaddrs(self); if (ifa->ifa_addr) return rsock_sockaddr_obj(ifa->ifa_addr, rsock_sockaddr_len(ifa->ifa_addr)); return Qnil; }
#broadaddr ⇒ addrinfo
Returns the broadcast address of ifaddr. nil is returned if the flags doesn’t have IFF_BROADCAST.
# File 'ext/socket/ifaddr.c', line 231
static VALUE ifaddr_broadaddr(VALUE self) { struct ifaddrs *ifa = get_ifaddrs(self); if ((ifa->ifa_flags & IFF_BROADCAST) && ifa->ifa_broadaddr) return rsock_sockaddr_obj(ifa->ifa_broadaddr, rsock_sockaddr_len(ifa->ifa_broadaddr)); return Qnil; }
#dstaddr ⇒ addrinfo
Returns the destination address of ifaddr. nil is returned if the flags doesn’t have IFF_POINTOPOINT.
# File 'ext/socket/ifaddr.c', line 248
static VALUE ifaddr_dstaddr(VALUE self) { struct ifaddrs *ifa = get_ifaddrs(self); if ((ifa->ifa_flags & IFF_POINTOPOINT) && ifa->ifa_dstaddr) return rsock_sockaddr_obj(ifa->ifa_dstaddr, rsock_sockaddr_len(ifa->ifa_dstaddr)); return Qnil; }
#flags ⇒ Integer
Returns the flags of ifaddr.
# File 'ext/socket/ifaddr.c', line 182
static VALUE ifaddr_flags(VALUE self) { struct ifaddrs *ifa = get_ifaddrs(self); return IFAFLAGS2NUM(ifa->ifa_flags); }
#ifindex ⇒ Integer
Returns the interface index of ifaddr.
# File 'ext/socket/ifaddr.c', line 161
static VALUE ifaddr_ifindex(VALUE self) { struct ifaddrs *ifa = get_ifaddrs(self); unsigned int ifindex = if_nametoindex(ifa->ifa_name); if (ifindex == 0) { rb_raise(rb_eArgError, "invalid interface name: %s", ifa->ifa_name); } return UINT2NUM(ifindex); }
#inspect ⇒ String
Returns a string to show contents of ifaddr.
# File 'ext/socket/ifaddr.c', line 356
static VALUE ifaddr_inspect(VALUE self) { struct ifaddrs *ifa = get_ifaddrs(self); VALUE result; result = rb_str_new_cstr("#<"); rb_str_append(result, rb_class_name(CLASS_OF(self))); rb_str_cat2(result, " "); rb_str_cat2(result, ifa->ifa_name); if (ifa->ifa_flags) ifaddr_inspect_flags(ifa->ifa_flags, result); if (ifa->ifa_addr) { rb_str_cat2(result, " "); rsock_inspect_sockaddr(ifa->ifa_addr, rsock_sockaddr_len(ifa->ifa_addr), result); } if (ifa->ifa_netmask) { rb_str_cat2(result, " netmask="); rsock_inspect_sockaddr(ifa->ifa_netmask, rsock_sockaddr_len(ifa->ifa_netmask), result); } if ((ifa->ifa_flags & IFF_BROADCAST) && ifa->ifa_broadaddr) { rb_str_cat2(result, " broadcast="); rsock_inspect_sockaddr(ifa->ifa_broadaddr, rsock_sockaddr_len(ifa->ifa_broadaddr), result); } if ((ifa->ifa_flags & IFF_POINTOPOINT) && ifa->ifa_dstaddr) { rb_str_cat2(result, " dstaddr="); rsock_inspect_sockaddr(ifa->ifa_dstaddr, rsock_sockaddr_len(ifa->ifa_dstaddr), result); } rb_str_cat2(result, ">"); return result; }
#name ⇒ String
Returns the interface name of ifaddr.
# File 'ext/socket/ifaddr.c', line 146
static VALUE ifaddr_name(VALUE self) { struct ifaddrs *ifa = get_ifaddrs(self); return rb_str_new_cstr(ifa->ifa_name); }
#netmask ⇒ addrinfo
Returns the netmask address of ifaddr. nil is returned if netmask is not available in ifaddr.
# File 'ext/socket/ifaddr.c', line 214
static VALUE ifaddr_netmask(VALUE self) { struct ifaddrs *ifa = get_ifaddrs(self); if (ifa->ifa_netmask) return rsock_sockaddr_obj(ifa->ifa_netmask, rsock_sockaddr_len(ifa->ifa_netmask)); return Qnil; }
#vhid ⇒ Integer
Returns the vhid address of ifaddr. nil is returned if there is no vhid.
# File 'ext/socket/ifaddr.c', line 266
static VALUE ifaddr_vhid(VALUE self) { struct ifaddrs *ifa = get_ifaddrs(self); if (ifa->ifa_data) return (INT2FIX(((struct if_data*)ifa->ifa_data)->ifi_vhid)); else return Qnil; }