Apply `getservbyname' to the Port Number field in case it's
authorsimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Sun, 7 Jan 2001 15:12:20 +0000 (15:12 +0000)
committersimon <simon@cda61777-01e9-0310-a592-d414129be87e>
Sun, 7 Jan 2001 15:12:20 +0000 (15:12 +0000)
non-numeric. Patch due to Christian Biesinger.

git-svn-id: svn://svn.tartarus.org/sgt/putty@839 cda61777-01e9-0310-a592-d414129be87e

windlg.c
window.c

index 0ffe3c9..aa48346 100644 (file)
--- a/windlg.c
+++ b/windlg.c
@@ -598,6 +598,8 @@ static int GenericMainDlgProc (HWND hwnd, UINT msg,
     CHOOSEFONT cf;
     LOGFONT lf;
     char fontstatic[256];
+    char portname[32];
+    struct servent * service;
     int i;
 
     switch (msg) {
@@ -1105,8 +1107,16 @@ static int GenericMainDlgProc (HWND hwnd, UINT msg,
                                sizeof(cfg.host)-1);
            break;
          case IDC_PORT:
-           if (HIWORD(wParam) == EN_CHANGE)
-               MyGetDlgItemInt (hwnd, IDC_PORT, &cfg.port);
+           if (HIWORD(wParam) == EN_CHANGE) {
+               GetDlgItemText (hwnd, IDC_PORT, portname, 31);
+               if (isdigit(portname[0]))
+                   MyGetDlgItemInt (hwnd, IDC_PORT, &cfg.port);
+               else {
+                   service = getservbyname(portname, NULL);
+                   if (service) cfg.port = ntohs(service->s_port);
+                   else cfg.port = 0;
+               }
+           }
            break;
          case IDC_SESSEDIT:
            if (HIWORD(wParam) == EN_CHANGE) {
index 2797c53..46d9f7e 100644 (file)
--- a/window.c
+++ b/window.c
@@ -314,6 +314,14 @@ int WINAPI WinMain(HINSTANCE inst, HINSTANCE prev, LPSTR cmdline, int show) {
         }
     }
 
+    /* Check for invalid Port number (i.e. zero) */
+    if (cfg.port == 0) {
+        MessageBox(NULL, "Invalid Port Number",
+                  "PuTTY Internal Error", MB_OK |MB_ICONEXCLAMATION);
+        WSACleanup();
+        return 1;
+    }
+
     real_ldisc = (cfg.ldisc_term ? &ldisc_term : &ldisc_simple);
     /* To start with, we use the simple line discipline, so we can
      * type passwords etc without fear of them being echoed... */