Search code examples
pointersmacruby

how to SCNetworkReachabilityCreateWithName with macruby


i really don't know how to convert the example provided by apple into macruby code, since address is a char pointer, irghhh:

SCNetworkReachabilityRef target;
SCNetworkConnectionFlags flags = 0;
Boolean ok;

target = SCNetworkReachabilityCreateWithAddress(NULL, address);
ok = SCNetworkReachabilityGetFlags(target, &flags);

CFRelease(target);

here is an example implementation in Objective-C:

Determining Internet Availability on iPhone?

UPDATE:

i just realized, that i can do it very quickly with macruby itself, but i am stil interested in how you would do this with macruby.

def network_available?
  Socket.getaddrinfo('example.com', nil)
rescue
  false
end

Solution

  • You should simply get the pointer of your MacRuby NSString instance:

    address = "example.com".pointer
    ...
    target = SCNetworkReachabilityCreateWithAddress(NULL, address)