diff --git a/docs/src/misc.rst b/docs/src/misc.rst index 87a29a845bd..f00855c00a2 100644 --- a/docs/src/misc.rst +++ b/docs/src/misc.rst @@ -267,6 +267,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 54b3123a0c8..0bff2512967 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 c0442c6a437..37b8705c5a8 100644 --- a/include/uv.h +++ b/include/uv.h @@ -1442,6 +1442,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 d76f63d2dda..dabdfe4e1bf 100644 --- a/src/inet.c +++ b/src/inet.c @@ -44,6 +44,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";