在线文档教程
Ruby 2.4

Socket::Ifaddr

class Socket::Ifaddr

Parent:Data

Socket :: Ifaddr表示getifaddrs()函数的结果。

公共实例方法

addr → addrinfo Show source

返回ifaddr的地址。如果地址在ifaddr中不可用,则返回nil 。

static VALUE ifaddr_addr(VALUE self) { rb_ifaddr_t *rifaddr = get_ifaddr(self struct ifaddrs *ifa = rifaddr->ifaddr; if (ifa->ifa_addr) return rsock_sockaddr_obj(ifa->ifa_addr, rsock_sockaddr_len(ifa->ifa_addr) return Qnil; }

broadaddr → addrinfo Show source

返回ifaddr的广播地址。如果标志中没有IFF_BROADCAST,则返回nil。

static VALUE ifaddr_broadaddr(VALUE self) { rb_ifaddr_t *rifaddr = get_ifaddr(self struct ifaddrs *ifa = rifaddr->ifaddr; 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 Show source

返回ifaddr的目标地址。如果标志中没有IFF_POINTOPOINT,则返回nil。

static VALUE ifaddr_dstaddr(VALUE self) { rb_ifaddr_t *rifaddr = get_ifaddr(self struct ifaddrs *ifa = rifaddr->ifaddr; 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 Show source

返回ifaddr的标志。

static VALUE ifaddr_flags(VALUE self) { rb_ifaddr_t *rifaddr = get_ifaddr(self struct ifaddrs *ifa = rifaddr->ifaddr; return IFAFLAGS2NUM(ifa->ifa_flags }

ifindex → integer Show source

返回ifaddr的接口索引。

static VALUE ifaddr_ifindex(VALUE self) { rb_ifaddr_t *rifaddr = get_ifaddr(self struct ifaddrs *ifa = rifaddr->ifaddr; 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 Show source

返回一个字符串以显示ifaddr的内容。

static VALUE ifaddr_inspect(VALUE self) { rb_ifaddr_t *rifaddr = get_ifaddr(self struct ifaddrs *ifa; VALUE result; ifa = rifaddr->ifaddr; 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 Show source

返回ifaddr的接口名称。

static VALUE ifaddr_name(VALUE self) { rb_ifaddr_t *rifaddr = get_ifaddr(self struct ifaddrs *ifa = rifaddr->ifaddr; return rb_str_new_cstr(ifa->ifa_name }

netmask → addrinfo Show source

返回ifaddr的网络掩码地址。如果ifaddr中的网络掩码不可用,则返回nil 。

static VALUE ifaddr_netmask(VALUE self) { rb_ifaddr_t *rifaddr = get_ifaddr(self struct ifaddrs *ifa = rifaddr->ifaddr; if (ifa->ifa_netmask) return rsock_sockaddr_obj(ifa->ifa_netmask, rsock_sockaddr_len(ifa->ifa_netmask) return Qnil; }