{
struct interface *ifp;
unsigned long long opts;
- int opt, oi, do_reboot, do_renew, af = AF_UNSPEC;
+ int opt, oi, oifind, do_reboot, do_renew, af = AF_UNSPEC;
size_t len, l, nifaces;
char *tmp, *p;
return control_queue(fd, UNCONST(fd->ctx->cffile),
strlen(fd->ctx->cffile) + 1);
} else if (strcmp(*argv, "--getinterfaces") == 0) {
- optind = argc = 0;
+ oifind = argc = 0;
goto dumplease;
} else if (strcmp(*argv, "--listen") == 0) {
fd->flags |= FD_LISTEN;
}
}
+ /* store the index; the optind will change when a getopt get called */
+ oifind = optind;
+
if (opts & DHCPCD_DUMPLEASE) {
ctx->options |= DHCPCD_DUMPLEASE;
dumplease:
TAILQ_FOREACH(ifp, ctx->ifaces, next) {
if (!ifp->active)
continue;
- for (oi = optind; oi < argc; oi++) {
+ for (oi = oifind; oi < argc; oi++) {
if (strcmp(ifp->name, argv[oi]) == 0)
break;
}
- if (optind == argc || oi < argc) {
+ if (oifind == argc || oi < argc) {
opt = send_interface(NULL, ifp, af);
if (opt == -1)
goto dumperr;
TAILQ_FOREACH(ifp, ctx->ifaces, next) {
if (!ifp->active)
continue;
- for (oi = optind; oi < argc; oi++) {
+ for (oi = oifind; oi < argc; oi++) {
if (strcmp(ifp->name, argv[oi]) == 0)
break;
}
- if (optind == argc || oi < argc) {
+ if (oifind == argc || oi < argc) {
if (send_interface(fd, ifp, af) == -1)
goto dumperr;
}
}
if (opts & (DHCPCD_EXITING | DHCPCD_RELEASE)) {
- if (optind == argc) {
+ if (oifind == argc) {
stop_all_interfaces(ctx, opts);
eloop_exit(ctx->eloop, EXIT_SUCCESS);
return 0;
}
- for (oi = optind; oi < argc; oi++) {
+ for (oi = oifind; oi < argc; oi++) {
if ((ifp = if_find(ctx->ifaces, argv[oi])) == NULL)
continue;
if (!ifp->active)
}
if (do_renew) {
- if (optind == argc) {
+ if (oifind == argc) {
dhcpcd_renew(ctx);
return 0;
}
- for (oi = optind; oi < argc; oi++) {
+ for (oi = oifind; oi < argc; oi++) {
if ((ifp = if_find(ctx->ifaces, argv[oi])) == NULL)
continue;
dhcpcd_ifrenew(ifp);
reload_config(ctx);
/* XXX: Respect initial commandline options? */
- reconf_reboot(ctx, do_reboot, argc, argv, optind - 1);
+ reconf_reboot(ctx, do_reboot, argc, argv, oifind);
return 0;
}