summaryrefslogtreecommitdiff
path: root/ext
diff options
context:
space:
mode:
authornaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-08-31 08:29:38 +0000
committernaruse <naruse@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2017-08-31 08:29:38 +0000
commite7ddf8788f1eb9da7351d21a19c2c53228aac164 (patch)
treea68b401662e33253a701e21e2d9a0c443da0fa75 /ext
parent9f1994ed5ce9e5f3a0964058b4753a021a92e40d (diff)
Add Socket::Ifaddr.vhid on supported platforms [Feature #13803]
patched by Alan Somers git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@59702 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext')
-rw-r--r--ext/socket/extconf.rb1
-rw-r--r--ext/socket/ifaddr.c24
2 files changed, 25 insertions, 0 deletions
diff --git a/ext/socket/extconf.rb b/ext/socket/extconf.rb
index 247127b..ec89bed 100644
--- a/ext/socket/extconf.rb
+++ b/ext/socket/extconf.rb
@@ -476,6 +476,7 @@ EOF
have_func('inet_aton("", (struct in_addr *)0)', headers)
have_func('getservbyport(0, "")', headers)
have_func("getifaddrs((struct ifaddrs **)NULL)", headers)
+ have_struct_member("struct if_data", "ifi_vhid", headers) # FreeBSD
have_func("getpeereid", headers)
diff --git a/ext/socket/ifaddr.c b/ext/socket/ifaddr.c
index a954163..4e2fc06 100644
--- a/ext/socket/ifaddr.c
+++ b/ext/socket/ifaddr.c
@@ -256,6 +256,27 @@ ifaddr_dstaddr(VALUE self)
return Qnil;
}
+#ifdef HAVE_STRUCT_IF_DATA_IFI_VHID
+/*
+ * call-seq:
+ * ifaddr.vhid => Integer
+ *
+ * Returns the vhid address of _ifaddr_.
+ * nil is returned if there is no vhid
+ */
+
+static VALUE
+ifaddr_vhid(VALUE self)
+{
+ rb_ifaddr_t *rifaddr = get_ifaddr(self);
+ struct ifaddrs *ifa = rifaddr->ifaddr;
+ if (ifa->ifa_data)
+ return (INT2FIX(((struct if_data*)ifa->ifa_data)->ifi_vhid));
+ else
+ return Qnil;
+}
+#endif
+
static void
ifaddr_inspect_flags(ifa_flags_t flags, VALUE result)
{
@@ -453,6 +474,9 @@ rsock_init_sockifaddr(void)
rb_define_method(rb_cSockIfaddr, "netmask", ifaddr_netmask, 0);
rb_define_method(rb_cSockIfaddr, "broadaddr", ifaddr_broadaddr, 0);
rb_define_method(rb_cSockIfaddr, "dstaddr", ifaddr_dstaddr, 0);
+#ifdef HAVE_STRUCT_IF_DATA_IFI_VHID
+ rb_define_method(rb_cSockIfaddr, "vhid", ifaddr_vhid, 0);
+#endif
#endif
rb_define_singleton_method(rb_cSocket, "getifaddrs", socket_s_getifaddrs, 0);