diff options
author | Benny Prijono <bennylp@teluu.com> | 2007-10-12 12:14:27 +0000 |
---|---|---|
committer | Benny Prijono <bennylp@teluu.com> | 2007-10-12 12:14:27 +0000 |
commit | b0f62471ea72f5767d859f18e41d4326f57b85c5 (patch) | |
tree | 5be22dd454663b8e8daee9e322ed794ccf54e8c4 /pjsip-apps/src | |
parent | 9ca491d9d373e4f9114b429bcd61b72b1ff97048 (diff) |
Ticket #399: Initial implementation of tool to perform NAT type detection/classification
git-svn-id: http://svn.pjsip.org/repos/pjproject/trunk@1495 74dad513-b988-da41-8d7b-12977e46ad98
Diffstat (limited to 'pjsip-apps/src')
-rw-r--r-- | pjsip-apps/src/pjsua/pjsua_app.c | 36 | ||||
-rw-r--r-- | pjsip-apps/src/pjsua_wince/pjsua_wince.cpp | 23 |
2 files changed, 57 insertions, 2 deletions
diff --git a/pjsip-apps/src/pjsua/pjsua_app.c b/pjsip-apps/src/pjsua/pjsua_app.c index 919a1907..cc3cacac 100644 --- a/pjsip-apps/src/pjsua/pjsua_app.c +++ b/pjsip-apps/src/pjsua/pjsua_app.c @@ -19,7 +19,7 @@ #include <pjsua-lib/pjsua.h> -#define THIS_FILE "pjsua.c" +#define THIS_FILE "pjsua_app.c" #define NO_LIMIT (int)0x7FFFFFFF //#define STEREO_DEMO @@ -2307,6 +2307,33 @@ static void manage_codec_prio(void) } +/* Callback upon NAT detection completion */ +static void nat_detect_cb(void *user_data, + const pj_stun_nat_detect_result *res) +{ + PJ_UNUSED_ARG(user_data); + + if (res->status != PJ_SUCCESS) { + pjsua_perror(THIS_FILE, "NAT detection failed", res->status); + } else { + PJ_LOG(3, (THIS_FILE, "NAT detected as %s", res->nat_type_name)); + } +} + + +/* + * Detect NAT type. + */ +static void detect_nat_type(void) +{ + pj_status_t status; + + status = pjsua_detect_nat_type(NULL, &nat_detect_cb); + if (status != PJ_SUCCESS) + pjsua_perror(THIS_FILE, "Error", status); +} + + /* * Main "user interface" loop. */ @@ -2420,6 +2447,10 @@ void console_app_main(const pj_str_t *uri_to_call) } break; + case 'n': + detect_nat_type(); + break; + case 'i': /* Send instant messaeg */ @@ -3473,6 +3504,9 @@ pj_status_t app_main(void) return status; } + if (app_config.cfg.stun_domain.slen || app_config.cfg.stun_host.slen) + detect_nat_type(); + console_app_main(&uri_arg); return PJ_SUCCESS; diff --git a/pjsip-apps/src/pjsua_wince/pjsua_wince.cpp b/pjsip-apps/src/pjsua_wince/pjsua_wince.cpp index 81e47f39..0367d3b1 100644 --- a/pjsip-apps/src/pjsua_wince/pjsua_wince.cpp +++ b/pjsip-apps/src/pjsua_wince/pjsua_wince.cpp @@ -56,7 +56,7 @@ static HWND hwndActionButton, hwndExitButton; #if 0 // Use this to have the STUN server resolved normally # define STUN_DOMAIN NULL -# define STUN_SERVER "stun.fwdnet.net" +# define STUN_SERVER "192.168.0.2" #elif 0 // Use this to have the STUN server resolved with DNS SRV # define STUN_DOMAIN "iptel.org" @@ -515,6 +515,25 @@ static ATOM MyRegisterClass(HINSTANCE hInstance, LPTSTR szWindowClass) } +/* Callback upon NAT detection completion */ +static void nat_detect_cb(void *user_data, + const pj_stun_nat_detect_result *res) +{ + PJ_UNUSED_ARG(user_data); + + if (res->status != PJ_SUCCESS) { + char msg[250]; + pj_ansi_snprintf(msg, sizeof(msg), "NAT detection failed: %s", + res->status_text); + SetCallStatus(msg, pj_ansi_strlen(msg)); + } else { + char msg[250]; + pj_ansi_snprintf(msg, sizeof(msg), "NAT type is %s", + res->nat_type_name); + SetCallStatus(msg, pj_ansi_strlen(msg)); + } +} + BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) { @@ -548,6 +567,8 @@ BOOL InitInstance(HINSTANCE hInstance, int nCmdShow) CommandBar_Show(hwndCB, TRUE); SetTimer(hMainWnd, ID_POLL_TIMER, 50, NULL); + + pjsua_detect_nat_type(NULL, &nat_detect_cb); return TRUE; } |