diff options
author | Eric Andersen <andersen@codepoet.org> | 1999-12-08 04:13:44 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 1999-12-08 04:13:44 +0000 |
commit | d29edf34d6432a310dbb8124cd7963c34d31a69c (patch) | |
tree | e58040170817df14b887524d1498a2ea3487a784 | |
parent | 485b9550fd01eb519fc0d4f4f148af39fe22250e (diff) | |
download | busybox-w32-d29edf34d6432a310dbb8124cd7963c34d31a69c.tar.gz busybox-w32-d29edf34d6432a310dbb8124cd7963c34d31a69c.tar.bz2 busybox-w32-d29edf34d6432a310dbb8124cd7963c34d31a69c.zip |
Stuf
-rw-r--r-- | hostname.c | 70 | ||||
-rw-r--r-- | networking/hostname.c | 70 |
2 files changed, 82 insertions, 58 deletions
diff --git a/hostname.c b/hostname.c index 27f2800d8..3c22cf8c0 100644 --- a/hostname.c +++ b/hostname.c | |||
@@ -1,9 +1,12 @@ | |||
1 | /* | 1 | /* |
2 | * $Id: hostname.c,v 1.1 1999/12/07 23:14:59 andersen Exp $ | 2 | * $Id: hostname.c,v 1.2 1999/12/08 04:13:44 andersen Exp $ |
3 | * Mini hostname implementation for busybox | 3 | * Mini hostname implementation for busybox |
4 | * | 4 | * |
5 | * Copyright (C) 1999 by Randolph Chung <tausq@debian.org> | 5 | * Copyright (C) 1999 by Randolph Chung <tausq@debian.org> |
6 | * | 6 | * |
7 | * adjusted by Erik Andersen <andersee@debian.org> to remove | ||
8 | * use of long options and GNU getopt. Improved the usage info. | ||
9 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | 10 | * This program is free software; you can redistribute it and/or modify |
8 | * it under the terms of the GNU General Public License as published by | 11 | * it under the terms of the GNU General Public License as published by |
9 | * the Free Software Foundation; either version 2 of the License, or | 12 | * the Free Software Foundation; either version 2 of the License, or |
@@ -21,27 +24,21 @@ | |||
21 | 24 | ||
22 | #include "internal.h" | 25 | #include "internal.h" |
23 | #include <errno.h> | 26 | #include <errno.h> |
24 | #include <getopt.h> | ||
25 | #include <arpa/inet.h> | 27 | #include <arpa/inet.h> |
26 | #include <netdb.h> | 28 | #include <netdb.h> |
27 | #include <unistd.h> | 29 | #include <unistd.h> |
28 | #include <stdio.h> | 30 | #include <stdio.h> |
29 | 31 | ||
30 | static const char* hostname_usage = "hostname [OPTION] {hostname | -F file}\n\n" | 32 | static const char* hostname_usage = |
33 | "hostname [OPTION] {hostname | -F file}\n\n" | ||
34 | "Get or set the hostname or DNS domain name. If a hostname is given\n" | ||
35 | "(or a file with the -F parameter), the host name will be set.\n\n" | ||
31 | "Options:\n" | 36 | "Options:\n" |
32 | "\t-s, --short\t\tshort\n" | 37 | "\t-s\t\tShort\n" |
33 | "\t-i, --ip-address\t\taddresses for the hostname\n" | 38 | "\t-i\t\tAddresses for the hostname\n" |
34 | "\t-d, --domain\t\tDNS domain name\n" | 39 | "\t-d\t\tDNS domain name\n" |
35 | "If a hostname is given, or a file is given with the -F parameter, the host\n" | 40 | "\t-F file\tUse FILE to specify the hostname\n"; |
36 | "name will be set\n"; | ||
37 | 41 | ||
38 | static char short_opts[] = "sidF:"; | ||
39 | static const struct option long_opts[] = { | ||
40 | { "short", no_argument, NULL, 's' }, | ||
41 | { "ip-address", no_argument, NULL, 'i' }, | ||
42 | { "domain", no_argument, NULL, 'd' }, | ||
43 | { NULL, 0, NULL, 0 } | ||
44 | }; | ||
45 | 42 | ||
46 | void do_sethostname(char *s, int isfile) | 43 | void do_sethostname(char *s, int isfile) |
47 | { | 44 | { |
@@ -75,11 +72,9 @@ void do_sethostname(char *s, int isfile) | |||
75 | 72 | ||
76 | int hostname_main(int argc, char **argv) | 73 | int hostname_main(int argc, char **argv) |
77 | { | 74 | { |
78 | int c; | ||
79 | int opt_short = 0; | 75 | int opt_short = 0; |
80 | int opt_domain = 0; | 76 | int opt_domain = 0; |
81 | int opt_ip = 0; | 77 | int opt_ip = 0; |
82 | int opt_file = 0; | ||
83 | struct hostent *h; | 78 | struct hostent *h; |
84 | char *filename = NULL; | 79 | char *filename = NULL; |
85 | char buf[255]; | 80 | char buf[255]; |
@@ -87,19 +82,36 @@ int hostname_main(int argc, char **argv) | |||
87 | 82 | ||
88 | if (argc < 1) usage(hostname_usage); | 83 | if (argc < 1) usage(hostname_usage); |
89 | 84 | ||
90 | while ((c = getopt_long(argc, argv, short_opts, long_opts, NULL)) != -1) { | 85 | while (--argc > 0 && **(++argv) == '-') { |
91 | switch (c) { | 86 | while (*(++(*argv))) { |
92 | case 's': opt_short = 1; break; | 87 | switch (**argv) { |
93 | case 'i': opt_ip = 1; break; | 88 | case 's': |
94 | case 'd': opt_domain = 1; break; | 89 | opt_short = 1; |
95 | case 'F': opt_file = 1; filename = optarg; break; | 90 | break; |
96 | default: usage(hostname_usage); | 91 | case 'i': |
97 | } | 92 | opt_ip = 1; |
93 | break; | ||
94 | case 'd': | ||
95 | opt_domain = 1; | ||
96 | break; | ||
97 | case 'F': | ||
98 | filename = optarg; | ||
99 | if (--argc == 0) { | ||
100 | usage(hostname_usage); | ||
101 | } | ||
102 | filename = *(++argv); | ||
103 | break; | ||
104 | default: | ||
105 | usage(hostname_usage); | ||
106 | } | ||
107 | if (filename!=NULL) | ||
108 | break; | ||
109 | } | ||
98 | } | 110 | } |
99 | 111 | ||
100 | if (optind < argc) { | 112 | if (argc >= 1) { |
101 | do_sethostname(argv[optind], 0); | 113 | do_sethostname(*argv, 0); |
102 | } else if (opt_file) { | 114 | } else if (filename!=NULL) { |
103 | do_sethostname(filename, 1); | 115 | do_sethostname(filename, 1); |
104 | } else { | 116 | } else { |
105 | gethostname(buf, 255); | 117 | gethostname(buf, 255); |
@@ -121,6 +133,6 @@ int hostname_main(int argc, char **argv) | |||
121 | printf("%s\n", buf); | 133 | printf("%s\n", buf); |
122 | } | 134 | } |
123 | } | 135 | } |
124 | return 0; | 136 | exit( 0); |
125 | } | 137 | } |
126 | 138 | ||
diff --git a/networking/hostname.c b/networking/hostname.c index 27f2800d8..3c22cf8c0 100644 --- a/networking/hostname.c +++ b/networking/hostname.c | |||
@@ -1,9 +1,12 @@ | |||
1 | /* | 1 | /* |
2 | * $Id: hostname.c,v 1.1 1999/12/07 23:14:59 andersen Exp $ | 2 | * $Id: hostname.c,v 1.2 1999/12/08 04:13:44 andersen Exp $ |
3 | * Mini hostname implementation for busybox | 3 | * Mini hostname implementation for busybox |
4 | * | 4 | * |
5 | * Copyright (C) 1999 by Randolph Chung <tausq@debian.org> | 5 | * Copyright (C) 1999 by Randolph Chung <tausq@debian.org> |
6 | * | 6 | * |
7 | * adjusted by Erik Andersen <andersee@debian.org> to remove | ||
8 | * use of long options and GNU getopt. Improved the usage info. | ||
9 | * | ||
7 | * This program is free software; you can redistribute it and/or modify | 10 | * This program is free software; you can redistribute it and/or modify |
8 | * it under the terms of the GNU General Public License as published by | 11 | * it under the terms of the GNU General Public License as published by |
9 | * the Free Software Foundation; either version 2 of the License, or | 12 | * the Free Software Foundation; either version 2 of the License, or |
@@ -21,27 +24,21 @@ | |||
21 | 24 | ||
22 | #include "internal.h" | 25 | #include "internal.h" |
23 | #include <errno.h> | 26 | #include <errno.h> |
24 | #include <getopt.h> | ||
25 | #include <arpa/inet.h> | 27 | #include <arpa/inet.h> |
26 | #include <netdb.h> | 28 | #include <netdb.h> |
27 | #include <unistd.h> | 29 | #include <unistd.h> |
28 | #include <stdio.h> | 30 | #include <stdio.h> |
29 | 31 | ||
30 | static const char* hostname_usage = "hostname [OPTION] {hostname | -F file}\n\n" | 32 | static const char* hostname_usage = |
33 | "hostname [OPTION] {hostname | -F file}\n\n" | ||
34 | "Get or set the hostname or DNS domain name. If a hostname is given\n" | ||
35 | "(or a file with the -F parameter), the host name will be set.\n\n" | ||
31 | "Options:\n" | 36 | "Options:\n" |
32 | "\t-s, --short\t\tshort\n" | 37 | "\t-s\t\tShort\n" |
33 | "\t-i, --ip-address\t\taddresses for the hostname\n" | 38 | "\t-i\t\tAddresses for the hostname\n" |
34 | "\t-d, --domain\t\tDNS domain name\n" | 39 | "\t-d\t\tDNS domain name\n" |
35 | "If a hostname is given, or a file is given with the -F parameter, the host\n" | 40 | "\t-F file\tUse FILE to specify the hostname\n"; |
36 | "name will be set\n"; | ||
37 | 41 | ||
38 | static char short_opts[] = "sidF:"; | ||
39 | static const struct option long_opts[] = { | ||
40 | { "short", no_argument, NULL, 's' }, | ||
41 | { "ip-address", no_argument, NULL, 'i' }, | ||
42 | { "domain", no_argument, NULL, 'd' }, | ||
43 | { NULL, 0, NULL, 0 } | ||
44 | }; | ||
45 | 42 | ||
46 | void do_sethostname(char *s, int isfile) | 43 | void do_sethostname(char *s, int isfile) |
47 | { | 44 | { |
@@ -75,11 +72,9 @@ void do_sethostname(char *s, int isfile) | |||
75 | 72 | ||
76 | int hostname_main(int argc, char **argv) | 73 | int hostname_main(int argc, char **argv) |
77 | { | 74 | { |
78 | int c; | ||
79 | int opt_short = 0; | 75 | int opt_short = 0; |
80 | int opt_domain = 0; | 76 | int opt_domain = 0; |
81 | int opt_ip = 0; | 77 | int opt_ip = 0; |
82 | int opt_file = 0; | ||
83 | struct hostent *h; | 78 | struct hostent *h; |
84 | char *filename = NULL; | 79 | char *filename = NULL; |
85 | char buf[255]; | 80 | char buf[255]; |
@@ -87,19 +82,36 @@ int hostname_main(int argc, char **argv) | |||
87 | 82 | ||
88 | if (argc < 1) usage(hostname_usage); | 83 | if (argc < 1) usage(hostname_usage); |
89 | 84 | ||
90 | while ((c = getopt_long(argc, argv, short_opts, long_opts, NULL)) != -1) { | 85 | while (--argc > 0 && **(++argv) == '-') { |
91 | switch (c) { | 86 | while (*(++(*argv))) { |
92 | case 's': opt_short = 1; break; | 87 | switch (**argv) { |
93 | case 'i': opt_ip = 1; break; | 88 | case 's': |
94 | case 'd': opt_domain = 1; break; | 89 | opt_short = 1; |
95 | case 'F': opt_file = 1; filename = optarg; break; | 90 | break; |
96 | default: usage(hostname_usage); | 91 | case 'i': |
97 | } | 92 | opt_ip = 1; |
93 | break; | ||
94 | case 'd': | ||
95 | opt_domain = 1; | ||
96 | break; | ||
97 | case 'F': | ||
98 | filename = optarg; | ||
99 | if (--argc == 0) { | ||
100 | usage(hostname_usage); | ||
101 | } | ||
102 | filename = *(++argv); | ||
103 | break; | ||
104 | default: | ||
105 | usage(hostname_usage); | ||
106 | } | ||
107 | if (filename!=NULL) | ||
108 | break; | ||
109 | } | ||
98 | } | 110 | } |
99 | 111 | ||
100 | if (optind < argc) { | 112 | if (argc >= 1) { |
101 | do_sethostname(argv[optind], 0); | 113 | do_sethostname(*argv, 0); |
102 | } else if (opt_file) { | 114 | } else if (filename!=NULL) { |
103 | do_sethostname(filename, 1); | 115 | do_sethostname(filename, 1); |
104 | } else { | 116 | } else { |
105 | gethostname(buf, 255); | 117 | gethostname(buf, 255); |
@@ -121,6 +133,6 @@ int hostname_main(int argc, char **argv) | |||
121 | printf("%s\n", buf); | 133 | printf("%s\n", buf); |
122 | } | 134 | } |
123 | } | 135 | } |
124 | return 0; | 136 | exit( 0); |
125 | } | 137 | } |
126 | 138 | ||