From 700a5bcaec8efc53afc7d99db3b20fea6ab21b4d Mon Sep 17 00:00:00 2001 From: YuQing <384681@qq.com> Date: Fri, 24 Nov 2023 15:25:14 +0800 Subject: [PATCH] replace type in_addr_t to in_addr_64_t --- HISTORY | 3 +++ src/local_ip_func.c | 9 +++++---- src/local_ip_func.h | 2 +- src/shared_func.c | 12 ++++++------ src/sockopt.c | 6 +++--- src/tests/test_blocked_queue.c | 5 +++-- 6 files changed, 21 insertions(+), 16 deletions(-) diff --git a/HISTORY b/HISTORY index a89b36c..888d19a 100644 --- a/HISTORY +++ b/HISTORY @@ -1,4 +1,7 @@ +Version 1.71 2023-11-24 + * full support IPv6 by pull request #47 + Version 1.70 2023-09-30 * get full mac address of infiniband NIC under Linux * struct fast_task_info add field conn for RDMA connection diff --git a/src/local_ip_func.c b/src/local_ip_func.c index 12d5a65..b529970 100644 --- a/src/local_ip_func.c +++ b/src/local_ip_func.c @@ -160,9 +160,10 @@ const char *get_next_local_ip(const char *previous_ip) pEnd = g_local_host_ip_addrs + \ IP_ADDRESS_SIZE * g_local_host_ip_count; for (p=g_local_host_ip_addrs; p 0) { - qsort(*allow_ip_addrs, *allow_ip_count, sizeof(in_addr_t), \ + qsort(*allow_ip_addrs, *allow_ip_count, sizeof(in_addr_64_t), cmp_by_ip_addr_t); } @@ -2384,7 +2384,7 @@ int load_allow_hosts(IniContext *pIniContext, \ int cmp_by_ip_addr_t(const void *p1, const void *p2) { - return memcmp((in_addr_t *)p1, (in_addr_t *)p2, sizeof(in_addr_t)); + return memcmp((in_addr_64_t *)p1, (in_addr_64_t *)p2, sizeof(in_addr_64_t)); } int parse_bytes(const char *pStr, const int default_unit_bytes, int64_t *bytes) diff --git a/src/sockopt.c b/src/sockopt.c index 1558309..96ea0aa 100644 --- a/src/sockopt.c +++ b/src/sockopt.c @@ -1117,7 +1117,7 @@ in_addr_64_t getIpaddr(getnamefunc getname, int sock, if (convert.sa.addr.sa_family == AF_INET) { return convert.sa.addr4.sin_addr.s_addr; } else { - return *((in_addr_64_t *)&convert.sa.addr6.sin6_addr); + return *((in_addr_64_t *)((char *)&convert.sa.addr6.sin6_addr + 8)); } } @@ -1218,7 +1218,7 @@ in_addr_64_t getIpaddrByName(const char *name, char *buff, const int bufferSize) } } - ip_addr = *((in_addr_64_t *)&ipv6->sin6_addr); + ip_addr = *((in_addr_64_t *)((char *)&ipv6->sin6_addr + 8)); freeaddrinfo(res); return ip_addr; } @@ -1268,7 +1268,7 @@ int getIpaddrsByName(const char *name, continue; } } else { - addr = (struct sockaddr_in *) res->ai_addr; + addr = (struct sockaddr_in *)res->ai_addr; if (inet_ntop(res->ai_family, &addr->sin_addr, ip_addr_arr[ip_count].ip_addr, INET6_ADDRSTRLEN) == NULL) { diff --git a/src/tests/test_blocked_queue.c b/src/tests/test_blocked_queue.c index e87c604..3f15649 100644 --- a/src/tests/test_blocked_queue.c +++ b/src/tests/test_blocked_queue.c @@ -30,6 +30,7 @@ static bool g_continue_flag = true; static int64_t produce_count = 0; static int64_t consume_count = 0; +static struct fast_task_queue free_queue; static struct fast_blocked_queue blocked_queue; #define MAX_USLEEP 10000 @@ -51,7 +52,7 @@ void *producer_thread(void *arg) printf("produce count: %"PRId64"\n", count); } - pTask = free_queue_pop(); + pTask = free_queue_pop(&free_queue); if (pTask != NULL) { blocked_queue_push(&blocked_queue, pTask); } @@ -99,7 +100,7 @@ int main(int argc, char *argv[]) return errno; } - result = free_queue_init(1024, min_buff_size, \ + result = free_queue_init(&free_queue, 1024, min_buff_size, max_buff_size, arg_size); if (result != 0) { return result;