Method: Subnets::Net4#include?

Defined in:
ext/subnets/ext.c

#include?(v) ⇒ Boolean Also known as: ===

Test if this network includes v.

A String must parse as an IP4 or Net4. An IP4 must be included within the range defined by this network. A Net4 must both have a prefixlen greater than or equal to that of this network, and have an address included within the range defined by this network.

Parameters:

Returns:

  • (Boolean)


443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
# File 'ext/subnets/ext.c', line 443

VALUE
method_net4_include_p(VALUE self, VALUE v) {
  net4_t *net;
  Data_Get_Struct(self, net4_t, net);

  if (CLASS_OF(v) == IP4) {
    ip4_t *ip;
    Data_Get_Struct(v, ip4_t, ip);
    return net4_include_p(*net, *ip) ? Qtrue : Qfalse;
  } else if (CLASS_OF(v) == Net4) {
    net4_t *other;
    Data_Get_Struct(v, net4_t, other);
    return net4_include_net4_p(*net, *other) ? Qtrue : Qfalse;
  } else if (CLASS_OF(v) == IP6 || CLASS_OF(v) == Net6) {
    return Qfalse;
  } else {
    v = StringValue(v);

    {
      net4_t other;
      if (read_net4_strict(RSTRING_PTR(v), &other)) {
        return net4_include_net4_p(*net, other) ? Qtrue : Qfalse;
      }
    }
    {
      ip4_t ip;
      if (read_ip4_strict(RSTRING_PTR(v), &ip)) {
        return net4_include_p(*net, ip) ? Qtrue : Qfalse;
      }
    }

    return Qfalse;
  }
}