aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
-rw-r--r--networking/hostname.c32
1 files changed, 15 insertions, 17 deletions
diff --git a/networking/hostname.c b/networking/hostname.c
index 4fe28d740..6975b2b30 100644
--- a/networking/hostname.c
+++ b/networking/hostname.c
@@ -18,29 +18,27 @@
18static void do_sethostname(char *s, int isfile) 18static void do_sethostname(char *s, int isfile)
19{ 19{
20 FILE *f; 20 FILE *f;
21 char buf[256];
22 21
23 if (!s) 22 if (!s)
24 return; 23 return;
25 if (!isfile) { 24 if (!isfile) {
26 if (sethostname(s, strlen(s)) < 0) { 25 if (sethostname(s, strlen(s)) < 0) {
27 if (errno == EPERM) 26 if (errno == EPERM)
28 bb_error_msg_and_die("you must be root to change the hostname"); 27 bb_error_msg_and_die(bb_msg_perm_denied_are_you_root);
29 else 28 else
30 bb_perror_msg_and_die("sethostname"); 29 bb_perror_msg_and_die("sethostname");
31 } 30 }
32 } else { 31 } else {
33 f = xfopen(s, "r"); 32 f = xfopen(s, "r");
34 while (fgets(buf, sizeof(buf), f) != NULL) { 33 while (fgets(bb_common_bufsiz1, sizeof(bb_common_bufsiz1), f) != NULL) {
35 if (buf[0] =='#') { 34 if (bb_common_bufsiz1[0] == '#') {
36 continue; 35 continue;
37 } 36 }
38 chomp(buf); 37 chomp(bb_common_bufsiz1);
39 do_sethostname(buf, 0); 38 do_sethostname(bb_common_bufsiz1, 0);
40 } 39 }
41#ifdef CONFIG_FEATURE_CLEAN_UP 40 if (ENABLE_FEATURE_CLEAN_UP)
42 fclose(f); 41 fclose(f);
43#endif
44 } 42 }
45} 43}
46 44
@@ -55,31 +53,31 @@ int hostname_main(int argc, char **argv)
55 }; 53 };
56 54
57 char buf[256]; 55 char buf[256];
58 unsigned opt;
59 char *hostname_str = NULL; 56 char *hostname_str = NULL;
60 57
61 if (argc < 1) 58 if (argc < 1)
62 bb_show_usage(); 59 bb_show_usage();
63 60
64 opt = getopt32(argc, argv, "dfisF:", &hostname_str); 61 getopt32(argc, argv, "dfisF:", &hostname_str);
65 62
66 /* Output in desired format */ 63 /* Output in desired format */
67 if (opt & OPT_dfis) { 64 if (option_mask32 & OPT_dfis) {
68 struct hostent *hp; 65 struct hostent *hp;
69 char *p; 66 char *p;
70 gethostname(buf, sizeof(buf)); 67 gethostname(buf, sizeof(buf));
71 hp = xgethostbyname(buf); 68 hp = xgethostbyname(buf);
72 p = strchr(hp->h_name, '.'); 69 p = strchr(hp->h_name, '.');
73 if (opt & OPT_f) { 70 if (option_mask32 & OPT_f) {
74 puts(hp->h_name); 71 puts(hp->h_name);
75 } else if (opt & OPT_s) { 72 } else if (option_mask32 & OPT_s) {
76 if (p != NULL) { 73 if (p != NULL) {
77 *p = 0; 74 *p = 0;
78 } 75 }
79 puts(hp->h_name); 76 puts(hp->h_name);
80 } else if (opt & OPT_d) { 77 } else if (option_mask32 & OPT_d) {
81 if (p) puts(p + 1); 78 if (p)
82 } else if (opt & OPT_i) { 79 puts(p + 1);
80 } else if (option_mask32 & OPT_i) {
83 while (hp->h_addr_list[0]) { 81 while (hp->h_addr_list[0]) {
84 printf("%s ", inet_ntoa(*(struct in_addr *) (*hp->h_addr_list++))); 82 printf("%s ", inet_ntoa(*(struct in_addr *) (*hp->h_addr_list++)));
85 } 83 }