@@ -247,6 +247,32 @@ static void GetInterfaceAddresses(const FunctionCallbackInfo<Value>& args) {
247247 args.GetReturnValue ().Set (Array::New (isolate, result.data (), result.size ()));
248248}
249249
250+ static void GetOnLineStatus (const FunctionCallbackInfo<Value>& args) {
251+ Environment* env = Environment::GetCurrent (args);
252+ uv_interface_address_t * interfaces;
253+ int count, i;
254+
255+ int err = uv_interface_addresses (&interfaces, &count);
256+
257+ if (err == UV_ENOSYS) return args.GetReturnValue ().Set (false );
258+
259+ if (err) {
260+ CHECK_GE (args.Length (), 1 );
261+ env->CollectUVExceptionInfo (
262+ args[args.Length () - 1 ], errno, " uv_interface_addresses" );
263+ return args.GetReturnValue ().Set (false );
264+ }
265+
266+ for (i = 0 ; i < count; i++) {
267+ if (interfaces[i].is_internal == false ) {
268+ uv_free_interface_addresses (interfaces, count);
269+ return args.GetReturnValue ().Set (true );
270+ }
271+ }
272+
273+ uv_free_interface_addresses (interfaces, count);
274+ return args.GetReturnValue ().Set (false );
275+ }
250276
251277static void GetHomeDirectory (const FunctionCallbackInfo<Value>& args) {
252278 Environment* env = Environment::GetCurrent (args);
@@ -403,6 +429,7 @@ void Initialize(Local<Object> target,
403429 SetMethod (context, target, " getPriority" , GetPriority);
404430 SetMethod (
405431 context, target, " getAvailableParallelism" , GetAvailableParallelism);
432+ SetMethod (context, target, " getOnLineStatus" , GetOnLineStatus);
406433 SetMethod (context, target, " getOSInformation" , GetOSInformation);
407434 target
408435 ->Set (context,
@@ -419,6 +446,7 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
419446 registry->Register (GetFreeMemory);
420447 registry->Register (GetCPUInfo);
421448 registry->Register (GetInterfaceAddresses);
449+ registry->Register (GetOnLineStatus);
422450 registry->Register (GetHomeDirectory);
423451 registry->Register (GetUserInfo);
424452 registry->Register (SetPriority);
0 commit comments