diff options
| author | Roy Marples <roy@marples.name> | 2009-03-05 16:35:03 +0000 |
|---|---|---|
| committer | Roy Marples <roy@marples.name> | 2009-03-05 16:35:03 +0000 |
| commit | 2f7cb97c9b78099a721cbfe750f1274b7367cfc5 (patch) | |
| tree | 17dd8d1bd57069fcff8993d42e49811801b5a621 /if-options.c | |
| parent | ec080c73f8ef36c70350e1fa309d2ed314adde75 (diff) | |
| download | dhcpcd-2f7cb97c9b78099a721cbfe750f1274b7367cfc5.tar.xz | |
Improve INFORM and STATIC support.
It's now possible to flip between DHCP, INFORM and STATIC on already
running instances.
Diffstat (limited to 'if-options.c')
| -rw-r--r-- | if-options.c | 38 |
1 files changed, 23 insertions, 15 deletions
diff --git a/if-options.c b/if-options.c index 1e4ff981..7e79633a 100644 --- a/if-options.c +++ b/if-options.c @@ -271,8 +271,13 @@ parse_addr(struct in_addr *addr, struct in_addr *net, const char *arg) char *p; int i; - if (arg == NULL || *arg == '\0') + if (arg == NULL || *arg == '\0') { + if (addr != NULL) + addr->s_addr = 0; + if (net != NULL) + net->s_addr = 0; return 0; + } if ((p = strchr(arg, '/')) != NULL) { *p++ = '\0'; if (net != NULL && @@ -282,13 +287,16 @@ parse_addr(struct in_addr *addr, struct in_addr *net, const char *arg) syslog(LOG_ERR, "`%s' is not a valid CIDR", p); return -1; } - } + } + if (addr != NULL && inet_aton(arg, addr) == 0) { syslog(LOG_ERR, "`%s' is not a valid IP address", arg); return -1; } - if (p) + if (p != NULL) *--p = '/'; + else if (net != NULL) + net->s_addr = get_netmask(addr->s_addr); return 0; } @@ -382,23 +390,24 @@ parse_option(struct if_options *ifo, int opt, const char *arg) case 'q': ifo->options |= DHCPCD_QUIET; break; + case 'r': + ifo->options |= DHCPCD_REQUEST; + if (parse_addr(&ifo->req_addr, NULL, arg) != 0) + return -1; + ifo->req_mask.s_addr = 0; + break; case 's': ifo->options |= DHCPCD_INFORM | DHCPCD_PERSISTENT; ifo->options &= ~DHCPCD_ARP; - if (!arg || *arg == '\0') { - ifo->request_address.s_addr = 0; - } else { - if (parse_addr(&ifo->request_address, - &ifo->request_netmask, + if (arg && *arg != '\0') { + if (parse_addr(&ifo->req_addr, &ifo->req_mask, arg) != 0) return -1; + } else { + ifo->req_addr.s_addr = 0; + ifo->req_mask.s_addr = 0; } break; - case 'r': - ifo->options |= DHCPCD_REQUEST; - if (parse_addr(&ifo->request_address, NULL, arg) != 0) - return -1; - break; case 't': ifo->timeout = atoint(arg); if (ifo->timeout < 0) { @@ -559,8 +568,7 @@ parse_option(struct if_options *ifo, int opt, const char *arg) } p++; if (strncmp(arg, "ip_address=", strlen("ip_address=")) == 0) { - if (parse_addr(&ifo->request_address, - &ifo->request_netmask, p) != 0) + if (parse_addr(&ifo->req_addr, &ifo->req_mask, p) != 0) return -1; ifo->options |= DHCPCD_STATIC; |
