From a23308e8799823deaa27ad78c8a2849a81946c9e Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A9sz=C3=A1ros=20Mih=C3=A1ly?= Date: Mon, 4 Sep 2017 14:34:04 +0200 Subject: [PATCH 1/3] Display Local address --- src/apps/natdiscovery/natdiscovery.c | 2 ++ 1 file changed, 2 insertions(+) diff --git a/src/apps/natdiscovery/natdiscovery.c b/src/apps/natdiscovery/natdiscovery.c index 8c8ae67..a07bd91 100644 --- a/src/apps/natdiscovery/natdiscovery.c +++ b/src/apps/natdiscovery/natdiscovery.c @@ -201,6 +201,7 @@ static int run_stunclient(ioa_addr *remote_addr, ioa_addr *reflexive_addr, ioa_a addr_debug_print(1, other_addr, "Other addr: "); } addr_debug_print(1, reflexive_addr, "UDP reflexive addr"); + addr_debug_print(1, &real_local_addr, "Local addr: "); } else { printf("Cannot read the response\n"); @@ -337,6 +338,7 @@ static int run_stunclient(ioa_addr *remote_addr, ioa_addr *reflexive_addr, ioa_a addr_debug_print(1, other_addr, "Other addr: "); } addr_debug_print(1, reflexive_addr, "UDP reflexive addr"); + addr_debug_print(1, &real_local_addr, "Local addr: "); } else { printf("Cannot read the response\n"); From 0562a89a413b0ea670f83c83502fb0b8aba4ad34 Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A9sz=C3=A1ros=20Mih=C3=A1ly?= Date: Mon, 4 Sep 2017 14:34:49 +0200 Subject: [PATCH 2/3] Tidy:Remove trailing witespace --- src/apps/natdiscovery/natdiscovery.c | 14 +++++++------- 1 file changed, 7 insertions(+), 7 deletions(-) diff --git a/src/apps/natdiscovery/natdiscovery.c b/src/apps/natdiscovery/natdiscovery.c index a07bd91..c28650a 100644 --- a/src/apps/natdiscovery/natdiscovery.c +++ b/src/apps/natdiscovery/natdiscovery.c @@ -246,7 +246,7 @@ static int run_stunclient(ioa_addr *remote_addr, ioa_addr *reflexive_addr, ioa_a if (!addr_any(&real_local_addr)) { if (response_port >= 0) { addr_set_port(&real_local_addr, response_port); - } + } if (addr_bind(udp_fd, &real_local_addr,0,1,UDP_SOCKET) < 0) { err(-1, NULL); } @@ -472,15 +472,15 @@ int main(int argc, char **argv) run_stunclient(&remote_addr, &reflexive_addr, &other_addr, &local_port, &rfc5780,-1,0,0,0); if(addr_eq(&tmp_addr,&reflexive_addr)){ - discoveryresult("NAT with Enpoint Independent Mapping!"); + discoveryresult("NAT with Endpoint Independent Mapping!"); } else { addr_cpy(&tmp_addr, &reflexive_addr); addr_cpy(&remote_addr, &other_addr); run_stunclient(&remote_addr, &reflexive_addr, &other_addr, &local_port, &rfc5780,-1,0,0,0); if(addr_eq(&tmp_addr,&reflexive_addr)){ - discoveryresult("NAT with Address Dependent Mapping!"); + discoveryresult("NAT with Address Dependent Mapping!"); } else { - discoveryresult("NAT with Address and Port Dependent Mapping!"); + discoveryresult("NAT with Address and Port Dependent Mapping!"); } }; @@ -500,14 +500,14 @@ int main(int argc, char **argv) int res=0; res=run_stunclient(&remote_addr, &reflexive_addr, &other_addr, &local_port, &rfc5780,-1,1,1,0); if (!res) { - discoveryresult("NAT with Enpoint Independent Filtering!"); + discoveryresult("NAT with Endpoint Independent Filtering!"); } else { res=0; res=run_stunclient(&remote_addr, &reflexive_addr, &other_addr, &local_port, &rfc5780,-1,0,1,0); if(!res){ - discoveryresult("NAT with Address Dependent Filtering!"); + discoveryresult("NAT with Address Dependent Filtering!"); } else { - discoveryresult("NAT with Address and Port Dependent Filtering!"); + discoveryresult("NAT with Address and Port Dependent Filtering!"); } }; From 256266c757d0d663d887636ace9b5e2a262f10be Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?M=C3=A9sz=C3=A1ros=20Mih=C3=A1ly?= Date: Mon, 4 Sep 2017 14:37:09 +0200 Subject: [PATCH 3/3] Preserve STUN server IP:port during the map/filter tests even if FQDN is used --- src/apps/natdiscovery/natdiscovery.c | 19 +++++++++++-------- 1 file changed, 11 insertions(+), 8 deletions(-) diff --git a/src/apps/natdiscovery/natdiscovery.c b/src/apps/natdiscovery/natdiscovery.c index c28650a..28c225c 100644 --- a/src/apps/natdiscovery/natdiscovery.c +++ b/src/apps/natdiscovery/natdiscovery.c @@ -399,9 +399,11 @@ static void init(ioa_addr *real_local_addr,ioa_addr *remote_addr,int *local_port *local_port = -1; *rfc5780 = 0; - - if (make_ioa_addr((const u08bits*)remote_param, port, remote_addr) < 0) + if (addr_any(remote_addr)){ + if (make_ioa_addr((const u08bits*)remote_param, port, remote_addr) < 0) { err(-1, NULL); + } + } } static void discoveryresult(const char *decision){ @@ -418,7 +420,7 @@ int main(int argc, char **argv) int mapping = 0; int filtering = 0; int local_port, rfc5780; - ioa_addr other_addr, reflexive_addr, tmp_addr, remote_addr; + ioa_addr other_addr, reflexive_addr, tmp_addr, remote_addr, remote_tmp_addr; set_logfile("stdout"); @@ -426,6 +428,7 @@ int main(int argc, char **argv) ns_bzero(local_addr, sizeof(local_addr)); addr_set_any(&remote_addr); + addr_set_any(&remote_tmp_addr); addr_set_any(&other_addr); addr_set_any(&reflexive_addr); addr_set_any(&tmp_addr); @@ -466,17 +469,17 @@ int main(int argc, char **argv) if(!addr_any(&other_addr)){ addr_cpy(&tmp_addr, &reflexive_addr); - addr_cpy(&remote_addr, &other_addr); - addr_set_port(&remote_addr, port); + addr_cpy(&remote_tmp_addr, &other_addr); + addr_set_port(&remote_tmp_addr, port); - run_stunclient(&remote_addr, &reflexive_addr, &other_addr, &local_port, &rfc5780,-1,0,0,0); + run_stunclient(&remote_tmp_addr, &reflexive_addr, &other_addr, &local_port, &rfc5780,-1,0,0,0); if(addr_eq(&tmp_addr,&reflexive_addr)){ discoveryresult("NAT with Endpoint Independent Mapping!"); } else { addr_cpy(&tmp_addr, &reflexive_addr); - addr_cpy(&remote_addr, &other_addr); - run_stunclient(&remote_addr, &reflexive_addr, &other_addr, &local_port, &rfc5780,-1,0,0,0); + addr_cpy(&remote_tmp_addr, &other_addr); + run_stunclient(&remote_tmp_addr, &reflexive_addr, &other_addr, &local_port, &rfc5780,-1,0,0,0); if(addr_eq(&tmp_addr,&reflexive_addr)){ discoveryresult("NAT with Address Dependent Mapping!"); } else {