diff options
author | Eric Andersen <andersen@codepoet.org> | 2004-04-13 19:25:57 +0000 |
---|---|---|
committer | Eric Andersen <andersen@codepoet.org> | 2004-04-13 19:25:57 +0000 |
commit | a4375047d3da6d4d08f78647f1b5b6b6fc44e5c3 (patch) | |
tree | c4c8cf17b7fc7501f6648f1306db68815888e27b | |
parent | 625da9d61efd68a45bd5613450bcf96862ca8290 (diff) | |
download | busybox-w32-a4375047d3da6d4d08f78647f1b5b6b6fc44e5c3.tar.gz busybox-w32-a4375047d3da6d4d08f78647f1b5b6b6fc44e5c3.tar.bz2 busybox-w32-a4375047d3da6d4d08f78647f1b5b6b6fc44e5c3.zip |
slightly clean the whacked out formatting
-rw-r--r-- | networking/ipcalc.c | 93 |
1 files changed, 47 insertions, 46 deletions
diff --git a/networking/ipcalc.c b/networking/ipcalc.c index d75c883b8..5bf07c675 100644 --- a/networking/ipcalc.c +++ b/networking/ipcalc.c | |||
@@ -44,15 +44,15 @@ static unsigned long get_netmask(unsigned long ipaddr) | |||
44 | static int get_prefix(unsigned long netmask) | 44 | static int get_prefix(unsigned long netmask) |
45 | { | 45 | { |
46 | unsigned long msk = 0x80000000; | 46 | unsigned long msk = 0x80000000; |
47 | int ret = 0; | 47 | int ret = 0; |
48 | 48 | ||
49 | netmask = htonl(netmask); | 49 | netmask = htonl(netmask); |
50 | while(msk) { | 50 | while(msk) { |
51 | if (netmask & msk) | 51 | if (netmask & msk) |
52 | ret++; | 52 | ret++; |
53 | msk >>= 1; | 53 | msk >>= 1; |
54 | } | 54 | } |
55 | return ret; | 55 | return ret; |
56 | } | 56 | } |
57 | #endif | 57 | #endif |
58 | 58 | ||
@@ -81,13 +81,13 @@ int ipcalc_main(int argc, char **argv) | |||
81 | #endif | 81 | #endif |
82 | 82 | ||
83 | static const struct option long_options[] = { | 83 | static const struct option long_options[] = { |
84 | {"netmask", no_argument, NULL, 'm'}, | 84 | {"netmask", no_argument, NULL, 'm'}, |
85 | {"broadcast", no_argument, NULL, 'b'}, | 85 | {"broadcast", no_argument, NULL, 'b'}, |
86 | {"network", no_argument, NULL, 'n'}, | 86 | {"network", no_argument, NULL, 'n'}, |
87 | #ifdef CONFIG_FEATURE_IPCALC_FANCY | 87 | #ifdef CONFIG_FEATURE_IPCALC_FANCY |
88 | {"prefix", no_argument, NULL, 'p'}, | 88 | {"prefix", no_argument, NULL, 'p'}, |
89 | {"hostname", no_argument, NULL, 'h'}, | 89 | {"hostname", no_argument, NULL, 'h'}, |
90 | {"silent", no_argument, NULL, 's'}, | 90 | {"silent", no_argument, NULL, 's'}, |
91 | #endif | 91 | #endif |
92 | {NULL, 0, NULL, 0} | 92 | {NULL, 0, NULL, 0} |
93 | }; | 93 | }; |
@@ -95,10 +95,11 @@ int ipcalc_main(int argc, char **argv) | |||
95 | bb_applet_long_options = long_options; | 95 | bb_applet_long_options = long_options; |
96 | mode = bb_getopt_ulflags(argc, argv, | 96 | mode = bb_getopt_ulflags(argc, argv, |
97 | #ifdef CONFIG_FEATURE_IPCALC_FANCY | 97 | #ifdef CONFIG_FEATURE_IPCALC_FANCY |
98 | "mbnphs"); | 98 | "mbnphs" |
99 | #else | 99 | #else |
100 | "mbn"); | 100 | "mbn" |
101 | #endif | 101 | #endif |
102 | ); | ||
102 | if (mode & (BROADCAST | NETWORK | NETPREFIX)) { | 103 | if (mode & (BROADCAST | NETWORK | NETPREFIX)) { |
103 | if (argc - optind > 2) { | 104 | if (argc - optind > 2) { |
104 | bb_show_usage(); | 105 | bb_show_usage(); |
@@ -110,35 +111,35 @@ int ipcalc_main(int argc, char **argv) | |||
110 | } | 111 | } |
111 | 112 | ||
112 | #ifdef CONFIG_FEATURE_IPCALC_FANCY | 113 | #ifdef CONFIG_FEATURE_IPCALC_FANCY |
113 | prefixstr = ipstr = argv[optind]; | 114 | prefixstr = ipstr = argv[optind]; |
114 | 115 | ||
115 | while(*prefixstr) { | 116 | while(*prefixstr) { |
116 | if (*prefixstr == '/') { | 117 | if (*prefixstr == '/') { |
117 | *prefixstr = (char)0; | 118 | *prefixstr = (char)0; |
118 | prefixstr++; | 119 | prefixstr++; |
119 | if (*prefixstr) { | 120 | if (*prefixstr) { |
120 | unsigned int msk; | 121 | unsigned int msk; |
121 | 122 | ||
122 | if (safe_strtoul(prefixstr, &netprefix) || netprefix > 32) { | 123 | if (safe_strtoul(prefixstr, &netprefix) || netprefix > 32) { |
123 | IPCALC_MSG(bb_error_msg_and_die("bad IP prefix: %s\n", prefixstr), | 124 | IPCALC_MSG(bb_error_msg_and_die("bad IP prefix: %s\n", prefixstr), |
124 | exit(EXIT_FAILURE)); | 125 | exit(EXIT_FAILURE)); |
125 | } | 126 | } |
126 | netmask = 0; | 127 | netmask = 0; |
127 | msk = 0x80000000; | 128 | msk = 0x80000000; |
128 | while (netprefix > 0) { | 129 | while (netprefix > 0) { |
129 | netmask |= msk; | 130 | netmask |= msk; |
130 | msk >>= 1; | 131 | msk >>= 1; |
131 | netprefix--; | 132 | netprefix--; |
132 | } | 133 | } |
133 | netmask = htonl(netmask); | 134 | netmask = htonl(netmask); |
134 | /* Even if it was 0, we will signify that we have a netmask. This allows */ | 135 | /* Even if it was 0, we will signify that we have a netmask. This allows */ |
135 | /* for specification of default routes, etc which have a 0 netmask/prefix */ | 136 | /* for specification of default routes, etc which have a 0 netmask/prefix */ |
136 | have_netmask = 1; | 137 | have_netmask = 1; |
137 | } | 138 | } |
138 | break; | 139 | break; |
139 | } | 140 | } |
140 | prefixstr++; | 141 | prefixstr++; |
141 | } | 142 | } |
142 | ipaddr = inet_aton(ipstr, &a); | 143 | ipaddr = inet_aton(ipstr, &a); |
143 | #else | 144 | #else |
144 | ipaddr = inet_aton(argv[optind], &a); | 145 | ipaddr = inet_aton(argv[optind], &a); |
@@ -146,31 +147,31 @@ int ipcalc_main(int argc, char **argv) | |||
146 | 147 | ||
147 | if (ipaddr == 0) { | 148 | if (ipaddr == 0) { |
148 | IPCALC_MSG(bb_error_msg_and_die("bad IP address: %s", argv[optind]), | 149 | IPCALC_MSG(bb_error_msg_and_die("bad IP address: %s", argv[optind]), |
149 | exit(EXIT_FAILURE)); | 150 | exit(EXIT_FAILURE)); |
150 | } | 151 | } |
151 | ipaddr = a.s_addr; | 152 | ipaddr = a.s_addr; |
152 | 153 | ||
153 | if (argc - optind == 2) { | 154 | if (argc - optind == 2) { |
154 | #ifdef CONFIG_FEATURE_IPCALC_FANCY | 155 | #ifdef CONFIG_FEATURE_IPCALC_FANCY |
155 | if (have_netmask) { | 156 | if (have_netmask) { |
156 | IPCALC_MSG(bb_error_msg_and_die("Both prefix and netmask were specified, use one or the other.\n"), | 157 | IPCALC_MSG(bb_error_msg_and_die("Both prefix and netmask were specified, use one or the other.\n"), |
157 | exit(EXIT_FAILURE)); | 158 | exit(EXIT_FAILURE)); |
158 | } | 159 | } |
159 | 160 | ||
160 | #endif | 161 | #endif |
161 | netmask = inet_aton(argv[optind + 1], &a); | 162 | netmask = inet_aton(argv[optind + 1], &a); |
162 | if (netmask == 0) { | 163 | if (netmask == 0) { |
163 | IPCALC_MSG(bb_error_msg_and_die("bad netmask: %s", argv[optind + 1]), | 164 | IPCALC_MSG(bb_error_msg_and_die("bad netmask: %s", argv[optind + 1]), |
164 | exit(EXIT_FAILURE)); | 165 | exit(EXIT_FAILURE)); |
165 | } | 166 | } |
166 | netmask = a.s_addr; | 167 | netmask = a.s_addr; |
167 | } else { | 168 | } else { |
168 | #ifdef CONFIG_FEATURE_IPCALC_FANCY | 169 | #ifdef CONFIG_FEATURE_IPCALC_FANCY |
169 | 170 | ||
170 | if (!have_netmask) | 171 | if (!have_netmask) |
171 | #endif | 172 | #endif |
172 | /* JHC - If the netmask wasn't provided then calculate it */ | 173 | /* JHC - If the netmask wasn't provided then calculate it */ |
173 | netmask = get_netmask(ipaddr); | 174 | netmask = get_netmask(ipaddr); |
174 | } | 175 | } |
175 | 176 | ||
176 | if (mode & NETMASK) { | 177 | if (mode & NETMASK) { |
@@ -188,9 +189,9 @@ int ipcalc_main(int argc, char **argv) | |||
188 | } | 189 | } |
189 | 190 | ||
190 | #ifdef CONFIG_FEATURE_IPCALC_FANCY | 191 | #ifdef CONFIG_FEATURE_IPCALC_FANCY |
191 | if (mode & NETPREFIX) { | 192 | if (mode & NETPREFIX) { |
192 | printf("PREFIX=%i\n", get_prefix(netmask)); | 193 | printf("PREFIX=%i\n", get_prefix(netmask)); |
193 | } | 194 | } |
194 | 195 | ||
195 | if (mode & HOSTNAME) { | 196 | if (mode & HOSTNAME) { |
196 | struct hostent *hostinfo; | 197 | struct hostent *hostinfo; |
@@ -199,7 +200,7 @@ int ipcalc_main(int argc, char **argv) | |||
199 | hostinfo = gethostbyaddr((char *) &ipaddr, sizeof(ipaddr), AF_INET); | 200 | hostinfo = gethostbyaddr((char *) &ipaddr, sizeof(ipaddr), AF_INET); |
200 | if (!hostinfo) { | 201 | if (!hostinfo) { |
201 | IPCALC_MSG(bb_herror_msg_and_die( | 202 | IPCALC_MSG(bb_herror_msg_and_die( |
202 | "cannot find hostname for %s", argv[optind]),); | 203 | "cannot find hostname for %s", argv[optind]),); |
203 | exit(EXIT_FAILURE); | 204 | exit(EXIT_FAILURE); |
204 | } | 205 | } |
205 | for (x = 0; hostinfo->h_name[x]; x++) { | 206 | for (x = 0; hostinfo->h_name[x]; x++) { |