code adjust for pull request #47
parent
06f0ce67fd
commit
4eb30adb1a
|
|
@ -49,11 +49,7 @@ typedef DWORD (WINAPI *ThreadEntranceFunc)(LPVOID lpThreadParameter);
|
|||
#endif
|
||||
|
||||
/* Internet address (兼容IPv6长度). */
|
||||
typedef unsigned long int in_addr_64_t;
|
||||
struct in_addr_64
|
||||
{
|
||||
in_addr_64_t s_addr;
|
||||
};
|
||||
typedef uint64_t in_addr_64_t;
|
||||
|
||||
#define FILE_SEPERATOR "/"
|
||||
typedef int SOCKET;
|
||||
|
|
|
|||
|
|
@ -695,11 +695,10 @@ int conn_pool_parse_server_info(const char *pServerStr,
|
|||
memcpy(server_info, pServerStr, len);
|
||||
*(server_info + len) = '\0';
|
||||
|
||||
count = parseAddress(server_info,parts);
|
||||
count = parseAddress(server_info, parts);
|
||||
if (count == 1) {
|
||||
pServerInfo->port = default_port;
|
||||
}
|
||||
else {
|
||||
} else {
|
||||
char *endptr = NULL;
|
||||
pServerInfo->port = (int)strtol(parts[1], &endptr, 10);
|
||||
if ((endptr != NULL && *endptr != '\0') || pServerInfo->port <= 0) {
|
||||
|
|
@ -709,7 +708,7 @@ int conn_pool_parse_server_info(const char *pServerStr,
|
|||
return EINVAL;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
if (getIpaddrByName(parts[0], pServerInfo->ip_addr,
|
||||
sizeof(pServerInfo->ip_addr)) == INADDR_NONE)
|
||||
{
|
||||
|
|
|
|||
|
|
@ -182,6 +182,17 @@ static inline int free_queue_init_ex(struct fast_task_queue *queue,
|
|||
arg_size, NULL);
|
||||
}
|
||||
|
||||
static inline int free_queue_init(struct fast_task_queue *queue,
|
||||
const int max_connections, const int alloc_task_once,
|
||||
const int min_buff_size, const int max_buff_size)
|
||||
{
|
||||
const char *name = "";
|
||||
const bool double_buffers = false;
|
||||
const int arg_size = 0;
|
||||
return free_queue_init_ex(queue, name, double_buffers, max_connections,
|
||||
alloc_task_once, min_buff_size, max_buff_size, arg_size);
|
||||
}
|
||||
|
||||
static inline void free_queue_set_release_callback(
|
||||
struct fast_task_queue *queue,
|
||||
TaskReleaseCallback callback)
|
||||
|
|
|
|||
|
|
@ -85,7 +85,6 @@ int id_generator_init_extra_ex(struct idg_context *context, const char *filename
|
|||
const char *private_ip;
|
||||
struct in_addr ip_addr;
|
||||
struct in6_addr ip6_addr;
|
||||
bool is_local_ip_ok = false;
|
||||
|
||||
private_ip = get_first_local_private_ip();
|
||||
if (private_ip != NULL)
|
||||
|
|
@ -104,23 +103,26 @@ int id_generator_init_extra_ex(struct idg_context *context, const char *filename
|
|||
}
|
||||
else if (strcmp(local_ip, LOCAL_LOOPBACK_IPv4) == 0)
|
||||
{
|
||||
// 注意,当系统存在IPv6回环地址时,为了简化系统的改动,会将IPv6回环地址修改成IPv4回环地址返回
|
||||
// 此处错误打印时,需要带上IPv6回环地址
|
||||
/* 注意,当系统存在IPv6回环地址时,为了简化系统的改动,
|
||||
会将IPv6回环地址修改成IPv4回环地址返回
|
||||
此处错误打印时,需要带上IPv6回环地址
|
||||
*/
|
||||
logWarning("file: "__FILE__", line: %d, "
|
||||
"can't get local ip address, set to %s or %s",
|
||||
__LINE__, LOCAL_LOOPBACK_IPv4, LOCAL_LOOPBACK_IPv6);
|
||||
}
|
||||
}
|
||||
|
||||
if (inet_pton(AF_INET, local_ip, &ip_addr) != 1)
|
||||
{
|
||||
is_local_ip_ok = true;
|
||||
}else if(inet_pton(AF_INET6, local_ip, &ip6_addr) != 1)
|
||||
{
|
||||
is_local_ip_ok = true;
|
||||
}
|
||||
|
||||
if(is_local_ip_ok){
|
||||
if (inet_pton(AF_INET, local_ip, &ip_addr) == 1)
|
||||
{
|
||||
//do nothing
|
||||
}
|
||||
else if(inet_pton(AF_INET6, local_ip, &ip6_addr) == 1)
|
||||
{
|
||||
ip_addr.s_addr = *((in_addr_64_t *)&ip6_addr);
|
||||
}
|
||||
else
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, "
|
||||
"invalid local ip address: %s",
|
||||
__LINE__, local_ip);
|
||||
|
|
|
|||
|
|
@ -83,7 +83,7 @@ const char *local_host_ip_addrs_to_string(char *buff, const int size)
|
|||
|
||||
void log_local_host_ip_addrs()
|
||||
{
|
||||
char buff[512];
|
||||
char buff[1024];
|
||||
logInfo("%s", local_host_ip_addrs_to_string(buff, sizeof(buff)));
|
||||
}
|
||||
|
||||
|
|
@ -124,8 +124,8 @@ void load_local_host_ip_addrs()
|
|||
insert_into_local_host_ip(ip_addresses[k]);
|
||||
}
|
||||
|
||||
// log_local_host_ip_addrs();
|
||||
// print_local_host_ip_addrs();
|
||||
//log_local_host_ip_addrs();
|
||||
//print_local_host_ip_addrs();
|
||||
}
|
||||
|
||||
void print_local_host_ip_addrs()
|
||||
|
|
@ -188,7 +188,9 @@ const char *get_first_local_ip()
|
|||
}
|
||||
else
|
||||
{
|
||||
// 注意,当系统存在IPv6回环地址时,为了简化系统的改动,会将IPv6回环地址修改成IPv4回环地址返回
|
||||
/* 注意,当系统存在IPv6回环地址时,为了简化系统的改动,
|
||||
会将IPv6回环地址修改成IPv4回环地址返回
|
||||
*/
|
||||
return LOCAL_LOOPBACK_IPv4;
|
||||
}
|
||||
}
|
||||
|
|
|
|||
|
|
@ -2829,34 +2829,26 @@ bool is_private_ip(const char* ip)
|
|||
return false;
|
||||
}
|
||||
|
||||
int parseAddress(char *src, char *parts[2]){
|
||||
char *ip = NULL;
|
||||
char *port = NULL;
|
||||
|
||||
// 检查输入字符串是否为IPv6地址格式
|
||||
if (src[0] == '[') {
|
||||
ip = strtok(src, "[]");
|
||||
parts[0] = ip;
|
||||
port = strtok(NULL, ":");
|
||||
if(port=='\0'){
|
||||
return 1;
|
||||
}else{
|
||||
parts[1]=port;
|
||||
return 2;
|
||||
}
|
||||
} else {
|
||||
ip = strtok(src, ":");
|
||||
parts[0] = ip;
|
||||
port = strtok(NULL, ":");
|
||||
if(port=='\0'){
|
||||
return 1;
|
||||
}else{
|
||||
parts[1]=port;
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
}
|
||||
int parseAddress(char *src, char *parts[2])
|
||||
{
|
||||
char *ip;
|
||||
char *port;
|
||||
|
||||
if (src[0] == '[') {
|
||||
ip = strtok(src, "[]");
|
||||
} else {
|
||||
ip = strtok(src, ":");
|
||||
}
|
||||
|
||||
parts[0] = ip;
|
||||
port = strtok(NULL, ":");
|
||||
if (port == NULL) {
|
||||
return 1;
|
||||
} else {
|
||||
parts[1] = port;
|
||||
return 2;
|
||||
}
|
||||
}
|
||||
|
||||
int64_t get_current_time_ns()
|
||||
{
|
||||
|
|
|
|||
|
|
@ -1068,7 +1068,7 @@ const char *fc_inet_ntop(const struct sockaddr *addr,
|
|||
{
|
||||
void *sin_addr;
|
||||
const char *output;
|
||||
|
||||
|
||||
if (addr->sa_family == AF_INET) {
|
||||
sin_addr = &((struct sockaddr_in *)addr)->sin_addr;
|
||||
} else if (addr->sa_family == AF_INET6) {
|
||||
|
|
@ -1092,34 +1092,32 @@ const char *fc_inet_ntop(const struct sockaddr *addr,
|
|||
return output;
|
||||
}
|
||||
|
||||
in_addr_64_t getIpaddr(getnamefunc getname, int sock, \
|
||||
in_addr_64_t getIpaddr(getnamefunc getname, int sock,
|
||||
char *buff, const int bufferSize)
|
||||
{
|
||||
sockaddr_convert_t convert;
|
||||
|
||||
memset(&convert, 0, sizeof(convert));
|
||||
convert.len = sizeof(convert.sa);
|
||||
if (getname(sock, &convert.sa.addr, &convert.len) != 0)
|
||||
{
|
||||
*buff = '\0';
|
||||
return INADDR_NONE;
|
||||
}
|
||||
|
||||
if (convert.len > 0)
|
||||
{
|
||||
memset(&convert, 0, sizeof(convert));
|
||||
convert.len = sizeof(convert.sa);
|
||||
if (getname(sock, &convert.sa.addr, &convert.len) != 0)
|
||||
{
|
||||
*buff = '\0';
|
||||
return INADDR_NONE;
|
||||
}
|
||||
|
||||
if (convert.len > 0)
|
||||
{
|
||||
fc_inet_ntop(&convert.sa.addr, buff, bufferSize);
|
||||
}
|
||||
else
|
||||
{
|
||||
*buff = '\0';
|
||||
}
|
||||
}
|
||||
else
|
||||
{
|
||||
*buff = '\0';
|
||||
}
|
||||
|
||||
if (convert.sa.addr.sa_family == AF_INET) {
|
||||
return convert.sa.addr4.sin_addr.s_addr;
|
||||
return convert.sa.addr4.sin_addr.s_addr;
|
||||
} else {
|
||||
in_addr_64_t ip_addr = 0;
|
||||
memcpy(&ip_addr, &((struct sockaddr_in6 *)&convert.sa.addr)->sin6_addr, sizeof(in_addr_64_t));
|
||||
return ip_addr;
|
||||
return *((in_addr_64_t *)&convert.sa.addr6.sin6_addr);
|
||||
}
|
||||
}
|
||||
|
||||
|
|
@ -1181,14 +1179,16 @@ char *getHostnameByIp(const char *szIpAddr, char *buff, const int bufferSize)
|
|||
in_addr_64_t getIpaddrByName(const char *name, char *buff, const int bufferSize)
|
||||
{
|
||||
struct addrinfo hints, *res, *p;
|
||||
int status;
|
||||
memset(&hints, 0, sizeof hints);
|
||||
hints.ai_family = AF_UNSPEC; // 支持IPv4和IPv6
|
||||
status = getaddrinfo(name, NULL, &hints, &res);
|
||||
if (status != 0)
|
||||
{
|
||||
int status;
|
||||
in_addr_64_t ip_addr;
|
||||
|
||||
memset(&hints, 0, sizeof hints);
|
||||
hints.ai_family = AF_UNSPEC; // 支持IPv4和IPv6
|
||||
status = getaddrinfo(name, NULL, &hints, &res);
|
||||
if (status != 0)
|
||||
{
|
||||
return INADDR_NONE;
|
||||
}
|
||||
}
|
||||
|
||||
for (p = res; p != NULL; p = p->ai_next)
|
||||
{
|
||||
|
|
@ -1203,8 +1203,9 @@ in_addr_64_t getIpaddrByName(const char *name, char *buff, const int bufferSize)
|
|||
}
|
||||
}
|
||||
|
||||
freeaddrinfo(res);
|
||||
return ipv4->sin_addr.s_addr;
|
||||
ip_addr = ipv4->sin_addr.s_addr;
|
||||
freeaddrinfo(res);
|
||||
return ip_addr;
|
||||
}
|
||||
else if (p->ai_family == AF_INET6) // 处理IPv6地址
|
||||
{
|
||||
|
|
@ -1217,14 +1218,13 @@ in_addr_64_t getIpaddrByName(const char *name, char *buff, const int bufferSize)
|
|||
}
|
||||
}
|
||||
|
||||
in_addr_64_t ip_addr = 0;
|
||||
memcpy(&ip_addr, &ipv6->sin6_addr, sizeof(in_addr_64_t));
|
||||
|
||||
freeaddrinfo(res);
|
||||
ip_addr = *((in_addr_64_t *)&ipv6->sin6_addr);
|
||||
freeaddrinfo(res);
|
||||
return ip_addr;
|
||||
}
|
||||
}
|
||||
|
||||
|
||||
freeaddrinfo(res);
|
||||
return INADDR_NONE;
|
||||
}
|
||||
|
||||
|
|
@ -1258,7 +1258,7 @@ int getIpaddrsByName(const char *name,
|
|||
}
|
||||
|
||||
if (res->ai_family == AF_INET6) {
|
||||
addr6 = (struct sockaddr_in6 *) res->ai_addr;
|
||||
addr6 = (struct sockaddr_in6 *)res->ai_addr;
|
||||
if (inet_ntop(res->ai_family, &addr6->sin6_addr,
|
||||
ip_addr_arr[ip_count].ip_addr, INET6_ADDRSTRLEN) == NULL)
|
||||
{
|
||||
|
|
@ -1369,7 +1369,7 @@ int socketBind2(int af, int sock, const char *bind_ipaddr, const int port)
|
|||
}
|
||||
sprintf(bind_ip_prompt, "bind ip %s, ", bind_ipaddr);
|
||||
}
|
||||
|
||||
|
||||
if (bind(sock, &convert.sa.addr, convert.len) < 0)
|
||||
{
|
||||
logError("file: "__FILE__", line: %d, "
|
||||
|
|
@ -2188,9 +2188,10 @@ int getlocaladdrs(char ip_addrs[][IP_ADDRESS_SIZE], \
|
|||
ifc1 = ifc;
|
||||
while (NULL != ifc)
|
||||
{
|
||||
if(NULL == ifc->ifa_addr ){
|
||||
continue;
|
||||
}
|
||||
if (NULL == ifc->ifa_addr ) {
|
||||
ifc = ifc->ifa_next;
|
||||
continue;
|
||||
}
|
||||
|
||||
if (max_count <= *count)
|
||||
{
|
||||
|
|
@ -2201,9 +2202,9 @@ int getlocaladdrs(char ip_addrs[][IP_ADDRESS_SIZE], \
|
|||
return ENOSPC;
|
||||
}
|
||||
|
||||
if (AF_INET == ifc->ifa_addr->sa_family)
|
||||
if (ifc->ifa_addr->sa_family == AF_INET)
|
||||
{
|
||||
if (inet_ntop(AF_INET, &((struct sockaddr_in *)ifc->ifa_addr)-> \
|
||||
if (inet_ntop(AF_INET, &((struct sockaddr_in *)ifc->ifa_addr)->
|
||||
sin_addr, ip_addrs[*count], IP_ADDRESS_SIZE) != NULL)
|
||||
{
|
||||
(*count)++;
|
||||
|
|
@ -2216,10 +2217,9 @@ int getlocaladdrs(char ip_addrs[][IP_ADDRESS_SIZE], \
|
|||
__LINE__, errno, STRERROR(errno));
|
||||
}
|
||||
}
|
||||
|
||||
if (AF_INET6 == ifc->ifa_addr->sa_family)
|
||||
else if (ifc->ifa_addr->sa_family == AF_INET6)
|
||||
{
|
||||
if (inet_ntop(AF_INET6, &((struct sockaddr_in6 *)ifc->ifa_addr)-> \
|
||||
if (inet_ntop(AF_INET6, &((struct sockaddr_in6 *)ifc->ifa_addr)->
|
||||
sin6_addr, ip_addrs[*count], IP_ADDRESS_SIZE) != NULL)
|
||||
{
|
||||
(*count)++;
|
||||
|
|
|
|||
Loading…
Reference in New Issue