diff options
-rw-r--r-- | include/asterisk/utils.h | 9 | ||||
-rw-r--r-- | main/utils.c | 12 | ||||
-rw-r--r-- | res/res_pjsip_sdp_rtp.c | 7 | ||||
-rw-r--r-- | res/res_pjsip_t38.c | 7 |
4 files changed, 33 insertions, 2 deletions
diff --git a/include/asterisk/utils.h b/include/asterisk/utils.h index 2378c6971..423d73b26 100644 --- a/include/asterisk/utils.h +++ b/include/asterisk/utils.h @@ -1126,4 +1126,13 @@ int ast_file_is_readable(const char *filename); */ int ast_compare_versions(const char *version1, const char *version2); +/* + * \brief Test that an OS supports IPv6 Networking. + * \since 13.14.0 + * + * \return True (non-zero) if the IPv6 supported. + * \return False (zero) if the OS doesn't support IPv6. + */ +int ast_check_ipv6(void); + #endif /* _ASTERISK_UTILS_H */ diff --git a/main/utils.c b/main/utils.c index 2c56af3cd..2033664b8 100644 --- a/main/utils.c +++ b/main/utils.c @@ -2391,6 +2391,18 @@ char *ast_utils_which(const char *binary, char *fullpath, size_t fullpath_size) return NULL; } +int ast_check_ipv6(void) +{ + int udp6_socket = socket(AF_INET6, SOCK_DGRAM, 0); + + if (udp6_socket < 0) { + return 0; + } + + close(udp6_socket); + return 1; +} + void DO_CRASH_NORETURN ast_do_crash(void) { #if defined(DO_CRASH) diff --git a/res/res_pjsip_sdp_rtp.c b/res/res_pjsip_sdp_rtp.c index 7fd4f9abc..4d6a1a168 100644 --- a/res/res_pjsip_sdp_rtp.c +++ b/res/res_pjsip_sdp_rtp.c @@ -38,6 +38,7 @@ #include <pjmedia.h> #include <pjlib.h> +#include "asterisk/utils.h" #include "asterisk/module.h" #include "asterisk/format.h" #include "asterisk/format_cap.h" @@ -1514,7 +1515,11 @@ static int load_module(void) { CHECK_PJSIP_SESSION_MODULE_LOADED(); - ast_sockaddr_parse(&address_rtp, "::", 0); + if (ast_check_ipv6()) { + ast_sockaddr_parse(&address_rtp, "::", 0); + } else { + ast_sockaddr_parse(&address_rtp, "0.0.0.0", 0); + } if (!(sched = ast_sched_context_create())) { ast_log(LOG_ERROR, "Unable to create scheduler context.\n"); diff --git a/res/res_pjsip_t38.c b/res/res_pjsip_t38.c index adc99c30d..79dc9c324 100644 --- a/res/res_pjsip_t38.c +++ b/res/res_pjsip_t38.c @@ -37,6 +37,7 @@ #include <pjmedia.h> #include <pjlib.h> +#include "asterisk/utils.h" #include "asterisk/module.h" #include "asterisk/udptl.h" #include "asterisk/netsock2.h" @@ -916,7 +917,11 @@ static int load_module(void) { CHECK_PJSIP_SESSION_MODULE_LOADED(); - ast_sockaddr_parse(&address, "::", 0); + if (ast_check_ipv6()) { + ast_sockaddr_parse(&address, "::", 0); + } else { + ast_sockaddr_parse(&address, "0.0.0.0", 0); + } if (ast_sip_session_register_supplement(&t38_supplement)) { ast_log(LOG_ERROR, "Unable to register T.38 session supplement\n"); |