"nc" exits silently on errors. This patch makes it print something before
authorEric Andersen <andersen@codepoet.org>
Sun, 4 Jun 2000 05:21:49 +0000 (05:21 -0000)
committerEric Andersen <andersen@codepoet.org>
Sun, 4 Jun 2000 05:21:49 +0000 (05:21 -0000)
exit().

Note that calling perror() after gethostbyname() will most likely return
"No such file or directory" which is quite confusing, so I decided to use
fatalError instead.

Regards,
Pavel Roskin

nc.c
networking/nc.c

diff --git a/nc.c b/nc.c
index a588587fbc37331af01928ad01aa302d4e30a011..a7e48d39bed37cb7507897fdf4c9bb331279f837 100644 (file)
--- a/nc.c
+++ b/nc.c
@@ -69,7 +69,7 @@ int nc_main(int argc, char **argv)
        hostinfo = (struct hostent *) gethostbyname(*argv);
 
        if (!hostinfo) {
-               exit(1);
+               fatalError("nc: cannot resolve %s\n", *argv);
        }
 
        address.sin_family = AF_INET;
@@ -81,6 +81,7 @@ int nc_main(int argc, char **argv)
        result = connect(sfd, (struct sockaddr *) &address, len);
 
        if (result < 0) {
+               perror("nc: connect");
                exit(2);
        }
 
@@ -100,6 +101,7 @@ int nc_main(int argc, char **argv)
                                   (struct timeval *) 0);
 
                if (result < 1) {
+                       perror("nc: select");
                        exit(3);
                }
 
index a588587fbc37331af01928ad01aa302d4e30a011..a7e48d39bed37cb7507897fdf4c9bb331279f837 100644 (file)
@@ -69,7 +69,7 @@ int nc_main(int argc, char **argv)
        hostinfo = (struct hostent *) gethostbyname(*argv);
 
        if (!hostinfo) {
-               exit(1);
+               fatalError("nc: cannot resolve %s\n", *argv);
        }
 
        address.sin_family = AF_INET;
@@ -81,6 +81,7 @@ int nc_main(int argc, char **argv)
        result = connect(sfd, (struct sockaddr *) &address, len);
 
        if (result < 0) {
+               perror("nc: connect");
                exit(2);
        }
 
@@ -100,6 +101,7 @@ int nc_main(int argc, char **argv)
                                   (struct timeval *) 0);
 
                if (result < 1) {
+                       perror("nc: select");
                        exit(3);
                }