Allow command line option to select port number
authorJohn Carr <jfc@mit.edu>
Wed, 8 Apr 1992 15:44:47 +0000 (15:44 +0000)
committerJohn Carr <jfc@mit.edu>
Wed, 8 Apr 1992 15:44:47 +0000 (15:44 +0000)
git-svn-id: svn://anonsvn.mit.edu/krb5/trunk@2274 dc483132-0cff-0310-8789-dd5450dbe970

src/appl/sample/sclient/sclient.c

index 9bb015af66d8d36eabcb3ef2fed4b9eab45677ad..b3a243799d63925d37072ba6cd1196aa3e3720c6 100644 (file)
@@ -66,11 +66,11 @@ char *argv[];
     krb5_ap_rep_enc_part *rep_ret;
     short xmitlen;
 
-    if (argc != 2) {
-       fprintf(stderr, "usage: %s <hostname>\n",argv[0]);
+    if (argc != 2 && argc != 3) {
+       fprintf(stderr, "usage: %s <hostname> [port]\n",argv[0]);
        exit(1);
     }
-    
+
     krb5_init_ets();
 
     (void) signal(SIGPIPE, SIG_IGN);
@@ -82,17 +82,22 @@ char *argv[];
     /* clear out the structure first */
     (void) memset((char *)&sin, 0, sizeof(sin));
 
-    /* find the port number for knetd */
-    sp = getservbyname(SAMPLE_SERVICE, "tcp");
-    if (!sp) {
-       fprintf(stderr,
-               "unknown service %s/tcp; check /etc/services\n",
-               SAMPLE_SERVICE);
-       exit(1);
+    if (argc == 3) {
+       sin.sin_family = AF_INET;
+       sin.sin_port = htons(atoi(argv[2]));
+    } else {
+       /* find the port number for knetd */
+       sp = getservbyname(SAMPLE_SERVICE, "tcp");
+       if (!sp) {
+           fprintf(stderr,
+                   "unknown service %s/tcp; check /etc/services\n",
+                   SAMPLE_SERVICE);
+           exit(1);
+       }
+       /* copy the port number */
+       sin.sin_port = sp->s_port;
+       sin.sin_family = AF_INET;
     }
-    /* copy the port number */
-    sin.sin_port = sp->s_port;
-    sin.sin_family = AF_INET;
 
     /* look up the server host */
     hp = gethostbyname(argv[1]);