Class: Subnets::IP4
Class Method Summary collapse
- .new(address) ⇒ Object
-
.random(rng = Random.new) ⇒ IP4
A random IP4 address.
Instance Method Summary collapse
-
#&(other) ⇒ Subnets::IP4
Bitwise AND of
selfandother. - #==(other) ⇒ Boolean (also: #eql?)
-
#^(other) ⇒ Subnets::IP4
Bitwise exclusive XOR of
selfandother. - #hash ⇒ Integer
-
#to_i ⇒ Numeric
The 32 bit integer representing this address.
-
#to_s ⇒ String
Return a String in dotted-decimal notation.
-
#|(other) ⇒ Subnets::IP4
Bitwise OR of
selfandother. -
#~ ⇒ IP4
Bitwise NOT of
self.
Methods inherited from IP
Class Method Details
.new(address) ⇒ Object
81 82 83 84 |
# File 'ext/subnets/ext.c', line 81
VALUE
method_ip4_new(VALUE class, VALUE address) {
return ip4_new(class, RB_NUM2UINT(address));
}
|
.random(rng = Random.new) ⇒ IP4
Returns a random IP4 address.
187 188 189 190 191 192 193 194 195 196 197 198 199 200 201 202 |
# File 'ext/subnets/ext.c', line 187
VALUE
method_ip4_random(int argc, VALUE *argv, VALUE class) {
ip4_t ip;
VALUE rng, rand;
rb_scan_args(argc, argv, "01", &rng);
if (Qnil == rng) {
rng = rb_funcall(rb_cRandom, rb_intern("new"), 0);
}
rand = rb_intern("rand");
ip = FIX2INT(rb_funcall(rng, rand, 1, INT2FIX(0xffff+1)));
ip |= FIX2INT(rb_funcall(rng, rand, 1, INT2FIX(0xffff+1))) << 16;
return ip4_new(class, ip);
}
|
Instance Method Details
#&(other) ⇒ Subnets::IP4
341 342 343 344 345 346 347 348 349 350 |
# File 'ext/subnets/ext.c', line 341
VALUE
method_ip4_band(VALUE self, VALUE other) {
ip4_t *a, *b;
assert_kind_of(other, IP4);
Data_Get_Struct(self, ip4_t, a);
Data_Get_Struct(other, ip4_t, b);
return ip4_new(IP4, *a & *b);
}
|
#==(other) ⇒ Boolean Also known as: eql?
622 623 624 625 626 627 628 629 630 631 632 633 634 |
# File 'ext/subnets/ext.c', line 622
VALUE
method_ip4_eql_p(VALUE self, VALUE other) {
ip4_t *a, *b;
if (CLASS_OF(other) != CLASS_OF(self)) {
return Qfalse;
}
Data_Get_Struct(self, ip4_t, a);
Data_Get_Struct(other, ip4_t, b);
return (*a == *b) ? Qtrue : Qfalse;
}
|
#^(other) ⇒ Subnets::IP4
326 327 328 329 330 331 332 333 334 335 |
# File 'ext/subnets/ext.c', line 326
VALUE
method_ip4_xor(VALUE self, VALUE other) {
ip4_t *a, *b;
assert_kind_of(other, IP4);
Data_Get_Struct(self, ip4_t, a);
Data_Get_Struct(other, ip4_t, b);
return ip4_new(IP4, *a ^ *b);
}
|
#hash ⇒ Integer
703 704 705 706 707 708 |
# File 'ext/subnets/ext.c', line 703 VALUE method_ip4_hash(VALUE self) { ip4_t *ip; Data_Get_Struct(self, ip4_t, ip); return hash(UINT2NUM(*ip)); } |
#to_i ⇒ Numeric
587 588 589 590 591 592 |
# File 'ext/subnets/ext.c', line 587 VALUE method_ip4_to_i(VALUE self) { ip4_t *ip; Data_Get_Struct(self, ip4_t, ip); return RB_UINT2NUM(*ip); } |
#to_s ⇒ String
Return a String in dotted-decimal notation.
528 529 530 531 532 533 534 535 536 |
# File 'ext/subnets/ext.c', line 528 VALUE method_ip4_to_s(VALUE self) { ip4_t *ip; char buf[16]; Data_Get_Struct(self, ip4_t, ip); ip4_snprint(*ip, buf, 16); return rb_str_new2(buf); } |
#|(other) ⇒ Subnets::IP4
311 312 313 314 315 316 317 318 319 320 |
# File 'ext/subnets/ext.c', line 311
VALUE
method_ip4_bor(VALUE self, VALUE other) {
ip4_t *a, *b;
assert_kind_of(other, IP4);
Data_Get_Struct(self, ip4_t, a);
Data_Get_Struct(other, ip4_t, b);
return ip4_new(IP4, *a | *b);
}
|
#~ ⇒ IP4
300 301 302 303 304 305 |
# File 'ext/subnets/ext.c', line 300
VALUE
method_ip4_not(VALUE self) {
ip4_t *ip;
Data_Get_Struct(self, ip4_t, ip);
return ip4_new(IP4, ~ *ip);
}
|