diff options
Diffstat (limited to 'Utilities/cmlibuv/src/unix/getaddrinfo.c')
-rw-r--r-- | Utilities/cmlibuv/src/unix/getaddrinfo.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/Utilities/cmlibuv/src/unix/getaddrinfo.c b/Utilities/cmlibuv/src/unix/getaddrinfo.c index 2049aea..0185971 100644 --- a/Utilities/cmlibuv/src/unix/getaddrinfo.c +++ b/Utilities/cmlibuv/src/unix/getaddrinfo.c @@ -32,6 +32,7 @@ #include <stddef.h> /* NULL */ #include <stdlib.h> #include <string.h> +#include <net/if.h> /* if_indextoname() */ /* EAI_* constants. */ #include <netdb.h> @@ -200,3 +201,32 @@ void uv_freeaddrinfo(struct addrinfo* ai) { if (ai) freeaddrinfo(ai); } + + +int uv_if_indextoname(unsigned int ifindex, char* buffer, size_t* size) { + char ifname_buf[UV_IF_NAMESIZE]; + size_t len; + + if (buffer == NULL || size == NULL || *size == 0) + return UV_EINVAL; + + if (if_indextoname(ifindex, ifname_buf) == NULL) + return -errno; + + len = strnlen(ifname_buf, sizeof(ifname_buf)); + + if (*size <= len) { + *size = len + 1; + return UV_ENOBUFS; + } + + memcpy(buffer, ifname_buf, len); + buffer[len] = '\0'; + *size = len; + + return 0; +} + +int uv_if_indextoiid(unsigned int ifindex, char* buffer, size_t* size) { + return uv_if_indextoname(ifindex, buffer, size); +} |