Some more patchelttes from Larry Doolittle.
[oweals/busybox.git] / hostname.c
index ce17ba91cb751a301cadbf7ce3d5dc099ee01b7f..75e4d2e574e9cc635dca8112f745e33badf1af05 100644 (file)
@@ -1,6 +1,6 @@
 /* vi: set sw=4 ts=4: */
 /*
- * $Id: hostname.c,v 1.23 2001/02/01 16:49:29 kraai Exp $
+ * $Id: hostname.c,v 1.28 2001/05/16 15:40:48 kraai Exp $
  * Mini hostname implementation for busybox
  *
  * Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
@@ -30,8 +30,9 @@
 #include <unistd.h>
 #include <string.h>
 #include <stdio.h>
+#include <stdlib.h>
 
-void do_sethostname(char *s, int isfile)
+static void do_sethostname(char *s, int isfile)
 {
        FILE *f;
        char buf[255];
@@ -66,7 +67,7 @@ int hostname_main(int argc, char **argv)
        char *s = NULL;
 
        if (argc < 1)
-               usage(hostname_usage);
+               show_usage();
 
        while (--argc > 0 && **(++argv) == '-') {
                while (*(++(*argv))) {
@@ -82,18 +83,18 @@ int hostname_main(int argc, char **argv)
                                break;
                        case 'F':
                                if (--argc == 0) {
-                                       usage(hostname_usage);
+                                       show_usage();
                                }
                                filename = *(++argv);
                                break;
                        case '-':
                                if (strcmp(++(*argv), "file") || --argc ==0 ) {
-                                       usage(hostname_usage);
+                                       show_usage();
                                }
                                filename = *(++argv);
                                break;
                        default:
-                               usage(hostname_usage);
+                               show_usage();
                        }
                        if (filename != NULL)
                                break;
@@ -111,19 +112,15 @@ int hostname_main(int argc, char **argv)
                        if (!s)
                                s = buf;
                        *s = 0;
-                       printf("%s\n", buf);
+                       puts(buf);
                } else if (opt_domain) {
                        s = strchr(buf, '.');
-                       printf("%s\n", (s ? s + 1 : ""));
+                       puts(s ? s + 1 : "");
                } else if (opt_ip) {
-                       h = gethostbyname(buf);
-                       if (!h) {
-                               printf("Host not found\n");
-                               exit(1);
-                       }
-                       printf("%s\n", inet_ntoa(*(struct in_addr *) (h->h_addr)));
+                       h = xgethostbyname(buf);
+                       puts(inet_ntoa(*(struct in_addr *) (h->h_addr)));
                } else {
-                       printf("%s\n", buf);
+                       puts(buf);
                }
        }
        return(0);