Add support for ipv6

[Gitee link #I85687]
This commit is contained in:
Aoran Zeng 2024-06-05 10:15:58 +08:00
parent 4936826635
commit 557db108b3
2 changed files with 41 additions and 30 deletions

View File

@ -3,7 +3,7 @@
* License : GPLv3 * License : GPLv3
* Authors : Aoran Zeng <ccmywish@qq.com> * Authors : Aoran Zeng <ccmywish@qq.com>
* Created on : <2023-08-29> * Created on : <2023-08-29>
* Last modified : <2024-05-25> * Last modified : <2024-06-05>
* *
* chsrc: * chsrc:
* *
@ -21,17 +21,21 @@
#define chsrc_error(str) xy_error(xy_2strjoin(App_Prefix, (str))) #define chsrc_error(str) xy_error(xy_2strjoin(App_Prefix, (str)))
int Cli_Option_IPv6 = 0;
int Cli_Optiion_Locally = 0;
int Cli_Option_InEnglish = 0;
/** /**
* *
* *
* @param check_cmd `progname` `progname` * @param check_cmd `prog_name` `prog_name`
* 使 python Windows上 * 使 python Windows上
* Microsoft Store * Microsoft Store
* *
* @param progname * @param prog_name
*/ */
bool bool
query_program_exist (char *check_cmd, char *progname) query_program_exist (char *check_cmd, char *prog_name)
{ {
char *which = check_cmd; char *which = check_cmd;
@ -39,12 +43,15 @@ query_program_exist (char *check_cmd, char *progname)
// char buf[32] = {0}; sprintf(buf, "错误码: %d", ret); // char buf[32] = {0}; sprintf(buf, "错误码: %d", ret);
if (0!=ret) { if (0 != ret)
{
// xy_warn (xy_strjoin(4, "× 命令 ", progname, " 不存在,", buf)); // xy_warn (xy_strjoin(4, "× 命令 ", progname, " 不存在,", buf));
puts (xy_strjoin (4, xy_str_to_red ("x "), "命令 ", xy_str_to_red (progname), " 不存在")); puts (xy_strjoin (4, xy_str_to_red ("x "), "命令 ", xy_str_to_red (prog_name), " 不存在"));
return false; return false;
} else { }
puts (xy_strjoin (4, xy_str_to_green (""), "命令 ", xy_str_to_green (progname), " 存在")); else
{
puts (xy_strjoin (4, xy_str_to_green (""), "命令 ", xy_str_to_green (prog_name), " 存在"));
return true; return true;
} }
} }
@ -147,13 +154,20 @@ test_speed_url (const char *url)
} }
*/ */
char *ipv6 = ""; // 默认不启用
if (Cli_Option_IPv6==1) {
ipv6 = "--ipv6";
}
// 我们用 —L,因为Ruby China源会跳转到其他地方 // 我们用 —L,因为Ruby China源会跳转到其他地方
// npmmirror 也会跳转 // npmmirror 也会跳转
char *curl_cmd = xy_strjoin (6, "curl -qsL -o ", xy_os_devnull, char *curl_cmd = xy_strjoin (7, "curl -qsL ", ipv6,
" -o " xy_os_devnull,
" -w \"%{http_code} %{speed_download}\" -m", time_sec , " -w \"%{http_code} %{speed_download}\" -m", time_sec ,
" -A chsrc/" Chsrc_Version " ", url); " -A chsrc/" Chsrc_Version " ", url);
// xy_info (xy_2strjoin("chsrc: 测速 ", url)); // xy_info (xy_2strjoin ("chsrc: 测速命令 ", curl_cmd));
char *buf = xy_getcmd (curl_cmd, 0, NULL); char *buf = xy_getcmd (curl_cmd, 0, NULL);
// 如果尾部有换行,删除 // 如果尾部有换行,删除

View File

@ -2311,9 +2311,6 @@ get_target (const char *input, TargetOp code, char *option)
return true; return true;
} }
int Cli_Option_IPv6 = 0;
int Cli_Optiion_Locally = 0;
int Cli_Option_InEnglish = 0;
int int
main (int argc, char const *argv[]) main (int argc, char const *argv[])