From 094f3900c1b401390c3e4c7bb732affbc041346b Mon Sep 17 00:00:00 2001 From: yuqing Date: Tue, 17 May 2016 21:21:29 +0800 Subject: [PATCH] inet_aton to inet_pton --- HISTORY | 3 ++- src/connection_pool.c | 18 +++++++++--------- src/shared_func.c | 4 +++- src/sockopt.c | 6 +++--- 4 files changed, 17 insertions(+), 14 deletions(-) diff --git a/HISTORY b/HISTORY index 6a69b48..4af9c61 100644 --- a/HISTORY +++ b/HISTORY @@ -1,6 +1,7 @@ -Version 1.28 2016-05-14 +Version 1.28 2016-05-17 * id generator support extra bits + * change inet_aton to inet_pton Version 1.27 2016-04-15 * add function fd_set_cloexec diff --git a/src/connection_pool.c b/src/connection_pool.c index ecf6dfd..05d0752 100644 --- a/src/connection_pool.c +++ b/src/connection_pool.c @@ -120,18 +120,18 @@ int conn_pool_connect_server(ConnectionInfo *pConnection, \ static int conn_pool_get_key(const ConnectionInfo *conn, char *key, int *key_len) { - struct in_addr sin_addr; + struct in_addr sin_addr; - if (inet_aton(conn->ip_addr, &sin_addr) == 0) - { - *key_len = 0; - return EINVAL; - } + if (inet_pton(AF_INET, conn->ip_addr, &sin_addr) == 0) + { + *key_len = 0; + return EINVAL; + } - int2buff(sin_addr.s_addr, key); - *key_len = 4 + sprintf(key + 4, "%d", conn->port); + int2buff(sin_addr.s_addr, key); + *key_len = 4 + sprintf(key + 4, "%d", conn->port); - return 0; + return 0; } ConnectionInfo *conn_pool_get_connection(ConnectionPool *cp, diff --git a/src/shared_func.c b/src/shared_func.c index f9f4d4d..17777d9 100644 --- a/src/shared_func.c +++ b/src/shared_func.c @@ -1886,8 +1886,10 @@ int load_allow_hosts(IniContext *pIniContext, \ for (i=0; i<*allow_ip_count; i++) { struct in_addr address; + char buff[INET_ADDRSTRLEN]; address.s_addr = (*allow_ip_addrs)[i]; - logDebug("%d. %s", i + 1, inet_ntoa(address)); + logDebug("%d. %s", i + 1, inet_ntop(AF_INET, &address, + buff, sizeof(buff))); } return 0; diff --git a/src/sockopt.c b/src/sockopt.c index 4519d1b..3a0f1fc 100644 --- a/src/sockopt.c +++ b/src/sockopt.c @@ -465,7 +465,7 @@ int connectserverbyip(int sock, const char *server_ip, const short server_port) addr.sin_family = PF_INET; addr.sin_port = htons(server_port); - result = inet_aton(server_ip, &addr.sin_addr); + result = inet_pton(AF_INET, server_ip, &addr.sin_addr); if (result == 0 ) { return EINVAL; @@ -501,7 +501,7 @@ int connectserverbyip_nb_ex(int sock, const char *server_ip, \ addr.sin_family = PF_INET; addr.sin_port = htons(server_port); - result = inet_aton(server_ip, &addr.sin_addr); + result = inet_pton(AF_INET, server_ip, &addr.sin_addr); if (result == 0 ) { return EINVAL; @@ -754,7 +754,7 @@ int socketBind(int sock, const char *bind_ipaddr, const int port) } else { - if (inet_aton(bind_ipaddr, &bindaddr.sin_addr) == 0) + if (inet_pton(AF_INET, bind_ipaddr, &bindaddr.sin_addr) == 0) { logError("file: "__FILE__", line: %d, " \ "invalid ip addr %s", \