diff options
author | Denis Vlasenko <vda.linux@googlemail.com> | 2006-09-03 12:27:25 +0000 |
---|---|---|
committer | Denis Vlasenko <vda.linux@googlemail.com> | 2006-09-03 12:27:25 +0000 |
commit | 65dbd8752b4b183c11a631792ef2ad07a7f251e4 (patch) | |
tree | c329baa5221e9a09844482c842dc78af7468e312 /networking/zcip.c | |
parent | 60e3dd60160e0a3192fd0f2ed02cf6407ef36ed4 (diff) | |
download | busybox-w32-65dbd8752b4b183c11a631792ef2ad07a7f251e4.tar.gz busybox-w32-65dbd8752b4b183c11a631792ef2ad07a7f251e4.tar.bz2 busybox-w32-65dbd8752b4b183c11a631792ef2ad07a7f251e4.zip |
zcip: getopt -> bb_getopt_ulflags
Diffstat (limited to 'networking/zcip.c')
-rw-r--r-- | networking/zcip.c | 61 |
1 files changed, 24 insertions, 37 deletions
diff --git a/networking/zcip.c b/networking/zcip.c index e781a5882..55d28e563 100644 --- a/networking/zcip.c +++ b/networking/zcip.c | |||
@@ -201,8 +201,6 @@ static unsigned conflicts; // = 0; | |||
201 | static unsigned nprobes; // = 0; | 201 | static unsigned nprobes; // = 0; |
202 | static unsigned nclaims; // = 0; | 202 | static unsigned nclaims; // = 0; |
203 | static int ready; // = 0; | 203 | static int ready; // = 0; |
204 | static int quit; // = 0; | ||
205 | static int foreground; // = 0; | ||
206 | static int verbose; // = 0; | 204 | static int verbose; // = 0; |
207 | static int state = PROBE; | 205 | static int state = PROBE; |
208 | 206 | ||
@@ -211,39 +209,30 @@ int zcip_main(int argc, char *argv[]) | |||
211 | struct ether_addr eth_addr; | 209 | struct ether_addr eth_addr; |
212 | char *why; | 210 | char *why; |
213 | int fd; | 211 | int fd; |
214 | int t; | ||
215 | 212 | ||
216 | // parse commandline: prog [options] ifname script | 213 | // parse commandline: prog [options] ifname script |
217 | while ((t = getopt(argc, argv, "fqr:v")) != EOF) { | 214 | #define FOREGROUND (opts & 1) |
218 | switch (t) { | 215 | #define QUIT (opts & 2) |
219 | case 'f': | 216 | char *r_opt; |
220 | foreground = 1; | 217 | unsigned long opts; |
221 | continue; | 218 | |
222 | case 'q': | 219 | bb_opt_complementally = "vv"; // -v options accumulate |
223 | quit = 1; | 220 | opts = bb_getopt_ulflags(argc, argv, "fqr:v", &r_opt, &verbose); |
224 | continue; | 221 | if (opts & 4) { |
225 | case 'r': | 222 | if (inet_aton(r_opt, &ip) == 0 |
226 | if (inet_aton(optarg, &ip) == 0 | 223 | || (ntohl(ip.s_addr) & IN_CLASSB_NET) != LINKLOCAL_ADDR) { |
227 | || (ntohl(ip.s_addr) & IN_CLASSB_NET) | 224 | bb_error_msg_and_die("invalid link address"); |
228 | != LINKLOCAL_ADDR) { | ||
229 | bb_error_msg_and_die("invalid link address"); | ||
230 | } | ||
231 | continue; | ||
232 | case 'v': | ||
233 | verbose++; | ||
234 | foreground = 1; | ||
235 | continue; | ||
236 | default: | ||
237 | bb_error_msg_and_die("bad option"); | ||
238 | } | 225 | } |
239 | } | 226 | } |
240 | if (optind < argc - 1) { | 227 | if (verbose) opts |= 1; |
241 | intf = argv[optind++]; | 228 | argc -= optind; |
242 | setenv("interface", intf, 1); | 229 | argv += optind; |
243 | script = argv[optind++]; | 230 | if (argc != 2) |
244 | } | ||
245 | if (optind != argc || !intf) | ||
246 | bb_show_usage(); | 231 | bb_show_usage(); |
232 | |||
233 | intf = argv[0]; | ||
234 | script = argv[1]; | ||
235 | setenv("interface", intf, 1); | ||
247 | openlog(bb_applet_name, 0, LOG_DAEMON); | 236 | openlog(bb_applet_name, 0, LOG_DAEMON); |
248 | 237 | ||
249 | // initialize the interface (modprobe, ifup, etc) | 238 | // initialize the interface (modprobe, ifup, etc) |
@@ -257,15 +246,13 @@ int zcip_main(int argc, char *argv[]) | |||
257 | // open an ARP socket | 246 | // open an ARP socket |
258 | fd = xsocket(PF_PACKET, SOCK_PACKET, htons(ETH_P_ARP)); | 247 | fd = xsocket(PF_PACKET, SOCK_PACKET, htons(ETH_P_ARP)); |
259 | // bind to the interface's ARP socket | 248 | // bind to the interface's ARP socket |
260 | xbind(fd, &saddr, sizeof (saddr); | 249 | xbind(fd, &saddr, sizeof (saddr)); |
261 | 250 | ||
262 | // get the interface's ethernet address | 251 | // get the interface's ethernet address |
263 | //memset(&ifr, 0, sizeof (ifr)); | 252 | //memset(&ifr, 0, sizeof (ifr)); |
264 | strncpy(ifr.ifr_name, intf, sizeof (ifr.ifr_name)); | 253 | strncpy(ifr.ifr_name, intf, sizeof (ifr.ifr_name)); |
265 | if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0) { | 254 | if (ioctl(fd, SIOCGIFHWADDR, &ifr) < 0) { |
266 | foreground = 1; | 255 | bb_perror_msg_and_die("get ethernet address"); |
267 | why = "get ethernet address"; | ||
268 | goto bad; | ||
269 | } | 256 | } |
270 | memcpy(ð_addr, &ifr.ifr_hwaddr.sa_data, ETH_ALEN); | 257 | memcpy(ð_addr, &ifr.ifr_hwaddr.sa_data, ETH_ALEN); |
271 | 258 | ||
@@ -283,7 +270,7 @@ int zcip_main(int argc, char *argv[]) | |||
283 | // - link already has local address... just defend/update | 270 | // - link already has local address... just defend/update |
284 | 271 | ||
285 | // daemonize now; don't delay system startup | 272 | // daemonize now; don't delay system startup |
286 | if (!foreground) { | 273 | if (!FOREGROUND) { |
287 | xdaemon(0, verbose); | 274 | xdaemon(0, verbose); |
288 | syslog(LOG_INFO, "start, interface %s", intf); | 275 | syslog(LOG_INFO, "start, interface %s", intf); |
289 | } | 276 | } |
@@ -394,7 +381,7 @@ int zcip_main(int argc, char *argv[]) | |||
394 | 381 | ||
395 | // NOTE: all other exit paths | 382 | // NOTE: all other exit paths |
396 | // should deconfig ... | 383 | // should deconfig ... |
397 | if (quit) | 384 | if (QUIT) |
398 | return EXIT_SUCCESS; | 385 | return EXIT_SUCCESS; |
399 | } | 386 | } |
400 | break; | 387 | break; |
@@ -555,7 +542,7 @@ int zcip_main(int argc, char *argv[]) | |||
555 | } // switch poll | 542 | } // switch poll |
556 | } | 543 | } |
557 | bad: | 544 | bad: |
558 | if (foreground) | 545 | if (FOREGROUND) |
559 | perror(why); | 546 | perror(why); |
560 | else | 547 | else |
561 | syslog(LOG_ERR, "%s %s, %s error: %s", | 548 | syslog(LOG_ERR, "%s %s, %s error: %s", |