@@ -50,6 +50,12 @@ constexpr unsigned int socks_header_ipv6_size = 22;
5050
5151constexpr auto expire_seconds = std::chrono::seconds(180 );
5252
53+ #ifdef __linux__
54+ constexpr bool linux_system = true ;
55+ #else
56+ constexpr bool linux_system = false ;
57+ #endif
58+
5359uint8_t convert_error_code (asio::error_code ec);
5460
5561#pragma pack (push, 1)
@@ -876,6 +882,11 @@ awaitable<void> listener_ipv6(const char *username, const char *password, uint16
876882 catch (std::exception &e)
877883 {
878884 std::printf (" IPv6 socks5_listen Exception: %s\n " , e.what ());
885+ if constexpr (linux_system)
886+ {
887+ std::printf (" Fallback to IPv4\n " );
888+ co_spawn (executor, listener_ipv4 (nullptr , nullptr ), detached);
889+ }
879890 }
880891}
881892
@@ -890,8 +901,9 @@ int main(int argc, char *argv[])
890901
891902 if (argc == 1 )
892903 {
893- co_spawn (io_context, listener_ipv4 (nullptr , nullptr ), detached);
894904 co_spawn (io_context, listener_ipv6 (nullptr , nullptr ), detached);
905+ if constexpr (!linux_system)
906+ co_spawn (io_context, listener_ipv4 (nullptr , nullptr ), detached);
895907 }
896908 else if (argc == 2 )
897909 {
@@ -901,13 +913,15 @@ int main(int argc, char *argv[])
901913 std::printf (" Incorrect port number: %d\n " , port);
902914 return 1 ;
903915 }
904- co_spawn (io_context, listener_ipv4 (nullptr , nullptr , (uint16_t )port), detached);
905916 co_spawn (io_context, listener_ipv6 (nullptr , nullptr , (uint16_t )port), detached);
917+ if constexpr (!linux_system)
918+ co_spawn (io_context, listener_ipv4 (nullptr , nullptr , (uint16_t )port), detached);
906919 }
907920 else if (argc == 3 )
908921 {
909- co_spawn (io_context, listener_ipv4 (argv[1 ], argv[2 ]), detached);
910922 co_spawn (io_context, listener_ipv6 (argv[1 ], argv[2 ]), detached);
923+ if constexpr (!linux_system)
924+ co_spawn (io_context, listener_ipv4 (argv[1 ], argv[2 ]), detached);
911925 }
912926 else if (argc == 4 )
913927 {
@@ -917,8 +931,9 @@ int main(int argc, char *argv[])
917931 std::printf (" Incorrect port number: %d\n " , (uint16_t )port);
918932 return 1 ;
919933 }
920- co_spawn (io_context, listener_ipv4 (argv[2 ], argv[3 ], port), detached);
921934 co_spawn (io_context, listener_ipv6 (argv[2 ], argv[3 ], port), detached);
935+ if constexpr (!linux_system)
936+ co_spawn (io_context, listener_ipv4 (argv[2 ], argv[3 ], port), detached);
922937 }
923938 else
924939 {
0 commit comments