- Timestamp:
- May 29, 2015, 7:08:24 PM (10 years ago)
- Location:
- trunk/src
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/sh_calls.c
r412 r472 153 153 reject = 1; 154 154 155 #if defined(USE_IPVX)156 155 if (0 == sh_ipvx_aton(str, &bind_addr)) 157 156 return -1; 158 #else159 if (0 == inet_aton(str, &(bind_addr.sin.sin_addr)))160 return -1;161 #endif162 157 163 158 use_bind_addr = 1; … … 170 165 { 171 166 int error; 167 int err_bind = 0; 172 168 long int val_retry = 0; 173 169 char errbuf[SH_ERRBUF_SIZE]; … … 177 173 errno = 0; 178 174 179 if ( 0 !=use_bind_addr)175 if (use_bind_addr) 180 176 { 181 177 int slen = SH_SS_LEN(bind_addr); 182 183 val_retry = bind(sockfd, sh_ipvx_sockaddr_cast(&bind_addr), slen); 178 struct sockaddr *b_addr = sh_ipvx_sockaddr_cast(&bind_addr); 179 180 if (bind_addr.ss_family == AF_INET) 181 b_addr->sa_family = AF_INET; 182 #if defined(USE_IPVX) 183 else 184 b_addr->sa_family = AF_INET6; 185 #endif 186 val_retry = bind(sockfd, b_addr, slen); 184 187 } 185 188 … … 190 193 } while (val_retry < 0 && (errno == EINTR || errno == EINPROGRESS)); 191 194 } 195 else 196 { 197 err_bind = 1; 198 } 192 199 193 200 error = errno; … … 195 202 long eport; 196 203 char eaddr[SH_IP_BUF]; 197 204 char emesg[SH_BUFSIZE]; 205 struct sockaddr *err_addr = serv_addr; 198 206 struct sh_sockaddr ss; 199 sh_ipvx_save(&ss, serv_addr->sa_family, serv_addr); 207 208 if (err_bind) 209 err_addr = sh_ipvx_sockaddr_cast(&bind_addr); 210 211 sh_ipvx_save(&ss, err_addr->sa_family, err_addr); 200 212 sh_ipvx_ntoa(eaddr, sizeof(eaddr), &ss); 201 213 202 if ( serv_addr->sa_family == AF_INET)214 if (err_addr->sa_family == AF_INET) 203 215 eport = (long) ntohs(((struct sockaddr_in *)serv_addr)->sin_port); 216 #if defined(USE_IPVX) 204 217 else 205 218 eport = (long) ntohs(((struct sockaddr_in6 *)serv_addr)->sin6_port); 206 207 sh_error_handle ((-1), file, line, error, MSG_ERR_CONNECT, 208 sh_error_message(error, errbuf, sizeof(errbuf)), 219 #endif 220 221 sl_strlcpy(emesg, sh_error_message(error, errbuf, sizeof(errbuf)), sizeof(emesg)); 222 sl_strlcat(emesg, 223 (err_addr->sa_family == AF_INET) ? _(", AF_INET") : _(", AF_INET6"), 224 sizeof(emesg)); 225 226 sl_strlcat(emesg, 227 (err_bind) ? _(", bind") : _(", connect"), 228 sizeof(emesg)); 229 230 sh_error_handle ((-1), file, line, error, MSG_ERR_CONNECT, 231 emesg, 209 232 (long) sockfd, eport, eaddr); 210 233 } -
trunk/src/sh_tools.c
r425 r472 93 93 #undef FIL__ 94 94 #define FIL__ _("sh_tools.c") 95 96 static int tools_debug = 0; 95 97 96 98 #ifdef SH_ENCRYPT … … 564 566 SL_ENTER(_("connect_port")); 565 567 568 if (tools_debug) 569 fprintf(stderr, _("-00- <%s> <%d> no IPv6 support\n"), address, port); 570 566 571 if (errsiz > 0) errmsg[0] = '\0'; 567 572 … … 575 580 while (check_cache && check_cache->address) 576 581 { 582 if (tools_debug) 583 fprintf(stderr, _("-01- <%s> <%s>\n"), 584 address, check_cache->address); 585 577 586 if ( 0 == sl_strncmp(check_cache->address, 578 587 address, sl_strlen(address)) ) … … 584 593 break; 585 594 } 595 if (tools_debug) 596 { 597 char eaddr[SH_IP_BUF]; 598 sl_strlcpy(eaddr, 599 inet_ntoa(*(struct in_addr *) &(sinr.sin_addr)), 600 sizeof(eaddr)); 601 fprintf(stderr, _("-02- <AF_INET> <%s> <%d> <%d>\n"), 602 eaddr, 603 port, cached); 604 } 586 605 if (check_cache->next) 587 606 check_cache = check_cache->next; … … 595 614 if (cached == 0) 596 615 { 616 if (tools_debug) 617 fputs(_("-03- not cached\n"), stderr); 597 618 #ifdef HAVE_INET_ATON 598 619 if (0 == inet_aton(address, &haddr)) … … 625 646 sinr.sin_addr = *(struct in_addr *) host_entry->h_addr; 626 647 648 if (tools_debug) 649 fprintf(stderr, 650 _("-04- <%s> <%s> hostent->h_name %s <%s> hostent->h_addr\n"), 651 address, 652 (host_entry->h_name == NULL) ? _("NULL") : host_entry->h_name, 653 (host_entry->h_addrtype == AF_INET) ? _("AF_INET") : _("AF_INET6"), 654 inet_ntoa(*(struct in_addr *) &(sinr.sin_addr))); 627 655 628 656 /* reverse DNS lookup … … 688 716 sinr.sin_port = htons (port); 689 717 sinr.sin_addr = haddr; 718 719 if (tools_debug) 720 fprintf(stderr, 721 _("-04- <%s> is_numeric AF_INET <%s> \n"), 722 address, 723 inet_ntoa(*(struct in_addr *) &(sinr.sin_addr))); 690 724 } 691 725 … … 743 777 *errnum = status; 744 778 sl_strlcpy(errmsg, sh_error_message (status, errbuf, sizeof(errbuf)), errsiz); 779 sl_strlcat(errmsg, 780 (sinr.sin_family == AF_INET) ? _(", AF_INET ") : _(", AF_INET6 "), 781 errsiz); 745 782 sl_strlcat(errmsg, _(", address "), errsiz); 746 783 sl_strlcat(errmsg, address, errsiz); … … 776 813 delete_cache(); 777 814 815 if (tools_debug) 816 fprintf(stderr, _("-00- <%s> <%d>\n"), address, port); 817 778 818 if (check_cache != NULL) 779 819 { 780 820 while (check_cache && check_cache->address) 781 821 { 822 if (tools_debug) 823 fprintf(stderr, _("-01- <%s> <%s>\n"), 824 address, check_cache->address); 825 782 826 if ( 0 == sl_strcmp(check_cache->address, address) ) 783 827 { … … 798 842 break; 799 843 } 844 if (tools_debug) 845 { 846 char eaddr[SH_IP_BUF]; 847 sh_ipvx_ntoa(eaddr, sizeof(eaddr), &ss); 848 fprintf(stderr, _("-02- <%s> <%s> <%d> <%d>\n"), 849 (ss.ss_family == AF_INET) ? _("AF_INET") : _("AF_INET6"), 850 eaddr, 851 port, cached); 852 } 800 853 break; 801 854 } … … 809 862 if (cached != 0) 810 863 { 864 if (tools_debug) 865 fputs(_("-03- cached\n"), stderr); 811 866 fd = socket(ss.ss_family, SOCK_STREAM, 0); 812 867 if (fd < 0) … … 854 909 struct addrinfo hints; 855 910 911 if (tools_debug) 912 fputs(_("-03- not cached\n"), stderr); 913 856 914 memset (&hints, '\0', sizeof (hints)); 857 915 hints.ai_flags = AI_ADDRCONFIG; … … 882 940 const char * canonical; 883 941 942 884 943 #if defined(AI_CANONNAME) 885 944 if (ai->ai_canonname && strlen(ai->ai_canonname) > 0) 886 945 { 887 946 canonical = ai->ai_canonname; 947 if (tools_debug) 948 fprintf(stderr, _("-04- <%s> <%s> ai->ai_canonname\n"), 949 address, canonical); 888 950 } 889 951 else 890 952 { 891 953 canonical = address; 954 if (tools_debug) 955 fprintf(stderr, _("-04- <%s> <%s> defined ai_canonname\n"), 956 address, canonical); 892 957 } 893 958 #else 894 959 canonical = address; 960 if (tools_debug) 961 fprintf(stderr, _("-04- <%s> <%s> not defined ai_canonname\n"), 962 address, canonical); 895 963 #endif 896 964 … … 903 971 if (e == 0) 904 972 { 973 if (tools_debug) 974 { 975 fprintf(stderr, _("-05- <%s> <%s> <%s>\n"), 976 (p->ai_family == AF_INET) ? _("AF_INET") : _("AF_INET6"), 977 sh_ipvx_print_sockaddr (p->ai_addr, p->ai_family), 978 hostname); 979 } 980 905 981 if (sl_strcasecmp(hostname, canonical) == 0) 906 982 { 983 if (tools_debug) 984 fprintf(stderr, _("-06- <%s> <%s> match\n"), 985 hostname, canonical); 907 986 success = 1; 908 987 break; 909 988 } 989 910 990 } 911 991 … … 1418 1498 SH_IS_ASCII(head[5]) && isalpha(head[5]) && 1419 1499 SH_IS_ASCII(head[6]) && isalpha(head[6])) { 1420 fprintf(stderr, "%c %3o %s %5d %c %c %c %c\n", sign,1500 fprintf(stderr, _("%c %3o %s %5d %c %c %c %c\n"), sign, 1421 1501 head[0], code, msg_size, head[3], head[4], head[5], head[6]); 1422 1502 } else { 1423 fprintf(stderr, "%c %3o %s %5d %2X %2X %2X %2X\n", sign,1503 fprintf(stderr, _("%c %3o %s %5d %2X %2X %2X %2X\n"), sign, 1424 1504 head[0], code, msg_size, head[3], head[4], head[5], head[6]); 1425 1505 }
Note:
See TracChangeset
for help on using the changeset viewer.