Project

General

Profile

Feature #13803 ยป Ifaddr.vhid.patch

asomers (Alan Somers), 08/10/2017 08:36 PM

View differences:

ext/socket/extconf.rb (working copy)
476 476
    have_func('inet_aton("", (struct in_addr *)0)', headers)
477 477
  have_func('getservbyport(0, "")', headers)
478 478
  have_func("getifaddrs((struct ifaddrs **)NULL)", headers)
479
  have_struct_member("struct if_data", "ifi_vhid", headers) # FreeBSD
479 480

  
480 481
  have_func("getpeereid", headers)
481 482

  
ext/socket/ifaddr.c (working copy)
256 256
    return Qnil;
257 257
}
258 258

  
259
#ifdef HAVE_STRUCT_IF_DATA_IFI_VHID 
260
/*
261
 * call-seq:
262
 *   ifaddr.vhid => Fixnum
263
 *
264
 * Returns the vhid address of _ifaddr_.
265
 * nil is returned if there is no vhid
266
 */
267

  
268
static VALUE
269
ifaddr_vhid(VALUE self)
270
{
271
    rb_ifaddr_t *rifaddr = get_ifaddr(self);
272
    struct ifaddrs *ifa = rifaddr->ifaddr;
273
    if (ifa->ifa_data)
274
        return (INT2FIX(((struct if_data*)ifa->ifa_data)->ifi_vhid));
275
    else
276
        return Qnil;
277
}
278
#endif
279

  
259 280
static void
260 281
ifaddr_inspect_flags(ifa_flags_t flags, VALUE result)
261 282
{
......
453 474
    rb_define_method(rb_cSockIfaddr, "netmask", ifaddr_netmask, 0);
454 475
    rb_define_method(rb_cSockIfaddr, "broadaddr", ifaddr_broadaddr, 0);
455 476
    rb_define_method(rb_cSockIfaddr, "dstaddr", ifaddr_dstaddr, 0);
477
#ifdef HAVE_STRUCT_IF_DATA_IFI_VHID
478
    rb_define_method(rb_cSockIfaddr, "vhid", ifaddr_vhid, 0);
456 479
#endif
480
#endif
457 481

  
458 482
    rb_define_singleton_method(rb_cSocket, "getifaddrs", socket_s_getifaddrs, 0);
459 483
}