mirror of
https://github.com/libuv/libuv
synced 2025-03-28 21:13:16 +00:00
add uv_ip4_name and uv_ip6_name
This commit is contained in:
parent
4eff34da43
commit
07b49ce59a
@ -514,9 +514,15 @@ int64_t uv_now();
|
||||
|
||||
|
||||
/* Utility */
|
||||
|
||||
/* Convert string ip addresses to binary structures */
|
||||
struct sockaddr_in uv_ip4_addr(const char* ip, int port);
|
||||
struct sockaddr_in6 uv_ip6_addr(const char* ip, int port);
|
||||
|
||||
/* Convert binary addresses to strings */
|
||||
int uv_ip4_name(struct sockaddr_in* src, char* dst, size_t size);
|
||||
int uv_ip6_name(struct sockaddr_in6* src, char* dst, size_t size);
|
||||
|
||||
/* Gets the executable path */
|
||||
int uv_exepath(char* buffer, size_t* size);
|
||||
|
||||
|
@ -18,6 +18,7 @@
|
||||
*/
|
||||
|
||||
#ifdef HAVE_INET_NTOP
|
||||
#include <arpa/inet.h>
|
||||
#define ares_inet_ntop(w,x,y,z) inet_ntop(w,x,y,z)
|
||||
#else
|
||||
const char *ares_inet_ntop(int af, const void *src, char *dst, size_t size);
|
||||
|
@ -29,6 +29,7 @@
|
||||
/* use inet_pton from c-ares if necessary */
|
||||
#include "ares_config.h"
|
||||
#include "ares/inet_net_pton.h"
|
||||
#include "ares/inet_ntop.h"
|
||||
|
||||
/* list used for ares task handles */
|
||||
static uv_ares_task_t* uv_ares_handles_ = NULL;
|
||||
@ -112,6 +113,18 @@ struct sockaddr_in6 uv_ip6_addr(const char* ip, int port) {
|
||||
}
|
||||
|
||||
|
||||
int uv_ip4_name(struct sockaddr_in* src, char* dst, size_t size) {
|
||||
char* d = ares_inet_ntop(AF_INET, &src->sin_addr, dst, size);
|
||||
return d != dst;
|
||||
}
|
||||
|
||||
|
||||
int uv_ip6_name(struct sockaddr_in6* src, char* dst, size_t size) {
|
||||
char* d = ares_inet_ntop(AF_INET6, &src->sin6_addr, dst, size);
|
||||
return d != dst;
|
||||
}
|
||||
|
||||
|
||||
/* find matching ares handle in list */
|
||||
void uv_add_ares_handle(uv_ares_task_t* handle) {
|
||||
handle->ares_next = uv_ares_handles_;
|
||||
|
@ -151,6 +151,15 @@ static int tcp_listener(int port) {
|
||||
fprintf(stderr, "uv_getsockname error (listening) %d\n", uv_last_error().code);
|
||||
}
|
||||
ASSERT(r == 0);
|
||||
|
||||
char ip[20];
|
||||
r = uv_ip4_name((struct sockaddr_in*)&sockname, ip, 20);
|
||||
ASSERT(r == 0);
|
||||
ASSERT(ip[0] == '0');
|
||||
ASSERT(ip[1] == '.');
|
||||
ASSERT(ip[2] == '0');
|
||||
printf("sockname = %s\n", ip);
|
||||
|
||||
getsocknamecount++;
|
||||
|
||||
return 0;
|
||||
|
Loading…
x
Reference in New Issue
Block a user