Develop and Download Open Source Software

Browse Subversion Repository

Diff of /branches/ssh_chacha20poly1305/ttssh2/ttxssh/ttxssh.c

Parent Directory Parent Directory | Revision Log Revision Log | View Patch Patch

revision 6727 by doda, Wed May 17 13:01:26 2017 UTC revision 6738 by maya, Sat May 20 06:38:01 2017 UTC
# Line 53  SOFTWARE, EVEN IF ADVISED OF THE POSSIBI Line 53  SOFTWARE, EVEN IF ADVISED OF THE POSSIBI
53  #include "resource.h"  #include "resource.h"
54  #include <commctrl.h>  #include <commctrl.h>
55  #include <commdlg.h>  #include <commdlg.h>
 #ifndef NO_INET6  
56  #include <winsock2.h>  #include <winsock2.h>
57  static char FAR *ProtocolFamilyList[] = { "UNSPEC", "IPv6", "IPv4", NULL };  static char FAR *ProtocolFamilyList[] = { "UNSPEC", "IPv6", "IPv4", NULL };
 #else  
 #include <winsock.h>  
 #endif                                                  /* NO_INET6 */  
58    
59  #include <Lmcons.h>  #include <Lmcons.h>
60    
# Line 666  static void write_ssh_options(PTInstVar Line 662  static void write_ssh_options(PTInstVar
662  static unsigned short find_local_port(PTInstVar pvar)  static unsigned short find_local_port(PTInstVar pvar)
663  {  {
664          int tries;          int tries;
 #ifndef NO_INET6  
665          SOCKET connecter;          SOCKET connecter;
666          struct addrinfo hints;          struct addrinfo hints;
667          struct addrinfo FAR *res;          struct addrinfo FAR *res;
668          struct addrinfo FAR *res0;          struct addrinfo FAR *res0;
669          unsigned short port;          unsigned short port;
670          char pname[NI_MAXHOST];          char pname[NI_MAXHOST];
 #endif                                                  /* NO_INET6 */  
671    
672          if (pvar->session_settings.DefaultAuthMethod != SSH_AUTH_RHOSTS) {          if (pvar->session_settings.DefaultAuthMethod != SSH_AUTH_RHOSTS) {
673                  return 0;                  return 0;
# Line 686  static unsigned short find_local_port(PT Line 680  static unsigned short find_local_port(PT
680           */           */
681          srand((unsigned) GetTickCount());          srand((unsigned) GetTickCount());
682    
 #ifndef NO_INET6  
683          for (tries = 20; tries > 0; tries--) {          for (tries = 20; tries > 0; tries--) {
684                  memset(&hints, 0, sizeof(hints));                  memset(&hints, 0, sizeof(hints));
685                  hints.ai_family = pvar->ts->ProtocolFamily;                  hints.ai_family = pvar->ts->ProtocolFamily;
# Line 727  static unsigned short find_local_port(PT Line 720  static unsigned short find_local_port(PT
720          }          }
721    
722          return 0;          return 0;
 #else  
         for (tries = 20; tries > 0; tries--) {  
                 SOCKET connecter = socket(AF_INET, SOCK_STREAM, 0);  
                 struct sockaddr_in connecter_addr;  
   
                 connecter_addr.sin_family = AF_INET;  
                 connecter_addr.sin_port = (unsigned) rand() % 512 + 512;  
                 connecter_addr.sin_addr.s_addr = htonl(INADDR_ANY);  
   
                 if (connecter == INVALID_SOCKET) {  
                         return 0;  
                 }  
   
                 if (bind  
                     (connecter, (struct sockaddr FAR *) &connecter_addr,  
                      sizeof(connecter_addr)) != SOCKET_ERROR) {  
                     closesocket(connecter);  
                         return connecter_addr.sin_port;  
                 } else if (WSAGetLastError() != WSAEADDRINUSE) {  
                         closesocket(connecter);  
                         return 0;  
                 }  
   
                 closesocket(connecter);  
         }  
   
         return 0;  
 #endif                                                  /* NO_INET6 */  
723  }  }
724    
725  static int PASCAL FAR TTXconnect(SOCKET s,  static int PASCAL FAR TTXconnect(SOCKET s,
726                                   const struct sockaddr FAR * name,                                   const struct sockaddr FAR * name,
727                                   int namelen)                                   int namelen)
728  {  {
 #ifndef NO_INET6  
729          if (pvar->socket == INVALID_SOCKET || pvar->socket != s) {          if (pvar->socket == INVALID_SOCKET || pvar->socket != s) {
730                  struct sockaddr_storage ss;                  struct sockaddr_storage ss;
731                  int len;                  int len;
# Line 792  static int PASCAL FAR TTXconnect(SOCKET Line 756  static int PASCAL FAR TTXconnect(SOCKET
756    
757                  bind(s, (struct sockaddr FAR *) &ss, len);                  bind(s, (struct sockaddr FAR *) &ss, len);
758          }          }
 #else  
         if (pvar->socket == INVALID_SOCKET) {  
                 struct sockaddr_in addr;  
   
                 pvar->socket = s;  
   
                 addr.sin_family = AF_INET;  
                 addr.sin_port = htons(find_local_port(pvar));  
                 addr.sin_addr.s_addr = INADDR_ANY;  
                 memset(addr.sin_zero, 0, sizeof(addr.sin_zero));  
   
                 bind(s, (struct sockaddr FAR *) &addr, sizeof(addr));  
         }  
 #endif                                                  /* NO_INET6 */  
759    
760          return (pvar->Pconnect) (s, name, namelen);          return (pvar->Pconnect) (s, name, namelen);
761  }  }
# Line 1380  static BOOL CALLBACK TTXHostDlg(HWND dlg Line 1330  static BOOL CALLBACK TTXHostDlg(HWND dlg
1330                                   Telnet ? IDC_HOSTTELNET : IDC_HOSTOTHER);                                   Telnet ? IDC_HOSTTELNET : IDC_HOSTOTHER);
1331                  SendDlgItemMessage(dlg, IDC_HOSTTCPPORT, EM_LIMITTEXT, 5, 0);                  SendDlgItemMessage(dlg, IDC_HOSTTCPPORT, EM_LIMITTEXT, 5, 0);
1332                  SetDlgItemInt(dlg, IDC_HOSTTCPPORT, GetHNRec->TCPPort, FALSE);                  SetDlgItemInt(dlg, IDC_HOSTTCPPORT, GetHNRec->TCPPort, FALSE);
 #ifndef NO_INET6  
