class Subnets::IP6
Public Class Methods
new(p1)
click to toggle source
VALUE method_ip6_new(VALUE class, VALUE hextets) { ip6_t ip; if (RARRAY_LEN(hextets) != 8) { rb_raise(rb_eArgError, "hextets must be size=8, was %ld", RARRAY_LEN(hextets)); } for (ssize_t i = 0; i < RARRAY_LEN(hextets); i++) { ip.x[i] = NUM2INT(RARRAY_AREF(hextets, i)) & 0xffff; } return ip6_new(class, ip); }
random(p1 = v1, p2 = {})
click to toggle source
@overload random(rand=Random.new, opts={})
@param rand [#rand] (optional) a random number generator @param opts [Hash] @option opts [Boolean] :zeros include a random string of zeros at a random position rather than simply randomizing the entire address
@return [IP6] a random IP6
address
VALUE method_ip6_random(int argc, VALUE *argv, VALUE class) { ip6_t ip; VALUE rng; VALUE opts; rb_scan_args(argc, argv, "01:", &rng, &opts); ip6_fill_random(&ip, rng, opts); return ip6_new(class, ip); }
Public Instance Methods
&(p1)
click to toggle source
@param other [Subnets::IP6] @return [Subnets::IP4] bitwise AND of self
and other
VALUE method_ip6_band(VALUE self, VALUE other) { ip6_t *a, *b; assert_kind_of(other, IP6); Data_Get_Struct(self, ip6_t, a); Data_Get_Struct(other, ip6_t, b); return ip6_new(IP6, ip6_band(*a, *b)); }
==(p1)
click to toggle source
@return [Boolean]
VALUE method_ip6_eql_p(VALUE self, VALUE other) { ip6_t *a, *b; if (CLASS_OF(other) != CLASS_OF(self)) { return Qfalse; } Data_Get_Struct(self, ip6_t, a); Data_Get_Struct(other, ip6_t, b); return ip6_eql_p(*a, *b) ? Qtrue : Qfalse; }
Also aliased as: eql?
^(p1)
click to toggle source
@param other [Subnets::IP6] @return [Subnets::IP4] bitwise XOR of self
and other
VALUE method_ip6_xor(VALUE self, VALUE other) { ip6_t *a, *b; assert_kind_of(other, IP6); Data_Get_Struct(self, ip6_t, a); Data_Get_Struct(other, ip6_t, b); return ip6_new(IP6, ip6_xor(*a, *b)); }
hash()
click to toggle source
@return [Integer]
VALUE method_ip6_hash(VALUE self) { ip6_t *ip; VALUE ret; Data_Get_Struct(self, ip6_t, ip); ret = hash(INT2FIX(ip->x[0])); for (int i=1; i<8; i++) { ret = xor(ret, hash(INT2FIX(ip->x[i]))); } return ret; }
hextets()
click to toggle source
@return [Array<Fixnum>] 16-bit hextets, most significant first
VALUE method_ip6_hextets(VALUE self) { ip6_t *ip; VALUE hextets; Data_Get_Struct(self, ip6_t, ip); hextets = rb_ary_new(); for (int i=0; i<8; i++) { rb_ary_push(hextets, INT2FIX(ip->x[i])); } return hextets; }
to_i()
click to toggle source
@return [Numeric] the 128 bit integer representing this address
VALUE method_ip6_to_i(VALUE self) { VALUE ret; ip6_t *ip; ID lshift, plus; Data_Get_Struct(self, ip6_t, ip); lshift = rb_intern("<<"); plus = rb_intern("+"); ret = RB_INT2NUM(0); for (int i=0; i<8; i++) { VALUE hextet = RB_UINT2NUM(ip->x[i]); VALUE inc = rb_funcall(hextet, lshift, 1, RB_INT2NUM(16*(7-i))); ret = rb_funcall(ret, plus, 1, inc); } return ret; }
to_s()
click to toggle source
Return a String of colon-separated hexadecimal parts with multiple zeros compresses with a double-colon.
@return [String]
VALUE method_ip6_to_s(VALUE self) { ip6_t *ip; char buf[64]; Data_Get_Struct(self, ip6_t, ip); ip6_snprint(*ip, buf, 64); return rb_str_new2(buf); }
|(p1)
click to toggle source
@param other [Subnets::IP6] @return [Subnets::IP4] bitwise OR of self
and other
VALUE method_ip6_bor(VALUE self, VALUE other) { ip6_t *a, *b; assert_kind_of(other, IP6); Data_Get_Struct(self, ip6_t, a); Data_Get_Struct(other, ip6_t, b); return ip6_new(IP6, ip6_bor(*a, *b)); }
~()
click to toggle source
@return [Subnets::IP6] bitwise NOT of self
VALUE method_ip6_not(VALUE self) { ip6_t *ip; Data_Get_Struct(self, ip6_t, ip); return ip6_new(IP6, ip6_not(*ip)); }