@@ -248,6 +248,33 @@ static void GetInterfaceAddresses(const FunctionCallbackInfo<Value>& args) {
248248}
249249
250250
251+ static void GetOnLineStatus (const FunctionCallbackInfo<Value>& args) {
252+ Environment* env = Environment::GetCurrent (args);
253+ uv_interface_address_t * interfaces;
254+ int count, i;
255+
256+ int err = uv_interface_addresses (&interfaces, &count);
257+
258+ if (err == UV_ENOSYS) return args.GetReturnValue ().Set (false );
259+
260+ if (err) {
261+ CHECK_GE (args.Length (), 1 );
262+ env->CollectUVExceptionInfo (
263+ args[args.Length () - 1 ], errno, " uv_interface_addresses" );
264+ return args.GetReturnValue ().Set (false );
265+ }
266+
267+ for (i = 0 ; i < count; i++) {
268+ if (interfaces[i].is_internal == false ) {
269+ return args.GetReturnValue ().Set (true );
270+ }
271+ }
272+
273+ uv_free_interface_addresses (interfaces, count);
274+ return args.GetReturnValue ().Set (false );
275+ }
276+
277+
251278static void GetHomeDirectory (const FunctionCallbackInfo<Value>& args) {
252279 Environment* env = Environment::GetCurrent (args);
253280 char buf[PATH_MAX];
@@ -403,6 +430,7 @@ void Initialize(Local<Object> target,
403430 SetMethod (context, target, " getPriority" , GetPriority);
404431 SetMethod (
405432 context, target, " getAvailableParallelism" , GetAvailableParallelism);
433+ SetMethod (context, target, " getOnLineStatus" , GetOnLineStatus);
406434 SetMethod (context, target, " getOSInformation" , GetOSInformation);
407435 target
408436 ->Set (context,
@@ -419,6 +447,7 @@ void RegisterExternalReferences(ExternalReferenceRegistry* registry) {
419447 registry->Register (GetFreeMemory);
420448 registry->Register (GetCPUInfo);
421449 registry->Register (GetInterfaceAddresses);
450+ registry->Register (GetOnLineStatus);
422451 registry->Register (GetHomeDirectory);
423452 registry->Register (GetUserInfo);
424453 registry->Register (SetPriority);
0 commit comments