1333                  for (i = 0; ProtocolFamilyList[i]; ++i) {                  for (i = 0; ProtocolFamilyList[i]; ++i) {
1334                          SendDlgItemMessage(dlg, IDC_HOSTTCPPROTOCOL, CB_ADDSTRING,                          SendDlgItemMessage(dlg, IDC_HOSTTCPPROTOCOL, CB_ADDSTRING,
1335                                             0, (LPARAM) ProtocolFamilyList[i]);                                             0, (LPARAM) ProtocolFamilyList[i]);
# Line 1388  static BOOL CALLBACK TTXHostDlg(HWND dlg Line 1337  static BOOL CALLBACK TTXHostDlg(HWND dlg
1337                  SendDlgItemMessage(dlg, IDC_HOSTTCPPROTOCOL, EM_LIMITTEXT,                  SendDlgItemMessage(dlg, IDC_HOSTTCPPROTOCOL, EM_LIMITTEXT,
1338                                     ProtocolFamilyMaxLength - 1, 0);                                     ProtocolFamilyMaxLength - 1, 0);
1339                  SendDlgItemMessage(dlg, IDC_HOSTTCPPROTOCOL, CB_SETCURSEL, 0, 0);                  SendDlgItemMessage(dlg, IDC_HOSTTCPPROTOCOL, CB_SETCURSEL, 0, 0);
 #endif                                                  /* NO_INET6 */  
1340    
1341                  /////// SSH version                  /////// SSH version
1342                  for (i = 0; ssh_version[i]; ++i) {                  for (i = 0; ssh_version[i]; ++i) {
# Line 1472  static BOOL CALLBACK TTXHostDlg(HWND dlg Line 1420  static BOOL CALLBACK TTXHostDlg(HWND dlg
1420    
1421                          enable_dlg_items(dlg, IDC_HISTORY, IDC_HISTORY, TRUE); // enabled                          enable_dlg_items(dlg, IDC_HISTORY, IDC_HISTORY, TRUE); // enabled
1422                  }                  }
 #ifndef NO_INET6  
1423                  else {                  else {
1424                          enable_dlg_items(dlg, IDC_HOSTNAMELABEL, IDC_HOSTTCPPORT,                          enable_dlg_items(dlg, IDC_HOSTNAMELABEL, IDC_HOSTTCPPORT,
1425                                           FALSE);                                           FALSE);
# Line 1484  static BOOL CALLBACK TTXHostDlg(HWND dlg Line 1431  static BOOL CALLBACK TTXHostDlg(HWND dlg
1431    
1432                          enable_dlg_items(dlg, IDC_HISTORY, IDC_HISTORY, FALSE); // disabled                          enable_dlg_items(dlg, IDC_HISTORY, IDC_HISTORY, FALSE); // disabled
1433                  }                  }
 #else  
                 else  
                         enable_dlg_items(dlg, IDC_HOSTNAMELABEL, IDC_HOSTTCPPORT,  
                                                          FALSE);  
 #endif                                                  /* NO_INET6 */  
1434    
1435                  // Host dialogにフォーカスをあてる (2004.10.2 yutaka)                  // Host dialogにフォーカスをあてる (2004.10.2 yutaka)
1436                  if (GetHNRec->PortType == IdTCPIP) {                  if (GetHNRec->PortType == IdTCPIP) {
# Line 1539  static BOOL CALLBACK TTXHostDlg(HWND dlg Line 1481  static BOOL CALLBACK TTXHostDlg(HWND dlg
1481                          GetHNRec = (PGetHNRec) GetWindowLong(dlg, DWL_USER);                          GetHNRec = (PGetHNRec) GetWindowLong(dlg, DWL_USER);
1482                          if (GetHNRec != NULL) {                          if (GetHNRec != NULL) {
1483                                  if (IsDlgButtonChecked(dlg, IDC_HOSTTCPIP)) {                                  if (IsDlgButtonChecked(dlg, IDC_HOSTTCPIP)) {
 #ifndef NO_INET6  
1484                                          char afstr[BUFSIZ];                                          char afstr[BUFSIZ];
 #endif                                                  /* NO_INET6 */  
1485                                          i = GetDlgItemInt(dlg, IDC_HOSTTCPPORT, &Ok, FALSE);                                          i = GetDlgItemInt(dlg, IDC_HOSTTCPPORT, &Ok, FALSE);
1486                                          if (Ok) {                                          if (Ok) {
1487                                                  GetHNRec->TCPPort = i;                                                  GetHNRec->TCPPort = i;
# Line 1552  static BOOL CALLBACK TTXHostDlg(HWND dlg Line 1492  static BOOL CALLBACK TTXHostDlg(HWND dlg
1492                                                             "Tera Term", MB_OK | MB_ICONEXCLAMATION);                                                             "Tera Term", MB_OK | MB_ICONEXCLAMATION);
1493                                                  return TRUE;                                                  return TRUE;
1494                                          }                                          }
 #ifndef NO_INET6  
1495  #define getaf(str) \  #define getaf(str) \
1496  ((strcmp((str), "IPv6") == 0) ? AF_INET6 : \  ((strcmp((str), "IPv6") == 0) ? AF_INET6 : \
1497   ((strcmp((str), "IPv4") == 0) ? AF_INET : AF_UNSPEC))   ((strcmp((str), "IPv4") == 0) ? AF_INET : AF_UNSPEC))
# Line 1560  static BOOL CALLBACK TTXHostDlg(HWND dlg Line 1499  static BOOL CALLBACK TTXHostDlg(HWND dlg
1499                                          GetDlgItemText(dlg, IDC_HOSTTCPPROTOCOL, afstr,                                          GetDlgItemText(dlg, IDC_HOSTTCPPROTOCOL, afstr,
1500                                                         sizeof(afstr));                                                         sizeof(afstr));
1501                                          GetHNRec->ProtocolFamily = getaf(afstr);                                          GetHNRec->ProtocolFamily = getaf(afstr);
 #endif                                                  /* NO_INET6 */  
1502                                          GetHNRec->PortType = IdTCPIP;                                          GetHNRec->PortType = IdTCPIP;
1503                                          GetDlgItemText(dlg, IDC_HOSTNAME, GetHNRec->HostName,                                          GetDlgItemText(dlg, IDC_HOSTNAME, GetHNRec->HostName,
1504                                                         HostNameMaxLength);                                                         HostNameMaxLength);
# Line 1628  static BOOL CALLBACK TTXHostDlg(HWND dlg Line 1566  static BOOL CALLBACK TTXHostDlg(HWND dlg
1566                  case IDC_HOSTTCPIP:                  case IDC_HOSTTCPIP:
1567                          enable_dlg_items(dlg, IDC_HOSTNAMELABEL, IDC_HOSTTCPPORT,                          enable_dlg_items(dlg, IDC_HOSTNAMELABEL, IDC_HOSTTCPPORT,
1568                                           TRUE);                                           TRUE);
 #ifndef NO_INET6  
1569                          enable_dlg_items(dlg, IDC_HOSTTCPPROTOCOLLABEL,                          enable_dlg_items(dlg, IDC_HOSTTCPPROTOCOLLABEL,
1570                                           IDC_HOSTTCPPROTOCOL, TRUE);                                           IDC_HOSTTCPPROTOCOL, TRUE);
 #endif                                                  /* NO_INET6 */  
1571                          enable_dlg_items(dlg, IDC_HOSTCOMLABEL, IDC_HOSTCOM, FALSE);                          enable_dlg_items(dlg, IDC_HOSTCOMLABEL, IDC_HOSTCOM, FALSE);
1572    
1573                          enable_dlg_items(dlg, IDC_SSH_VERSION_LABEL, IDC_SSH_VERSION_LABEL, TRUE); // disabled (2004.11.23 yutaka)                          enable_dlg_items(dlg, IDC_SSH_VERSION_LABEL, IDC_SSH_VERSION_LABEL, TRUE); // disabled (2004.11.23 yutaka)
# Line 1649  static BOOL CALLBACK TTXHostDlg(HWND dlg Line 1585  static BOOL CALLBACK TTXHostDlg(HWND dlg
1585                          enable_dlg_items(dlg, IDC_HOSTCOMLABEL, IDC_HOSTCOM, TRUE);                          enable_dlg_items(dlg, IDC_HOSTCOMLABEL, IDC_HOSTCOM, TRUE);
1586                          enable_dlg_items(dlg, IDC_HOSTNAMELABEL, IDC_HOSTTCPPORT,                          enable_dlg_items(dlg, IDC_HOSTNAMELABEL, IDC_HOSTTCPPORT,
1587                                           FALSE);                                           FALSE);
 #ifndef NO_INET6  
1588                          enable_dlg_items(dlg, IDC_HOSTTCPPROTOCOLLABEL,                          enable_dlg_items(dlg, IDC_HOSTTCPPROTOCOLLABEL,
1589                                           IDC_HOSTTCPPROTOCOL, FALSE);                                           IDC_HOSTTCPPROTOCOL, FALSE);
 #endif                                                  /* NO_INET6 */  
1590                          enable_dlg_items(dlg, IDC_SSH_VERSION, IDC_SSH_VERSION, FALSE); // disabled                          enable_dlg_items(dlg, IDC_SSH_VERSION, IDC_SSH_VERSION, FALSE); // disabled
1591                          enable_dlg_items(dlg, IDC_SSH_VERSION_LABEL, IDC_SSH_VERSION_LABEL, FALSE); // disabled (2004.11.23 yutaka)                          enable_dlg_items(dlg, IDC_SSH_VERSION_LABEL, IDC_SSH_VERSION_LABEL, FALSE); // disabled (2004.11.23 yutaka)
1592    
# Line 2108  static void FAR PASCAL TTXParseParam(PCH Line 2042  static void FAR PASCAL TTXParseParam(PCH
2042                          option[hostlen] = 0;                          option[hostlen] = 0;
2043    
2044                          // ポート指定が無い時は":22"を足す                          // ポート指定が無い時は":22"を足す
 #ifndef NO_INET6  
2045                          if (option[0] == '[' && option[hostlen-1] == ']' ||     // IPv6 raw address without port                          if (option[0] == '[' && option[hostlen-1] == ']' ||     // IPv6 raw address without port
2046                              option[0] != '[' && _mbschr(option, ':') == NULL) { // hostname or IPv4 raw address without port                              option[0] != '[' && _mbschr(option, ':') == NULL) { // hostname or IPv4 raw address without port
 #else  
                         if (_mbschr(option, ':') == NULL) {  
 #endif                                                  /* NO_INET6 */  
2047                                  memcpy_s(option+hostlen, optlen-hostlen, ":22", 3);                                  memcpy_s(option+hostlen, optlen-hostlen, ":22", 3);
2048                                  hostlen += 3;                                  hostlen += 3;
2049                          }                          }

Legend:
Removed from v.6727  
changed lines
  Added in v.6738

Back to OSDN">Back to OSDN
ViewVC Help
Powered by ViewVC 1.1.26