@@ -174,7 +174,7 @@ static struct s_server {
174
174
175
175
} is_server [MAX_IS_HOSTS ];
176
176
177
- int num_is_servers = 0 ; // Number of element used above for CWOP mode.
177
+ static int num_is_servers = 0 ; // Number of elements used above for CWOP mode.
178
178
// Should be 1 for normal ham APRS-IS.
179
179
180
180
@@ -371,6 +371,7 @@ int igate_get_dnl_cnt (void) {
371
371
* 1 plus packets sent TO server or why not.
372
372
* 2 plus duplicate detection overview.
373
373
* 3 plus duplicate detection details.
374
+ * 4 plus DNS details.
374
375
*
375
376
* Description: Originally: This starts two threads:
376
377
*
@@ -572,21 +573,20 @@ static void setup_cwop_connect_threads(void)
572
573
freeaddrinfo (ai_head );
573
574
}
574
575
575
- # if DEBUG_DNS
576
- text_color_set (DW_COLOR_DEBUG );
577
- dw_printf ("cwop getaddrinfo returns:\n" );
578
- #endif
576
+ if ( s_debug >= 4 ) {
577
+ text_color_set (DW_COLOR_DEBUG );
578
+ dw_printf ("cwop getaddrinfo returns:\n" );
579
+ }
579
580
num_is_servers = 0 ;
580
581
for (ai = ai_head ; ai != NULL ; ai = ai -> ai_next ) {
581
- #if DEBUG_DNS
582
- text_color_set (DW_COLOR_DEBUG );
583
582
dwsock_ia_to_text (ai -> ai_family , ai -> ai_addr ,
584
583
is_server [num_is_servers ].ipaddr_str ,
585
584
sizeof (is_server [num_is_servers ].ipaddr_str ));
586
585
strlcpy (is_server [num_is_servers ].server_port_str , server_port_str ,
587
586
sizeof (is_server [num_is_servers ].server_port_str ));
588
- dw_printf (" %s\n" , is_server [num_is_servers ].ipaddr_str );
589
- #endif
587
+ if (s_debug >= 4 ) {
588
+ dw_printf (" [%d] %s\n" , num_is_servers , is_server [num_is_servers ].ipaddr_str );
589
+ }
590
590
591
591
// Don't run off end if too many.
592
592
if (num_is_servers < MAX_IS_HOSTS ) num_is_servers ++ ;
@@ -757,17 +757,17 @@ static void * connnect_thread_aprs (void *arg)
757
757
continue ;
758
758
}
759
759
760
- # if DEBUG_DNS
761
- text_color_set (DW_COLOR_DEBUG );
762
- dw_printf ("getaddrinfo returns:\n" );
763
- #endif
760
+ if ( s_debug >= 4 ) {
761
+ text_color_set (DW_COLOR_DEBUG );
762
+ dw_printf ("getaddrinfo returns:\n" );
763
+ }
764
764
num_hosts = 0 ;
765
765
for (ai = ai_head ; ai != NULL ; ai = ai -> ai_next ) {
766
- # if DEBUG_DNS
767
- text_color_set (DW_COLOR_DEBUG );
768
- dwsock_ia_to_text (ai -> ai_family , ai -> ai_addr , ipaddr_str , sizeof (ipaddr_str ));
769
- dw_printf (" % s\n" , ipaddr_str );
770
- #endif
766
+ if ( s_debug >= 4 ) {
767
+ text_color_set (DW_COLOR_DEBUG );
768
+ dwsock_ia_to_text (ai -> ai_family , ai -> ai_addr , ipaddr_str , sizeof (ipaddr_str ));
769
+ dw_printf (" [%d] % s\n" , num_hosts , ipaddr_str );
770
+ }
771
771
hosts [num_hosts ] = ai ;
772
772
if (num_hosts < MAX_IS_HOSTS ) num_hosts ++ ;
773
773
}
@@ -780,14 +780,14 @@ static void * connnect_thread_aprs (void *arg)
780
780
781
781
shuffle (hosts , num_hosts );
782
782
783
- #if DEBUG_DNS
784
- text_color_set (DW_COLOR_DEBUG );
785
- dw_printf ("after shuffling:\n" );
786
- for (n = 0 ; n < num_hosts ; n ++ ) {
787
- dwsock_ia_to_text (hosts [n ]-> ai_family , hosts [n ]-> ai_addr , ipaddr_str , sizeof (ipaddr_str ));
788
- dw_printf (" %s\n" , ipaddr_str );
783
+ if (s_debug >= 4 ) {
784
+ text_color_set (DW_COLOR_DEBUG );
785
+ dw_printf ("after shuffling:\n" );
786
+ for (n = 0 ; n < num_hosts ; n ++ ) {
787
+ dwsock_ia_to_text (hosts [n ]-> ai_family , hosts [n ]-> ai_addr , ipaddr_str , sizeof (ipaddr_str ));
788
+ dw_printf (" [%d] %s\n" , n , ipaddr_str );
789
+ }
789
790
}
790
- #endif
791
791
792
792
// Try each address until we find one that is successful.
793
793
@@ -822,7 +822,8 @@ static void * connnect_thread_aprs (void *arg)
822
822
}
823
823
#endif
824
824
825
- #ifndef DEBUG_DNS
825
+ //#ifndef DEBUG_DNS
826
+ #if 1
826
827
err = connect (is , ai -> ai_addr , (int )ai -> ai_addrlen );
827
828
#if __WIN32__
828
829
if (err == SOCKET_ERROR ) {
@@ -1670,7 +1671,7 @@ static int get1ch (int my_server_index)
1670
1671
1671
1672
n = SOCK_RECV (is_server [my_server_index ].igate_sock , (char * )(& ch ), 1 );
1672
1673
1673
- if (n == 1 ) {
1674
+ if (n == 1 ) { // Success
1674
1675
#if DEBUG9
1675
1676
dw_printf (log_fp , "%02x %c %c" , ch ,
1676
1677
isprint (ch ) ? ch : '.' ,
@@ -1682,8 +1683,19 @@ static int get1ch (int my_server_index)
1682
1683
return (ch );
1683
1684
}
1684
1685
1686
+ // Linux man page: "These calls return the number of bytes received, or -1 if an error occurred
1687
+ // The return value will be 0 when the peer has performed an orderly shutdown.
1688
+
1689
+ // I saw 0 when two different clients were logged in with same callsign-ssid.
1690
+
1685
1691
text_color_set (DW_COLOR_ERROR );
1686
- dw_printf ("\nError reading from IGate server. Closing connection.\n\n" );
1692
+ if (n == 0 ) {
1693
+ dw_printf ("\nServer %s has closed connection.\n\n" ,
1694
+ is_server [my_server_index ].ipaddr_str );
1695
+ }
1696
+ else {
1697
+ dw_printf ("\nError reading from server %s. Closing connection.\n\n" , is_server [my_server_index ].ipaddr_str );
1698
+ }
1687
1699
#if __WIN32__
1688
1700
closesocket (is_server [my_server_index ].igate_sock );
1689
1701
#else
0 commit comments