Module: GeoIP

Defined in:
ext/geoip/geoip.c

Defined Under Namespace

Classes: City, Country, Domain, ISP, NetSpeed, Organization

Class Method Summary collapse

Class Method Details

.addr_to_num(addr) ⇒ Object

Returns the numeric form of an IP address.

For example: 24.24.24.24 => 404232216

This is used in order to be able to perform searches in CSV versions of the data files or in SQL records if the data has been put there.



361
362
363
364
# File 'ext/geoip/geoip.c', line 361

VALUE rb_geoip_addr_to_num(VALUE self, VALUE addr) {
  Check_Type(addr, T_STRING);
  return UINT2NUM((unsigned int)GeoIP_addr_to_num(StringValuePtr(addr)));
}

.num_to_addr(num) ⇒ Object



367
368
369
370
371
372
373
374
375
# File 'ext/geoip/geoip.c', line 367

VALUE rb_geoip_num_to_addr(VALUE self, VALUE num) {
  VALUE num_type = TYPE(num);
  switch(num_type) {
    case T_FIXNUM: break;
    case T_BIGNUM: break;
    default: rb_raise(rb_eTypeError, "wrong argument type %s (expected Fixnum or Bignum)", rb_obj_classname(num));
  }
  return rb_str_new2((char*)GeoIP_num_to_addr((unsigned long)NUM2ULONG(num)));
}