From: Roy Marples Date: Sat, 26 Apr 2008 07:39:23 +0000 (+0000) Subject: Repair whitespace damage. X-Git-Tag: v4.0.2~446 X-Git-Url: http://git.ipfire.org/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=f409012f02fb430b9684427ab8b298942f185768;p=thirdparty%2Fdhcpcd.git Repair whitespace damage. --- diff --git a/Makefile b/Makefile index 2338ff14..bb542d81 100644 --- a/Makefile +++ b/Makefile @@ -11,7 +11,7 @@ CONF= dhcpcd.conf MAN5= dhcpcd.conf.5 MAN8= dhcpcd.8 dhcpcd.sh.8 -VERSION= 4.0.0-alpha2 +VERSION= 4.0.0-alpha3 CLEANFILES= dhcpcd.sh dhcpcd.8 dhcpcd.sh.8 BINDIR= ${PREFIX}/sbin diff --git a/bpf.c b/bpf.c index da75a315..8dc2c319 100644 --- a/bpf.c +++ b/bpf.c @@ -176,9 +176,9 @@ get_packet(const struct interface *iface, unsigned char *data, bpf.buffer += *buffer_pos; for (; bpf.buffer - buffer < *buffer_len; - bpf.buffer += BPF_WORDALIGN(bpf.packet->bh_hdrlen + - bpf.packet->bh_caplen), - *buffer_pos = bpf.buffer - buffer) + bpf.buffer += BPF_WORDALIGN(bpf.packet->bh_hdrlen + + bpf.packet->bh_caplen), + *buffer_pos = bpf.buffer - buffer) { /* Ensure we have the whole packet */ if (bpf.packet->bh_caplen != bpf.packet->bh_datalen) diff --git a/client.c b/client.c index 9e9ca1d2..483214d3 100644 --- a/client.c +++ b/client.c @@ -219,7 +219,7 @@ daemonise(struct if_state *state, const struct options *options) state->options |= DHCPCD_DAEMONISED; return 0; } - + state->options |= DHCPCD_PERSISTENT | DHCPCD_FORKED; return -1; } @@ -239,7 +239,7 @@ get_duid(unsigned char *duid, const struct interface *iface) unsigned char *p = duid; size_t len = 0; char *line = NULL; - + /* If we already have a DUID then use it as it's never supposed * to change once we have one even if the interfaces do */ if ((f = fopen(DUIDFILE, "r"))) { @@ -262,7 +262,7 @@ get_duid(unsigned char *duid, const struct interface *iface) /* No file? OK, lets make one based on our interface */ if (!(f = fopen(DUIDFILE, "w"))) return 0; - + type = htons(1); /* DUI-D-LLT */ memcpy(p, &type, 2); p += 2; @@ -376,7 +376,7 @@ get_old_lease(struct if_state *state, const struct options *options) (options->options & DHCPCD_LASTLEASE || (options->options & DHCPCD_IPV4LL && IN_LINKLOCAL(ntohl(lease->addr.s_addr)))) && - arp_claim(iface, lease->addr)) + arp_claim(iface, lease->addr)) { lease->addr.s_addr = 0; free(dhcp); @@ -490,7 +490,7 @@ client_setup(struct if_state *state, const struct options *options) if (duid_len > 0) { logger(LOG_INFO, "DUID = %s", hwaddr_ntoa(duid, duid_len)); - + iface->clientid_len = duid_len + 5; iface->clientid = xmalloc(iface->clientid_len); *iface->clientid = 255; /* RFC 4361 */ @@ -509,234 +509,234 @@ client_setup(struct if_state *state, const struct options *options) free(duid); } else { #else - { + { #endif - iface->clientid_len = iface->hwlen + 1; - iface->clientid = xmalloc(iface->clientid_len); - *iface->clientid = iface->family; - memcpy(iface->clientid + 1, iface->hwaddr, iface->hwlen); + iface->clientid_len = iface->hwlen + 1; + iface->clientid = xmalloc(iface->clientid_len); + *iface->clientid = iface->family; + memcpy(iface->clientid + 1, iface->hwaddr, iface->hwlen); + } } - } - /* Remove all existing addresses. - * After all, we ARE a DHCP client whose job it is to configure the - * interface. We only do this on start, so persistent addresses - * can be added afterwards by the user if needed. */ - if (!(options->options & DHCPCD_TEST) && - !(options->options & DHCPCD_DAEMONISED)) - { - if (!(options->options & DHCPCD_INFORM)) { - while (get_address(iface->name, &addr, &net) == 1) { - logger(LOG_DEBUG, "deleting IP address %s/%d", - inet_ntoa(addr), - inet_ntocidr(lease->net)); - if (del_address(iface->name, &addr, &net) == -1) - { - logger(LOG_ERR, "delete_address: %s", - strerror(errno)); - break; - } - } - } else if (has_address(iface->name, - &lease->addr, &lease->net) < 1) + /* Remove all existing addresses. + * After all, we ARE a DHCP client whose job it is to configure the + * interface. We only do this on start, so persistent addresses + * can be added afterwards by the user if needed. */ + if (!(options->options & DHCPCD_TEST) && + !(options->options & DHCPCD_DAEMONISED)) { - /* The inform address HAS to be configured for it to - * work with most DHCP servers */ - /* add_address */ - addr.s_addr = lease->addr.s_addr | ~lease->net.s_addr; - logger(LOG_DEBUG, "adding IP address %s/%d", - inet_ntoa(lease->addr), - inet_ntocidr(lease->net)); - if (add_address(iface->name, &lease->addr, - &lease->net, &addr) == -1) + if (!(options->options & DHCPCD_INFORM)) { + while (get_address(iface->name, &addr, &net) == 1) { + logger(LOG_DEBUG, "deleting IP address %s/%d", + inet_ntoa(addr), + inet_ntocidr(lease->net)); + if (del_address(iface->name, &addr, &net) == -1) + { + logger(LOG_ERR, "delete_address: %s", + strerror(errno)); + break; + } + } + } else if (has_address(iface->name, + &lease->addr, &lease->net) < 1) { - logger(LOG_ERR, "add_address: %s", - strerror(errno)); - return -1; + /* The inform address HAS to be configured for it to + * work with most DHCP servers */ + /* add_address */ + addr.s_addr = lease->addr.s_addr | ~lease->net.s_addr; + logger(LOG_DEBUG, "adding IP address %s/%d", + inet_ntoa(lease->addr), + inet_ntocidr(lease->net)); + if (add_address(iface->name, &lease->addr, + &lease->net, &addr) == -1) + { + logger(LOG_ERR, "add_address: %s", + strerror(errno)); + return -1; + } + iface->addr.s_addr = lease->addr.s_addr; + iface->net.s_addr = lease->net.s_addr; } - iface->addr.s_addr = lease->addr.s_addr; - iface->net.s_addr = lease->net.s_addr; } + + return 0; } - return 0; -} + static int + do_socket(struct if_state *state, int mode) + { + if (state->interface->fd >= 0) { + close(state->interface->fd); + state->interface->fd = -1; + } + if (mode == SOCKET_CLOSED && state->interface->udp_fd >= 0) { + close(state->interface->udp_fd); + state->interface->udp_fd = -1; + } -static int -do_socket(struct if_state *state, int mode) -{ - if (state->interface->fd >= 0) { - close(state->interface->fd); - state->interface->fd = -1; - } - if (mode == SOCKET_CLOSED && state->interface->udp_fd >= 0) { - close(state->interface->udp_fd); - state->interface->udp_fd = -1; - } + /* We need to bind to a port, otherwise we generate ICMP messages + * that cannot connect the port when we have an address. + * We don't actually use this fd at all, instead using our packet + * filter socket. */ + if (mode == SOCKET_OPEN && + state->interface->udp_fd == -1 && + state->lease.addr.s_addr != 0) + if (open_udp_socket(state->interface) == -1) { + logger(LOG_ERR, "open_udp_socket: %s", strerror(errno)); + return -1; + } - /* We need to bind to a port, otherwise we generate ICMP messages - * that cannot connect the port when we have an address. - * We don't actually use this fd at all, instead using our packet - * filter socket. */ - if (mode == SOCKET_OPEN && - state->interface->udp_fd == -1 && - state->lease.addr.s_addr != 0) - if (open_udp_socket(state->interface) == -1) { - logger(LOG_ERR, "open_udp_socket: %s", strerror(errno)); - return -1; + if (mode == SOCKET_OPEN) + if (open_socket(state->interface, ETHERTYPE_IP) == -1) { + logger(LOG_ERR, "open_socket: %s", strerror(errno)); + return -1; + } + state->socket = mode; + return 0; } - if (mode == SOCKET_OPEN) - if (open_socket(state->interface, ETHERTYPE_IP) == -1) { - logger(LOG_ERR, "open_socket: %s", strerror(errno)); - return -1; + static ssize_t + send_message(struct if_state *state, int type, const struct options *options) + { + struct dhcp_message *dhcp; + uint8_t *udp; + ssize_t len; + ssize_t r; + struct in_addr from; + struct in_addr to; + + logger(LOG_DEBUG, "sending %s with xid 0x%x", + get_dhcp_op(type), state->xid); + state->last_type = type; + state->last_sent = uptime(); + len = make_message(&dhcp, state->interface, &state->lease, state->xid, + type, options); + from.s_addr = dhcp->ciaddr; + if (from.s_addr) + to.s_addr = state->lease.server.s_addr; + else + to.s_addr = 0; + if (to.s_addr) { + r = send_packet(state->interface, to, (uint8_t *)dhcp, len); + if (r == -1) + logger(LOG_ERR, "send_packet: %s", strerror(errno)); + } else { + len = make_udp_packet(&udp, (uint8_t *)dhcp, len, from, to); + free(dhcp); + r = send_raw_packet(state->interface, ETHERTYPE_IP, udp, len); + if (r == -1) + logger(LOG_ERR, "send_raw_packet: %s", strerror(errno)); + free(udp); + } + return r; } - state->socket = mode; - return 0; -} -static ssize_t -send_message(struct if_state *state, int type, const struct options *options) -{ - struct dhcp_message *dhcp; - uint8_t *udp; - ssize_t len; - ssize_t r; - struct in_addr from; - struct in_addr to; - - logger(LOG_DEBUG, "sending %s with xid 0x%x", - get_dhcp_op(type), state->xid); - state->last_type = type; - state->last_sent = uptime(); - len = make_message(&dhcp, state->interface, &state->lease, state->xid, - type, options); - from.s_addr = dhcp->ciaddr; - if (from.s_addr) - to.s_addr = state->lease.server.s_addr; - else - to.s_addr = 0; - if (to.s_addr) { - r = send_packet(state->interface, to, (uint8_t *)dhcp, len); - if (r == -1) - logger(LOG_ERR, "send_packet: %s", strerror(errno)); - } else { - len = make_udp_packet(&udp, (uint8_t *)dhcp, len, from, to); - free(dhcp); - r = send_raw_packet(state->interface, ETHERTYPE_IP, udp, len); - if (r == -1) - logger(LOG_ERR, "send_raw_packet: %s", strerror(errno)); - free(udp); - } - return r; -} + static void + drop_config(struct if_state *state, const char *reason, const struct options *options) + { + configure(state->interface, reason, NULL, state->dhcp, + &state->lease, options, 0); + free(state->old_dhcp); + state->old_dhcp = NULL; + free(state->dhcp); + state->dhcp = NULL; -static void -drop_config(struct if_state *state, const char *reason, const struct options *options) -{ - configure(state->interface, reason, NULL, state->dhcp, - &state->lease, options, 0); - free(state->old_dhcp); - state->old_dhcp = NULL; - free(state->dhcp); - state->dhcp = NULL; + state->lease.addr.s_addr = 0; + } - state->lease.addr.s_addr = 0; -} + static int + wait_for_packet(struct pollfd *fds, struct if_state *state, + const struct options *options) + { + struct dhcp_lease *lease = &state->lease; + struct interface *iface = state->interface; + int timeout = 0; + int retval = 0; + + if (!(state->timeout > 0 || + (options->timeout == 0 && + (state->state != STATE_INIT || state->xid)))) { + /* We need to zero our signal fd, otherwise we will block + * trying to read a signal. */ + fds[POLLFD_SIGNAL].revents = 0; + return 0; + } -static int -wait_for_packet(struct pollfd *fds, struct if_state *state, - const struct options *options) -{ - struct dhcp_lease *lease = &state->lease; - struct interface *iface = state->interface; - int timeout = 0; - int retval = 0; - - if (!(state->timeout > 0 || - (options->timeout == 0 && - (state->state != STATE_INIT || state->xid)))) { - /* We need to zero our signal fd, otherwise we will block - * trying to read a signal. */ - fds[POLLFD_SIGNAL].revents = 0; - return 0; - } + fds[POLLFD_IFACE].fd = iface->fd; - fds[POLLFD_IFACE].fd = iface->fd; + if ((options->timeout == 0 && state->xid) || + (lease->leasetime == ~0U && + state->state == STATE_BOUND)) + { + logger(LOG_DEBUG, "waiting for infinity"); + while (retval == 0) { + if (iface->fd == -1) + retval = poll(fds, 1, INFTIM); + else { + /* Slow down our requests */ + if (timeout < TIMEOUT_MINI_INF) + timeout += TIMEOUT_MINI; + else if (timeout > TIMEOUT_MINI_INF) + timeout = TIMEOUT_MINI_INF; + + retval = poll(fds, 2, timeout * 1000); + if (retval == -1 && errno == EINTR) { + /* If interupted, continue as normal as + * the signal will be delivered down + * the pipe */ + retval = 0; + continue; + } + if (retval == 0) + send_message(state, state->last_type, + options); + } + } - if ((options->timeout == 0 && state->xid) || - (lease->leasetime == ~0U && - state->state == STATE_BOUND)) - { - logger(LOG_DEBUG, "waiting for infinity"); - while (retval == 0) { - if (iface->fd == -1) - retval = poll(fds, 1, INFTIM); - else { - /* Slow down our requests */ - if (timeout < TIMEOUT_MINI_INF) - timeout += TIMEOUT_MINI; - else if (timeout > TIMEOUT_MINI_INF) - timeout = TIMEOUT_MINI_INF; - - retval = poll(fds, 2, timeout * 1000); + return retval; + } + + /* Resend our message if we're getting loads of packets. + * As we use BPF or LPF, we shouldn't hit this as much, but it's + * still nice to have. */ + if (iface->fd > -1 && uptime() - state->last_sent >= TIMEOUT_MINI) + send_message(state, state->last_type, options); + + logger(LOG_DEBUG, "waiting for %lu seconds", state->timeout); + /* If we're waiting for a reply, then we re-send the last + * DHCP request periodically in-case of a bad line */ + retval = 0; + while (state->timeout > 0 && retval == 0) { + if (iface->fd == -1) + timeout = (int)state->timeout; + else { + timeout = TIMEOUT_MINI; + if (state->timeout < timeout) + timeout = (int)state->timeout; + } + timeout *= 1000; + state->start = uptime(); + retval = poll(fds, iface->fd == -1 ? 1 : 2, timeout); + state->timeout -= uptime() - state->start; if (retval == -1 && errno == EINTR) { - /* If interupted, continue as normal as - * the signal will be delivered down - * the pipe */ + /* If interupted, continue as normal as the signal + * will be delivered down the pipe */ retval = 0; continue; } - if (retval == 0) - send_message(state, state->last_type, - options); + if (retval == 0 && iface->fd != -1 && state->timeout > 0) + send_message(state, state->last_type, options); } - } - return retval; - } - - /* Resend our message if we're getting loads of packets. - * As we use BPF or LPF, we shouldn't hit this as much, but it's - * still nice to have. */ - if (iface->fd > -1 && uptime() - state->last_sent >= TIMEOUT_MINI) - send_message(state, state->last_type, options); - - logger(LOG_DEBUG, "waiting for %lu seconds", state->timeout); - /* If we're waiting for a reply, then we re-send the last - * DHCP request periodically in-case of a bad line */ - retval = 0; - while (state->timeout > 0 && retval == 0) { - if (iface->fd == -1) - timeout = (int)state->timeout; - else { - timeout = TIMEOUT_MINI; - if (state->timeout < timeout) - timeout = (int)state->timeout; + return retval; } - timeout *= 1000; - state->start = uptime(); - retval = poll(fds, iface->fd == -1 ? 1 : 2, timeout); - state->timeout -= uptime() - state->start; - if (retval == -1 && errno == EINTR) { - /* If interupted, continue as normal as the signal - * will be delivered down the pipe */ - retval = 0; - continue; - } - if (retval == 0 && iface->fd != -1 && state->timeout > 0) - send_message(state, state->last_type, options); - } - return retval; -} - -static int -handle_signal(int sig, struct if_state *state, const struct options *options) -{ - struct dhcp_lease *lease = &state->lease; + static int + handle_signal(int sig, struct if_state *state, const struct options *options) + { + struct dhcp_lease *lease = &state->lease; - switch (sig) { + switch (sig) { case SIGINT: logger(LOG_INFO, "received SIGINT, stopping"); drop_config(state, "STOP", options); @@ -858,7 +858,7 @@ handle_timeout(struct if_state *state, const struct options *options) reason = "FAIL"; drop_config(state, reason, options); if (!(state->options & DHCPCD_DAEMONISED)) - return -1; + return -1; } if (!(state->options & DHCPCD_DAEMONISED) && IN_LINKLOCAL(ntohl(lease->addr.s_addr))) @@ -885,7 +885,7 @@ handle_timeout(struct if_state *state, const struct options *options) if (lease->addr.s_addr == 0) { if (!IN_LINKLOCAL(ntohl(iface->addr.s_addr))) logger(LOG_INFO, "broadcasting for a lease"); - send_message (state, DHCP_DISCOVER, options); + send_message (state, DHCP_DISCOVER, options); } else if (state->options & DHCPCD_INFORM) { logger(LOG_INFO, "broadcasting inform for %s", inet_ntoa(lease->addr)); @@ -943,7 +943,8 @@ handle_timeout(struct if_state *state, const struct options *options) } static int -handle_dhcp(struct if_state *state, struct dhcp_message **dhcpp, const struct options *options) +handle_dhcp(struct if_state *state, struct dhcp_message **dhcpp, + const struct options *options) { struct timespec ts; struct dhcp_message *dhcp = *dhcpp; @@ -974,7 +975,7 @@ handle_dhcp(struct if_state *state, struct dhcp_message **dhcpp, const struct op /* If we constantly get NAKS then we should slowly back off */ if (state->nakoff > 0) { logger(LOG_DEBUG, "sleeping for %lu seconds", - (unsigned long)state->nakoff); + (unsigned long)state->nakoff); ts.tv_sec = state->nakoff; ts.tv_nsec = 0; state->nakoff *= 2; @@ -1097,50 +1098,50 @@ handle_dhcp(struct if_state *state, struct dhcp_message **dhcpp, const struct op lease->leasedfrom = tv.tv_sec; get_lease(lease, dhcp); - + if (lease->leasetime == ~0U) { lease->renewaltime = lease->rebindtime = lease->leasetime; state->timeout = 1; /* So we wait for infinity */ logger(LOG_INFO, "leased %s for infinity", - inet_ntoa(lease->addr)); + inet_ntoa(lease->addr)); state->state = STATE_BOUND; } else { logger(LOG_INFO, "leased %s for %u seconds", - inet_ntoa(lease->addr), lease->leasetime); + inet_ntoa(lease->addr), lease->leasetime); if (lease->rebindtime >= lease->leasetime) { lease->rebindtime = (lease->leasetime * 0.875); logger(LOG_ERR, - "rebind time greater than lease " - "time, forcing to %u seconds", - lease->rebindtime); + "rebind time greater than lease " + "time, forcing to %u seconds", + lease->rebindtime); } if (lease->renewaltime > lease->rebindtime) { lease->renewaltime = (lease->leasetime * 0.5); logger(LOG_ERR, - "renewal time greater than rebind time, " - "forcing to %u seconds", - lease->renewaltime); + "renewal time greater than rebind time, " + "forcing to %u seconds", + lease->renewaltime); } if (!lease->renewaltime) { lease->renewaltime = (lease->leasetime * 0.5); logger(LOG_INFO, - "no renewal time supplied, assuming %d seconds", - lease->renewaltime); + "no renewal time supplied, assuming %d seconds", + lease->renewaltime); } else logger(LOG_DEBUG, "renew in %u seconds", - lease->renewaltime); + lease->renewaltime); if (!lease->rebindtime) { lease->rebindtime = (lease->leasetime * 0.875); logger(LOG_INFO, - "no rebind time supplied, assuming %d seconds", - lease->rebindtime); + "no rebind time supplied, assuming %d seconds", + lease->rebindtime); } else logger(LOG_DEBUG, "rebind in %u seconds", - lease->rebindtime); + lease->rebindtime); } diff --git a/configure.c b/configure.c index 1e30885c..fd0bd941 100644 --- a/configure.c +++ b/configure.c @@ -181,7 +181,7 @@ in_routes(const struct rt *routes, const struct rt *rt) static int configure_routes(struct interface *iface, const struct dhcp_message *dhcp, - const struct options *options) + const struct options *options) { struct rt *rt, *ort; struct rt *rtn = NULL, *nr = NULL; @@ -350,7 +350,7 @@ int configure(struct interface *iface, const char *reason, const struct dhcp_message *dhcp, const struct dhcp_message *old, const struct dhcp_lease *lease, const struct options *options, - int up) + int up) { struct in_addr addr; struct in_addr net; @@ -379,13 +379,13 @@ configure(struct interface *iface, const char *reason, if (!(options->options & DHCPCD_KEEPADDRESS)) { delete_routes(iface, options->metric); logger(LOG_DEBUG, "deleting IP address %s/%d", - inet_ntoa(iface->addr), - inet_ntocidr(iface->net)); + inet_ntoa(iface->addr), + inet_ntocidr(iface->net)); if (del_address(iface->name, &iface->addr, &iface->net) == -1 && - errno != ENOENT) + errno != ENOENT) logger(LOG_ERR, "del_address: %s", - strerror(errno)); + strerror(errno)); iface->addr.s_addr = 0; iface->net.s_addr = 0; } @@ -399,7 +399,7 @@ configure(struct interface *iface, const char *reason, if (!(options->options & DHCPCD_INFORM) || !has_address(iface->name, &addr, &net)) { logger(LOG_DEBUG, "adding IP address %s/%d", - inet_ntoa(addr), inet_ntocidr(net)); + inet_ntoa(addr), inet_ntocidr(net)); if (add_address(iface->name, &addr, &net, &brd) == -1 && errno != EEXIST) { @@ -428,7 +428,7 @@ configure(struct interface *iface, const char *reason, configure_routes(iface, dhcp, options); up = (iface->addr.s_addr != addr.s_addr || - iface->net.s_addr != net.s_addr); + iface->net.s_addr != net.s_addr); iface->addr.s_addr = addr.s_addr; iface->net.s_addr = net.s_addr; diff --git a/dhcp.c b/dhcp.c index 64964257..5f8abe99 100644 --- a/dhcp.c +++ b/dhcp.c @@ -158,8 +158,8 @@ print_options(void) for (i = 0; i < sizeof(dhcp_options) / sizeof(dhcp_options[0]); i++) if (dhcp_options[i].var) printf("%03d %s\n", - dhcp_options[i].option, - dhcp_options[i].var); + dhcp_options[i].option, + dhcp_options[i].var); } int make_reqmask(struct options *options, char **opts, int add) @@ -209,11 +209,11 @@ valid_length(uint8_t option, const uint8_t *data, int *type) for (i = 0; i < sizeof(dhcp_options) / sizeof(dhcp_options[0]); i++) { if (dhcp_options[i].option != option) continue; - + t = dhcp_options[i].type; if (type) *type = t; - + if (t == 0 || t & STRING || t & RFC3442) return 0; @@ -730,8 +730,7 @@ make_message(struct dhcp_message **message, case ARPHRD_ETHER: case ARPHRD_IEEE802: dhcp->hwlen = ETHER_ADDR_LEN; - memcpy(&dhcp->chaddr, &iface->hwaddr, - ETHER_ADDR_LEN); + memcpy(&dhcp->chaddr, &iface->hwaddr, ETHER_ADDR_LEN); break; case ARPHRD_IEEE1394: case ARPHRD_INFINIBAND: @@ -795,8 +794,8 @@ make_message(struct dhcp_message **message, p += 4; \ } if (lease->addr.s_addr && - lease->addr.s_addr != iface->addr.s_addr && - !IN_LINKLOCAL(ntohl(lease->addr.s_addr))) + lease->addr.s_addr != iface->addr.s_addr && + !IN_LINKLOCAL(ntohl(lease->addr.s_addr))) { PUTADDR(DHCP_IPADDRESS, lease->addr); if (lease->server.s_addr) @@ -925,7 +924,7 @@ read_lease(const struct interface *iface) int fd; struct dhcp_message *dhcp; ssize_t bytes; - + fd = open(iface->leasefile, O_RDONLY); if (fd == -1) return NULL; diff --git a/dhcpcd.c b/dhcpcd.c index 94677e2a..2f6de6c5 100644 --- a/dhcpcd.c +++ b/dhcpcd.c @@ -169,8 +169,8 @@ parse_option(int opt, char *oarg, struct options *options) *options->hostname = '\0'; else if (strlen(oarg) > MAXHOSTNAMELEN) { logger(LOG_ERR, - "`%s' too long for HostName string, max is %d", - oarg, MAXHOSTNAMELEN); + "`%s' too long for HostName string, max is %d", + oarg, MAXHOSTNAMELEN); return -1; } else strlcpy(options->hostname, oarg, @@ -261,17 +261,17 @@ parse_option(int opt, char *oarg, struct options *options) j = 0; for (i = 0; i < userclasses; i++) j += (int)options->userclass[j] + 1; - if (j + 1 + strlen(oarg) > USERCLASS_MAX_LEN) { - logger(LOG_ERR, - "userclass overrun, max is %d", - USERCLASS_MAX_LEN); - return -1; - } - userclasses++; - memcpy(options->userclass + j + 1 , - oarg, strlen(optarg)); - options->userclass[j] = strlen(oarg); - options->userclass_len += (strlen(oarg)) + 1; + if (j + 1 + strlen(oarg) > USERCLASS_MAX_LEN) { + logger(LOG_ERR, + "userclass overrun, max is %d", + USERCLASS_MAX_LEN); + return -1; + } + userclasses++; + memcpy(options->userclass + j + 1 , + oarg, strlen(optarg)); + options->userclass[j] = strlen(oarg); + options->userclass_len += (strlen(oarg)) + 1; break; case 'A': options->options &= ~DHCPCD_ARP; @@ -384,7 +384,7 @@ main(int argc, char **argv) dhcpcd_argc = argc; if (!realpath(argv[0], dhcpcd)) { fprintf(stderr, "unable to resolve the path `%s': %s", - argv[0], strerror(errno)); + argv[0], strerror(errno)); goto abort; } #endif @@ -426,18 +426,18 @@ main(int argc, char **argv) printf(""PACKAGE" "VERSION"\n"); printf("Compile time options:" #ifdef ENABLE_ARP - " ARP" + " ARP" #endif #ifdef ENABLE_DUID - " DUID" + " DUID" #endif #ifdef ENABLE_IPV4LL - " IPV4LL" + " IPV4LL" #endif #ifdef THERE_IS_NO_FORK - " THERE_IS_NO_FORK" + " THERE_IS_NO_FORK" #endif - "\n"); + "\n"); } if (dohelp) @@ -535,7 +535,7 @@ main(int argc, char **argv) } else { if (errno != ENOENT || cf) { logger(LOG_ERR, "fopen `%s': %s", cf ? cf : CONFIGFILE, - strerror(errno)); + strerror(errno)); goto abort; } } @@ -557,12 +557,12 @@ main(int argc, char **argv) case 'd': debug++; switch (debug) { - case 1: - setloglevel(LOG_DEBUG); - break; - case 2: - options->options &= ~DHCPCD_DAEMONISE; - break; + case 1: + setloglevel(LOG_DEBUG); + break; + case 2: + options->options &= ~DHCPCD_DAEMONISE; + break; } break; case 'f': diff --git a/logger.c b/logger.c index da9338d1..e542081f 100644 --- a/logger.c +++ b/logger.c @@ -120,4 +120,3 @@ logger(int level, const char *fmt, ...) va_end(p2); va_end(p); } - diff --git a/net.c b/net.c index 467cdf7e..9de0bdb9 100644 --- a/net.c +++ b/net.c @@ -411,36 +411,36 @@ free_routes(struct rt *routes) int open_udp_socket(struct interface *iface) { - int s; - union sockunion { - struct sockaddr sa; - struct sockaddr_in sin; - } su; - int n = 1; - - if ((s = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) - return -1; - - memset(&su, 0, sizeof(su)); - su.sin.sin_family = AF_INET; - su.sin.sin_port = htons(DHCP_CLIENT_PORT); + int s; + union sockunion { + struct sockaddr sa; + struct sockaddr_in sin; + } su; + int n = 1; + + if ((s = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) == -1) + return -1; + + memset(&su, 0, sizeof(su)); + su.sin.sin_family = AF_INET; + su.sin.sin_port = htons(DHCP_CLIENT_PORT); su.sin.sin_addr.s_addr = iface->addr.s_addr; - if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &n, sizeof(n)) == -1) - goto eexit; + if (setsockopt(s, SOL_SOCKET, SO_REUSEADDR, &n, sizeof(n)) == -1) + goto eexit; /* As we don't actually use this socket for anything, set * the receiver buffer to 1 */ - if (setsockopt(s, SOL_SOCKET, SO_RCVBUF, &n, sizeof(n)) == -1) - goto eexit; - if (bind(s, &su.sa, sizeof(su)) == -1) - goto eexit; + if (setsockopt(s, SOL_SOCKET, SO_RCVBUF, &n, sizeof(n)) == -1) + goto eexit; + if (bind(s, &su.sa, sizeof(su)) == -1) + goto eexit; - iface->udp_fd = s; - close_on_exec(s); - return 0; + iface->udp_fd = s; + close_on_exec(s); + return 0; eexit: - close(s); - return -1; + close(s); + return -1; } ssize_t diff --git a/signal.c b/signal.c index ea036d6e..f9498748 100644 --- a/signal.c +++ b/signal.c @@ -146,7 +146,7 @@ signal_setup(void) for (i = 0; i < sizeof(handle_sigs) / sizeof(handle_sigs[0]); i++) if (sigaction(handle_sigs[i], &sa, NULL) == -1) return -1; - + return 0; } @@ -163,6 +163,6 @@ signal_reset(void) for (i = 0; i < sizeof(handle_sigs) / sizeof(handle_sigs[0]); i++) if (sigaction(handle_sigs[i], &sa, NULL) == -1) return -1; - + return 0; } diff --git a/socket.c b/socket.c index 54d2706d..e0012253 100644 --- a/socket.c +++ b/socket.c @@ -102,7 +102,7 @@ open_socket(struct interface *iface, int protocol) if ((s = socket(PF_PACKET, SOCK_DGRAM, htons(protocol))) == -1) return -1; - + close_on_exec(s); memset(&su, 0, sizeof(su)); su.sll.sll_family = PF_PACKET;