@@ -360,16 +360,20 @@ Local<Object> AddressToJS(Environment* env,
360360 a6 = reinterpret_cast <const sockaddr_in6*>(addr);
361361 uv_inet_ntop (AF_INET6, &a6->sin6_addr , ip, sizeof ip);
362362 // Add an interface identifier to a link local address.
363- if (IN6_IS_ADDR_LINKLOCAL (&a6->sin6_addr )) {
364- const size_t addrlen = strlen (ip);
365- CHECK_LT (addrlen, sizeof (ip));
366- ip[addrlen] = ' %' ;
367- size_t scopeidlen = sizeof (ip) - addrlen - 1 ;
368- CHECK_GE (scopeidlen, UV_IF_NAMESIZE);
369- const int r = uv_if_indextoiid (a6->sin6_scope_id ,
370- ip + addrlen + 1 ,
371- &scopeidlen);
372- CHECK_EQ (r, 0 );
363+ if (IN6_IS_ADDR_LINKLOCAL (&a6->sin6_addr ) && a6->sin6_scope_id > 0 ) {
364+ const size_t addrlen = strlen (ip);
365+ CHECK_LT (addrlen, sizeof (ip));
366+ ip[addrlen] = ' %' ;
367+ size_t scopeidlen = sizeof (ip) - addrlen - 1 ;
368+ CHECK_GE (scopeidlen, UV_IF_NAMESIZE);
369+ const int r = uv_if_indextoiid (a6->sin6_scope_id ,
370+ ip + addrlen + 1 ,
371+ &scopeidlen);
372+ if (r) {
373+ env->ThrowUVException (r, " uv_if_indextoiid" );
374+ // TODO(addaleax): Do proper MaybeLocal handling here
375+ return scope.Escape (info);
376+ }
373377 }
374378 port = ntohs (a6->sin6_port );
375379 info->Set (env->context (),
0 commit comments