diff --git a/docs/src/misc.rst b/docs/src/misc.rst index 3fea708a8d3..921df4a6826 100644 --- a/docs/src/misc.rst +++ b/docs/src/misc.rst @@ -271,6 +271,12 @@ API and :man:`inet_pton(3)`. On success they return 0. In case of error the target `dst` pointer is unmodified. +.. c:function:: char* uv_if_indextoname(unsigned int ifindex, char* ifname) + + Cross-platform IPv6-capable implementation of :man:`if_indextoname(3)`. + Writes the result to `ifname`, which must be at least `IFNAMSIZ` long. + On success returns the generated string. In case of error returns `NULL`. + .. c:function:: int uv_exepath(char* buffer, size_t* size) Gets the executable path. diff --git a/include/uv-unix.h b/include/uv-unix.h index d7754509b1e..4deb03af832 100644 --- a/include/uv-unix.h +++ b/include/uv-unix.h @@ -32,6 +32,7 @@ #include #include #include +#include #include #include diff --git a/include/uv.h b/include/uv.h index 6aa43a271c2..9bd82f5e4e0 100644 --- a/include/uv.h +++ b/include/uv.h @@ -1392,6 +1392,8 @@ UV_EXTERN int uv_ip6_name(const struct sockaddr_in6* src, char* dst, size_t size UV_EXTERN int uv_inet_ntop(int af, const void* src, char* dst, size_t size); UV_EXTERN int uv_inet_pton(int af, const char* src, void* dst); +UV_EXTERN char* uv_if_indextoname(unsigned int ifindex, char* ifname); + UV_EXTERN int uv_exepath(char* buffer, size_t* size); UV_EXTERN int uv_cwd(char* buffer, size_t* size); diff --git a/src/inet.c b/src/inet.c index da63a688c4e..2e7d527c9e2 100644 --- a/src/inet.c +++ b/src/inet.c @@ -49,6 +49,9 @@ int uv_inet_ntop(int af, const void* src, char* dst, size_t size) { /* NOTREACHED */ } +char* uv_if_indextoname(unsigned int ifindex, char* ifname) { + return if_indextoname(ifindex, ifname); +} static int inet_ntop4(const unsigned char *src, char *dst, size_t size) { static const char fmt[] = "%u.%u.%u.%u"; diff --git a/test/test-ip6-addr.c b/test/test-ip6-addr.c index 156fccde39d..c86f4523824 100644 --- a/test/test-ip6-addr.c +++ b/test/test-ip6-addr.c @@ -67,6 +67,8 @@ TEST_IMPL(ip6_addr_link_local) { iface_index = address->address.address6.sin6_scope_id; device_name = address->name; + ASSERT(0 == strcmp(device_name, uv_if_indextoname(iface_index, scoped_addr))); + #ifdef _WIN32 snprintf(scoped_addr, sizeof(scoped_addr),