Make usage of grpc_inet_ntop consistent

pull/7665/head
murgatroid99 9 years ago
parent 0b110dd28d
commit 31963632dc
  1. 4
      src/core/lib/iomgr/sockaddr_utils.c
  2. 2
      src/core/lib/iomgr/socket_utils.h
  3. 4
      src/core/lib/iomgr/socket_utils_common_posix.c
  4. 5
      src/core/lib/iomgr/socket_utils_windows.c

@ -42,6 +42,7 @@
#include <grpc/support/port_platform.h> #include <grpc/support/port_platform.h>
#include <grpc/support/string_util.h> #include <grpc/support/string_util.h>
#include "src/core/lib/iomgr/socket_utils.h"
#include "src/core/lib/iomgr/unix_sockets_posix.h" #include "src/core/lib/iomgr/unix_sockets_posix.h"
#include "src/core/lib/support/string.h" #include "src/core/lib/support/string.h"
@ -155,9 +156,8 @@ int grpc_sockaddr_to_string(char **out, const struct sockaddr *addr,
ip = &addr6->sin6_addr; ip = &addr6->sin6_addr;
port = ntohs(addr6->sin6_port); port = ntohs(addr6->sin6_port);
} }
/* Windows inet_ntop wants a mutable ip pointer */
if (ip != NULL && if (ip != NULL &&
inet_ntop(addr->sa_family, (void *)ip, ntop_buf, sizeof(ntop_buf)) != grpc_inet_ntop(addr->sa_family, ip, ntop_buf, sizeof(ntop_buf)) !=
NULL) { NULL) {
ret = gpr_join_host_port(out, ntop_buf, port); ret = gpr_join_host_port(out, ntop_buf, port);
} else { } else {

@ -43,7 +43,7 @@
#endif #endif
/* A wrapper for inet_ntop on POSIX systems and InetNtop on Windows systems */ /* A wrapper for inet_ntop on POSIX systems and InetNtop on Windows systems */
const char *grpc_inet_ntop(int af, void *src, const char *grpc_inet_ntop(int af, const void *src,
char *dst, socklen_t size); char *dst, socklen_t size);
#endif /* GRPC_CORE_LIB_IOMGR_SOCKET_UTILS_H */ #endif /* GRPC_CORE_LIB_IOMGR_SOCKET_UTILS_H */

@ -297,9 +297,9 @@ grpc_error *grpc_create_dualstack_socket(const struct sockaddr *addr, int type,
return error_for_fd(*newfd, addr); return error_for_fd(*newfd, addr);
} }
const char *grpc_inet_ntop(int af, void *src, const char *grpc_inet_ntop(int af, const void *src,
char *dst, socklen_t size) { char *dst, socklen_t size) {
return inet_ntop(af, (const void*)src, dst, size); return inet_ntop(af, src, dst, size);
} }
#endif #endif

@ -39,10 +39,11 @@
#include <grpc/support/log.h> #include <grpc/support/log.h>
const char *grpc_inet_ntop(int af, void *src, const char *grpc_inet_ntop(int af, const void *src,
char *dst, socklen_t size) { char *dst, socklen_t size) {
GPR_ASSERT(sizeof(socklen_t) <= sizeof(size_t)); GPR_ASSERT(sizeof(socklen_t) <= sizeof(size_t));
return InetNtopA(af, src, dst, (size_t)size); /* Windows InetNtopA wants a mutable ip pointer */
return InetNtopA(af, (void*)src, dst, (size_t)size);
} }
#endif /* GRPC_WINDOWS_SOCKETUTILS */ #endif /* GRPC_WINDOWS_SOCKETUTILS */

Loading…
Cancel
Save