diff options
author | libuv upstream <libuv@googlegroups.com> | 2018-01-19 16:57:06 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2018-01-19 18:03:03 (GMT) |
commit | f4a26c748b5ea2cafecdf5490b744a2b167c01ae (patch) | |
tree | f59656c8a8c55c9e5482185a827f24457f1f9ae3 /src/unix/getaddrinfo.c | |
parent | 362435f02a52008a90a1c19862f09b01f1b5bd7f (diff) | |
download | CMake-f4a26c748b5ea2cafecdf5490b744a2b167c01ae.zip CMake-f4a26c748b5ea2cafecdf5490b744a2b167c01ae.tar.gz CMake-f4a26c748b5ea2cafecdf5490b744a2b167c01ae.tar.bz2 |
libuv 2018-01-19 (63de1eca)
Code extracted from:
https://github.com/libuv/libuv.git
at commit 63de1ecad3252d3e9ed2fe960c21d9387615fa45 (v1.x).
Diffstat (limited to 'src/unix/getaddrinfo.c')
-rw-r--r-- | src/unix/getaddrinfo.c | 30 |
1 files changed, 30 insertions, 0 deletions
diff --git a/src/unix/getaddrinfo.c b/src/unix/getaddrinfo.c index 2049aea..0185971 100644 --- a/src/unix/getaddrinfo.c +++ b/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); +} |