mirror of
https://github.com/transmission/transmission.git
synced 2025-12-20 02:18:42 +00:00
Handle IPv6 RPC addresses in transmission-remote
This commit is contained in:
@@ -2912,10 +2912,12 @@ static int processArgs(char const* rpcurl, int argc, char const* const* argv)
|
||||
/* [host:port] or [host] or [port] or [http(s?)://host:port/transmission/] */
|
||||
static void getHostAndPortAndRpcUrl(int* argc, char** argv, char** host, int* port, char** rpcurl)
|
||||
{
|
||||
if (*argv[1] != '-')
|
||||
if (*argv[1] == '-')
|
||||
{
|
||||
char const* s = argv[1];
|
||||
char const* delim = strchr(s, ':');
|
||||
return;
|
||||
}
|
||||
|
||||
char const* const s = argv[1];
|
||||
|
||||
if (strncmp(s, "http://", 7) == 0) /* user passed in http rpc url */
|
||||
{
|
||||
@@ -2926,10 +2928,16 @@ static void getHostAndPortAndRpcUrl(int* argc, char** argv, char** host, int* po
|
||||
UseSSL = true;
|
||||
*rpcurl = tr_strdup_printf("%s/rpc/", s + 8);
|
||||
}
|
||||
else if (delim != NULL) /* user passed in both host and port */
|
||||
else
|
||||
{
|
||||
*host = tr_strndup(s, delim - s);
|
||||
*port = atoi(delim + 1);
|
||||
char const* const first_colon = strchr(s, ':');
|
||||
char const* const last_colon = strrchr(s, ':');
|
||||
|
||||
if (last_colon != NULL && ((*s == '[' && *(last_colon - 1) == ']') || first_colon == last_colon))
|
||||
{
|
||||
/* user passed in both host and port */
|
||||
*host = tr_strndup(s, last_colon - s);
|
||||
*port = atoi(last_colon + 1);
|
||||
}
|
||||
else
|
||||
{
|
||||
@@ -2941,10 +2949,19 @@ static void getHostAndPortAndRpcUrl(int* argc, char** argv, char** host, int* po
|
||||
*port = i;
|
||||
}
|
||||
else /* user passed in a host */
|
||||
{
|
||||
if (last_colon != NULL && first_colon != last_colon && (*s != '[' || *(s + strlen(s) - 1) != ']'))
|
||||
{
|
||||
/* looks like IPv6; let's add brackets as we'll be appending the port later on */
|
||||
*host = tr_strdup_printf("[%s]", s);
|
||||
}
|
||||
else
|
||||
{
|
||||
*host = tr_strdup(s);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
*argc -= 1;
|
||||
|
||||
@@ -2953,7 +2970,6 @@ static void getHostAndPortAndRpcUrl(int* argc, char** argv, char** host, int* po
|
||||
argv[i] = argv[i + 1];
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
int tr_main(int argc, char* argv[])
|
||||
{
|
||||
|
||||
Reference in New Issue
Block a user