Vodz, last_patch_104
[oweals/busybox.git] / networking / hostname.c
index 16de86adbd3bcd7757aa6d3d61b34e6d53cf6406..a00263d8f8db3d3f18dfffb6987321b18e72b53f 100644 (file)
@@ -1,11 +1,11 @@
 /* vi: set sw=4 ts=4: */
 /*
- * $Id: hostname.c,v 1.32 2001/10/31 09:59:57 andersen Exp $
+ * $Id: hostname.c,v 1.36 2003/07/14 21:21:01 andersen Exp $
  * Mini hostname implementation for busybox
  *
  * Copyright (C) 1999 by Randolph Chung <tausq@debian.org>
  *
- * adjusted by Erik Andersen <andersee@debian.org> to remove
+ * adjusted by Erik Andersen <andersen@codepoet.org> to remove
  * use of long options and GNU getopt.  Improved the usage info.
  *
  * This program is free software; you can redistribute it and/or modify
@@ -46,12 +46,12 @@ static void do_sethostname(char *s, int isfile)
        if (!isfile) {
                if (sethostname(s, strlen(s)) < 0) {
                        if (errno == EPERM)
-                               error_msg_and_die("you must be root to change the hostname");
+                               bb_error_msg_and_die("you must be root to change the hostname");
                        else
-                               perror_msg_and_die("sethostname");
+                               bb_perror_msg_and_die("sethostname");
                }
        } else {
-               f = xfopen(s, "r");
+               f = bb_xfopen(s, "r");
                while (fgets(buf, 255, f) != NULL) {
                        if (buf[0] =='#') {
                                continue;
@@ -75,7 +75,7 @@ int hostname_main(int argc, char **argv)
        char *p = NULL;
 
        if (argc < 1)
-               show_usage();
+               bb_show_usage();
 
         while ((opt = getopt(argc, argv, "dfisF:")) > 0) {
                 switch (opt) {
@@ -89,7 +89,7 @@ int hostname_main(int argc, char **argv)
                        filename = optarg;
                        break;
                default:
-                       show_usage();
+                       bb_show_usage();
                }
        }
 
@@ -104,9 +104,9 @@ int hostname_main(int argc, char **argv)
                        if (p != NULL) {
                                *p = 0;
                        }
-                       puts(buf);
+                       puts(hp->h_name);
                } else if (type == 'd') {
-                       puts(p ? p + 1 : "");
+                       if (p) puts(p + 1);
                } else if (type == 'i') {
                        while (hp->h_addr_list[0]) {
                                printf("%s ", inet_ntoa(*(struct in_addr *) (*hp->h_addr_list++)));