diff options
author | Brad King <brad.king@kitware.com> | 2018-01-19 18:03:04 (GMT) |
---|---|---|
committer | Brad King <brad.king@kitware.com> | 2018-01-19 18:03:04 (GMT) |
commit | b58d48c15f9ee18015960e2eed7410f5166c855f (patch) | |
tree | 640add606d5ca6c0a03f58589a7528eaa9511428 /Utilities/cmlibuv/src/unix/getaddrinfo.c | |
parent | e8b57c2283f731f42b4c7eece0531dab67df3d41 (diff) | |
parent | f4a26c748b5ea2cafecdf5490b744a2b167c01ae (diff) | |
download | CMake-b58d48c15f9ee18015960e2eed7410f5166c855f.zip CMake-b58d48c15f9ee18015960e2eed7410f5166c855f.tar.gz CMake-b58d48c15f9ee18015960e2eed7410f5166c855f.tar.bz2 |
Merge branch 'upstream-libuv' into update-libuv
* upstream-libuv:
libuv 2018-01-19 (63de1eca)
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); +} |