summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authornobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-22 01:49:00 +0000
committernobu <nobu@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-12-22 01:49:00 +0000
commit70001d5fda6bb87a12a1de580132ecc349656442 (patch)
tree2e93598beaeffd5d4455a138854d36e2f8260790 /ext
parent6e0074d0ff7473ee6152d8cb68855a64b4928ad5 (diff)
downloadruby-70001d5fda6bb87a12a1de580132ecc349656442.tar.gz
ifaddr.c: get_ifaddrs
* ext/socket/ifaddr.c (get_ifaddrs): extract ifaddrs from Socket::Ifaddr. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@61404 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/socket/ifaddr.c35
1 files changed, 15 insertions, 20 deletions
diff --git a/ext/socket/ifaddr.c b/ext/socket/ifaddr.c
index a2dce236d9..26aa0c8082 100644
--- a/ext/socket/ifaddr.c
+++ b/ext/socket/ifaddr.c
@@ -84,6 +84,12 @@ get_ifaddr(VALUE self)
return rifaddr;
}
+static struct ifaddrs *
+get_ifaddrs(VALUE self)
+{
+ return get_ifaddr(self)->ifaddr;
+}
+
static VALUE
rsock_getifaddrs(void)
{
@@ -140,8 +146,7 @@ rsock_getifaddrs(void)
static VALUE
ifaddr_name(VALUE self)
{
- rb_ifaddr_t *rifaddr = get_ifaddr(self);
- struct ifaddrs *ifa = rifaddr->ifaddr;
+ struct ifaddrs *ifa = get_ifaddrs(self);
return rb_str_new_cstr(ifa->ifa_name);
}
@@ -156,8 +161,7 @@ ifaddr_name(VALUE self)
static VALUE
ifaddr_ifindex(VALUE self)
{
- rb_ifaddr_t *rifaddr = get_ifaddr(self);
- struct ifaddrs *ifa = rifaddr->ifaddr;
+ 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);
@@ -178,8 +182,7 @@ ifaddr_ifindex(VALUE self)
static VALUE
ifaddr_flags(VALUE self)
{
- rb_ifaddr_t *rifaddr = get_ifaddr(self);
- struct ifaddrs *ifa = rifaddr->ifaddr;
+ struct ifaddrs *ifa = get_ifaddrs(self);
return IFAFLAGS2NUM(ifa->ifa_flags);
}
@@ -194,8 +197,7 @@ ifaddr_flags(VALUE self)
static VALUE
ifaddr_addr(VALUE self)
{
- rb_ifaddr_t *rifaddr = get_ifaddr(self);
- struct ifaddrs *ifa = rifaddr->ifaddr;
+ 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;
@@ -212,8 +214,7 @@ ifaddr_addr(VALUE self)
static VALUE
ifaddr_netmask(VALUE self)
{
- rb_ifaddr_t *rifaddr = get_ifaddr(self);
- struct ifaddrs *ifa = rifaddr->ifaddr;
+ 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;
@@ -230,8 +231,7 @@ ifaddr_netmask(VALUE self)
static VALUE
ifaddr_broadaddr(VALUE self)
{
- rb_ifaddr_t *rifaddr = get_ifaddr(self);
- struct ifaddrs *ifa = rifaddr->ifaddr;
+ 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;
@@ -248,8 +248,7 @@ ifaddr_broadaddr(VALUE self)
static VALUE
ifaddr_dstaddr(VALUE self)
{
- rb_ifaddr_t *rifaddr = get_ifaddr(self);
- struct ifaddrs *ifa = rifaddr->ifaddr;
+ 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;
@@ -267,8 +266,7 @@ ifaddr_dstaddr(VALUE self)
static VALUE
ifaddr_vhid(VALUE self)
{
- rb_ifaddr_t *rifaddr = get_ifaddr(self);
- struct ifaddrs *ifa = rifaddr->ifaddr;
+ struct ifaddrs *ifa = get_ifaddrs(self);
if (ifa->ifa_data)
return (INT2FIX(((struct if_data*)ifa->ifa_data)->ifi_vhid));
else
@@ -358,12 +356,9 @@ ifaddr_inspect_flags(ifa_flags_t flags, VALUE result)
static VALUE
ifaddr_inspect(VALUE self)
{
- rb_ifaddr_t *rifaddr = get_ifaddr(self);
- struct ifaddrs *ifa;
+ struct ifaddrs *ifa = get_ifaddrs(self);
VALUE result;
- ifa = rifaddr->ifaddr;
-
result = rb_str_new_cstr("#<");
rb_str_append(result, rb_class_name(CLASS_OF(self)));