bugfixed: fdfs_server_info_to_string support IPv6 correctly
parent
030520cb3a
commit
65aeeb28cc
3
HISTORY
3
HISTORY
|
|
@ -1,6 +1,7 @@
|
|||
|
||||
Version 6.12.0 2023-12-21
|
||||
Version 6.12.0 2024-01-11
|
||||
* bugfixed: parse ip and port use parseAddress instead of splitEx
|
||||
* bugfixed: fdfs_server_info_to_string support IPv6 correctly
|
||||
|
||||
Version 6.11.0 2023-12-10
|
||||
* support IPv6, config item: address_family in tracker.conf and storage.conf
|
||||
|
|
|
|||
|
|
@ -500,6 +500,7 @@ int fdfs_parse_server_info_ex(char *server_str, const int default_port,
|
|||
else
|
||||
{
|
||||
snprintf(conn->ip_addr, sizeof(conn->ip_addr), "%s", hosts[i]);
|
||||
conn->af = is_ipv6_addr(conn->ip_addr) ? AF_INET6 : AF_INET;
|
||||
}
|
||||
|
||||
conn->port = port;
|
||||
|
|
@ -516,24 +517,59 @@ int fdfs_server_info_to_string_ex(const TrackerServerInfo *pServer,
|
|||
const ConnectionInfo *conn;
|
||||
const ConnectionInfo *end;
|
||||
int len;
|
||||
bool is_ipv6;
|
||||
|
||||
if (pServer->count <= 0)
|
||||
{
|
||||
*buff = '\0';
|
||||
return 0;
|
||||
}
|
||||
|
||||
if (pServer->count == 1)
|
||||
{
|
||||
return snprintf(buff, buffSize, "%s:%u",
|
||||
pServer->connections[0].ip_addr, port);
|
||||
if (is_ipv6_addr(pServer->connections[0].ip_addr))
|
||||
{
|
||||
return snprintf(buff, buffSize, "[%s]:%u",
|
||||
pServer->connections[0].ip_addr, port);
|
||||
}
|
||||
else
|
||||
{
|
||||
return snprintf(buff, buffSize, "%s:%u",
|
||||
pServer->connections[0].ip_addr, port);
|
||||
}
|
||||
}
|
||||
|
||||
len = snprintf(buff, buffSize, "%s", pServer->connections[0].ip_addr);
|
||||
is_ipv6 = false;
|
||||
end = pServer->connections + pServer->count;
|
||||
for (conn=pServer->connections; conn<end; conn++)
|
||||
{
|
||||
if (is_ipv6_addr(conn->ip_addr))
|
||||
{
|
||||
is_ipv6 = true;
|
||||
break;
|
||||
}
|
||||
}
|
||||
|
||||
if (is_ipv6)
|
||||
{
|
||||
*buff = '[';
|
||||
len = 1;
|
||||
}
|
||||
else
|
||||
{
|
||||
len = 0;
|
||||
}
|
||||
|
||||
len += snprintf(buff + len, buffSize - len, "%s",
|
||||
pServer->connections[0].ip_addr);
|
||||
for (conn=pServer->connections + 1; conn<end; conn++)
|
||||
{
|
||||
len += snprintf(buff + len, buffSize - len, ",%s", conn->ip_addr);
|
||||
}
|
||||
if (is_ipv6 && len < buffSize - 2)
|
||||
{
|
||||
*(buff + len++) = ']';
|
||||
}
|
||||
len += snprintf(buff + len, buffSize - len, ":%d", port);
|
||||
return len;
|
||||
}
|
||||
|
|
|
|||
Loading…
Reference in New Issue