diff options
Diffstat (limited to 'sbin')
-rw-r--r-- | sbin/dhclient/dhclient.c | 504 | ||||
-rw-r--r-- | sbin/dhclient/dhcp.h | 16 | ||||
-rw-r--r-- | sbin/dhclient/dhcpd.h | 763 | ||||
-rw-r--r-- | sbin/dhclient/errwarn.c | 106 | ||||
-rw-r--r-- | sbin/dhclient/ethernet.c | 18 | ||||
-rw-r--r-- | sbin/dhclient/hash.c | 40 | ||||
-rw-r--r-- | sbin/dhclient/hash.h | 7 | ||||
-rw-r--r-- | sbin/dhclient/icmp.c | 68 | ||||
-rw-r--r-- | sbin/dhclient/inet.c | 90 | ||||
-rw-r--r-- | sbin/dhclient/inet.h | 4 | ||||
-rw-r--r-- | sbin/dhclient/options.c | 70 | ||||
-rw-r--r-- | sbin/dhclient/packet.c | 4 | ||||
-rw-r--r-- | sbin/dhclient/parse.c | 16 | ||||
-rw-r--r-- | sbin/dhclient/socket.c | 4 | ||||
-rw-r--r-- | sbin/dhclient/tables.c | 73 | ||||
-rw-r--r-- | sbin/dhclient/tree.c | 453 | ||||
-rw-r--r-- | sbin/dhclient/tree.h | 6 |
17 files changed, 1123 insertions, 1119 deletions
diff --git a/sbin/dhclient/dhclient.c b/sbin/dhclient/dhclient.c index a9473e98c19..77e6fb30d8a 100644 --- a/sbin/dhclient/dhclient.c +++ b/sbin/dhclient/dhclient.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dhclient.c,v 1.5 2004/02/05 13:39:32 henning Exp $ */ +/* $OpenBSD: dhclient.c,v 1.6 2004/02/07 13:26:35 henning Exp $ */ /* DHCP Client. */ @@ -57,7 +57,7 @@ #include "dhcpd.h" #define PERIOD 0x2e -#define hyphenchar(c) ((c) == 0x2d) +#define hyphenchar(c) ((c) == 0x2d) #define bslashchar(c) ((c) == 0x5c) #define periodchar(c) ((c) == PERIOD) #define asterchar(c) ((c) == 0x2a) @@ -67,9 +67,9 @@ #define borderchar(c) (alphachar(c) || digitchar(c)) #define middlechar(c) (borderchar(c) || hyphenchar(c)) -#define domainchar(c) ((c) > 0x20 && (c) < 0x7f) +#define domainchar(c) ((c) > 0x20 && (c) < 0x7f) -#define CLIENT_PATH "PATH=/usr/bin:/usr/sbin:/bin:/sbin" +#define CLIENT_PATH "PATH=/usr/bin:/usr/sbin:/bin:/sbin" TIME cur_time; TIME default_lease_time = 43200; /* 12 hours... */ @@ -89,8 +89,10 @@ struct iaddr iaddr_any = { 4, { 0, 0, 0, 0 } }; struct in_addr inaddr_any; struct sockaddr_in sockaddr_broadcast; -/* ASSERT_STATE() does nothing now; it used to be - assert (state_is == state_shouldbe). */ +/* + * ASSERT_STATE() does nothing now; it used to be + * assert (state_is == state_shouldbe). + */ #define ASSERT_STATE(state_is, state_shouldbe) {} u_int16_t local_port; @@ -110,15 +112,15 @@ static char url[] = "For info, please visit http://www.isc.org/dhcp-contrib.html static void usage(char *); -static int check_option (struct client_lease *l, int option); +static int check_option(struct client_lease *l, int option); static int ipv4addrs(char * buf); static int res_hnok(const char *dn); -char *option_as_string (unsigned int code, unsigned char *data, int len); +char *option_as_string(unsigned int code, unsigned char *data, int len); -int routefd; +int routefd; struct interface_info * isours(u_int16_t index) @@ -176,7 +178,7 @@ routehandler(struct protocol *p) struct interface_info *ip; ssize_t n; - n = read(routefd, &msg, sizeof msg); + n = read(routefd, &msg, sizeof(msg)); rtm = (struct rt_msghdr *)msg; if (n < sizeof(rtm->rtm_msglen) || n < rtm->rtm_msglen || rtm->rtm_version != RTM_VERSION) @@ -252,15 +254,15 @@ main(int argc, char *argv[]) save_scripts = 1; } else if (!strcmp(argv[i], "-cf")) { if (++i == argc) - usage (s); + usage(s); path_dhclient_conf = argv[i]; } else if (!strcmp(argv[i], "-pf")) { if (++i == argc) - usage (s); + usage(s); path_dhclient_pid = argv[i]; } else if (!strcmp(argv[i], "-lf")) { if (++i == argc) - usage (s); + usage(s); path_dhclient_db = argv[i]; } else if (!strcmp(argv[i], "-q")) { quiet = 1; @@ -270,14 +272,14 @@ main(int argc, char *argv[]) } else if (!strcmp(argv[i], "-1")) { onetry = 1; } else if (argv[i][0] == '-') { - usage (s); + usage(s); } else { struct interface_info *tmp = - dmalloc (sizeof *tmp, "specified_interface"); + dmalloc(sizeof(*tmp), "specified_interface"); if (!tmp) - error ("Insufficient memory to %s %s", - "record interface", argv[i]); - memset(tmp, 0, sizeof *tmp); + error("Insufficient memory to %s %s", + "record interface", argv[i]); + memset(tmp, 0, sizeof(*tmp)); strlcpy(tmp->name, argv[i], IFNAMSIZ); tmp->next = interfaces; tmp->flags = INTERFACE_REQUESTED; @@ -298,7 +300,7 @@ main(int argc, char *argv[]) local_port = ent->s_port; } remote_port = htons(ntohs(local_port) - 1); /* XXX */ - + /* Get the current time... */ GET_TIME(&cur_time); @@ -306,7 +308,7 @@ main(int argc, char *argv[]) sockaddr_broadcast.sin_family = AF_INET; sockaddr_broadcast.sin_port = remote_port; sockaddr_broadcast.sin_addr.s_addr = INADDR_BROADCAST; - sockaddr_broadcast.sin_len = sizeof sockaddr_broadcast; + sockaddr_broadcast.sin_len = sizeof(sockaddr_broadcast); inaddr_any.s_addr = INADDR_ANY; /* Discover all the network interfaces. */ @@ -328,7 +330,7 @@ main(int argc, char *argv[]) /* Close and unlock */ close(fd); - + /* If no broadcast interfaces were discovered, call the script and tell it so. */ if (!interfaces) { @@ -376,7 +378,7 @@ main(int argc, char *argv[]) for(ip = interfaces; ip; ip = ip->next) { int junk; memcpy(&junk, &ip->hw_address.haddr[ip->hw_address.hlen - - sizeof seed], sizeof seed); + sizeof(seed)], sizeof(seed)); seed += junk; } srandom(seed + cur_time); @@ -398,7 +400,7 @@ main(int argc, char *argv[]) } static void -usage (char *appname) +usage(char *appname) { note("%s", message); note("%s", copyright); @@ -412,17 +414,19 @@ usage (char *appname) error(" [-pf pidfile] [interface]"); } -void cleanup () +void +cleanup(void) { } -/* Individual States: - * +/* + * Individual States: + * * Each routine is called from the dhclient_state_machine() in one of * these conditions: - *->entering INIT state - *->recvpacket_flag == 0: timeout in this state - *->otherwise: received a packet in this state + * -> entering INIT state + * -> recvpacket_flag == 0: timeout in this state + * -> otherwise: received a packet in this state * * Return conditions as handled by dhclient_state_machine(): * Returns 1, sendpacket_flag = 1: send packet, reset timer. @@ -433,9 +437,9 @@ void cleanup () * active_lease: the lease that is being used on the interface * (null pointer if not configured yet). * offered_leases: leases corresponding to DHCPOFFER messages that have - * been sent to us by DHCP servers. + * been sent to us by DHCP servers. * acked_leases: leases corresponding to DHCPACK messages that have been - * sent to us by DHCP servers. + * sent to us by DHCP servers. * sendpacket: DHCP packet we're trying to send. * destination: IP address to send sendpacket to * In addition, there are several relevant per-lease variables. @@ -446,13 +450,13 @@ void cleanup () */ void -state_reboot (void *ipp) +state_reboot(void *ipp) { struct interface_info *ip = ipp; /* If we don't remember an active lease, go straight to INIT. */ if (!ip->client->active || ip->client->active->is_bootp) { - state_init (ip); + state_init(ip); return; } @@ -490,7 +494,7 @@ state_init(void *ipp) /* Make a DHCPDISCOVER packet, and set appropriate per-interface flags. */ - make_discover (ip, ip->client->active); + make_discover(ip, ip->client->active); ip->client->xid = ip->client->packet.xid; ip->client->destination = iaddr_broadcast; ip->client->state = S_SELECTING; @@ -536,7 +540,7 @@ state_selecting(void *ipp) machine using the offered address, it exits nonzero. We need to send a DHCPDECLINE and toss the lease. */ - if (script_go (ip)) { + if (script_go(ip)) { make_decline(ip, lp); send_decline(ip); goto freeit; @@ -554,7 +558,7 @@ freeit: to square one. */ if (!picked) { ip->client->state = S_INIT; - state_init (ip); + state_init(ip); return; } @@ -590,7 +594,7 @@ freeit: /* Add an immediate timeout to send the first DHCPREQUEST packet. */ send_request(ip); -} +} /* state_requesting is called when we receive a DHCPACK message after having sent out one or more DHCPREQUEST packets. */ @@ -600,15 +604,15 @@ dhcpack(struct packet *packet) { struct interface_info *ip = packet->interface; struct client_lease *lease; - + /* If we're not receptive to an offer right now, or if the offer has an unrecognizable transaction id, then just drop it. */ if (packet->interface->client->xid != packet->raw->xid || (packet->interface->hw_address.hlen != packet->raw->hlen) || (memcmp(packet->interface->hw_address.haddr, packet->raw->chaddr, packet->raw->hlen))) { -#if defined (DEBUG) - debug ("DHCPACK in wrong transaction."); +#ifdef DEBUG + debug("DHCPACK in wrong transaction."); #endif return; } @@ -617,13 +621,13 @@ dhcpack(struct packet *packet) ip->client->state != S_REQUESTING && ip->client->state != S_RENEWING && ip->client->state != S_REBINDING) { -#if defined (DEBUG) - debug ("DHCPACK in wrong state."); +#ifdef DEBUG + debug("DHCPACK in wrong state."); #endif return; } - note("DHCPACK from %s", piaddr (packet->client_addr)); + note("DHCPACK from %s", piaddr(packet->client_addr)); lease = packet_to_lease(packet); if (!lease) { @@ -692,36 +696,37 @@ bind_lease(struct interface_info *ip) (ip->client->state == S_REBOOTING ? "REBOOT" : "REBIND"))), ip->client->new->medium); if (ip->client->active && ip->client->state != S_REBOOTING) - script_write_params (ip, "old_", ip->client->active); - script_write_params (ip, "new_", ip->client->new); + script_write_params(ip, "old_", ip->client->active); + script_write_params(ip, "new_", ip->client->new); if (ip->client->alias) - script_write_params (ip, "alias_", ip->client->alias); - script_go (ip); + script_write_params(ip, "alias_", ip->client->alias); + script_go(ip); /* Replace the old active lease with the new one. */ if (ip->client->active) - free_client_lease (ip->client->active); + free_client_lease(ip->client->active); ip->client->active = ip->client->new; ip->client->new = NULL; /* Set up a timeout to start the renewal process. */ - add_timeout (ip->client->active->renewal, state_bound, ip); + add_timeout(ip->client->active->renewal, state_bound, ip); - note ("bound to %s -- renewal in %d seconds.", - piaddr (ip->client->active->address), + note("bound to %s -- renewal in %d seconds.", + piaddr(ip->client->active->address), ip->client->active->renewal - cur_time); ip->client->state = S_BOUND; reinitialize_interfaces(); go_daemon(); -} - -/* state_bound is called when we've successfully bound to a particular - lease, but the renewal time on that lease has expired. We are - expected to unicast a DHCPREQUEST to the server that gave us our - original lease. */ +} +/* + * state_bound is called when we've successfully bound to a particular + * lease, but the renewal time on that lease has expired. We are + * expected to unicast a DHCPREQUEST to the server that gave us our + * original lease. + */ void -state_bound (void *ipp) +state_bound(void *ipp) { struct interface_info *ip = ipp; @@ -744,7 +749,7 @@ state_bound (void *ipp) /* Send the first packet immediately. */ send_request(ip); -} +} int commit_leases(void) @@ -779,7 +784,7 @@ bootp(struct packet *packet) note("BOOTREPLY from %s rejected.", piaddr(ap->addr)); return; } - } + } dhcpoffer(packet); } @@ -811,7 +816,7 @@ dhcp(struct packet *packet) on it. */ for (ap = packet->interface->client->config->reject_list; ap; ap = ap->next) { - if (addr_eq (packet->client_addr, ap->addr)) { + if (addr_eq(packet->client_addr, ap->addr)) { note("%s from %s rejected.", type, piaddr(ap->addr)); return; } @@ -826,12 +831,12 @@ dhcpoffer(struct packet *packet) struct client_lease *lease, *lp; int i; int arp_timeout_needed, stop_selecting; - char *name = - (packet->options[DHO_DHCP_MESSAGE_TYPE].len ? "DHCPOFFER" : "BOOTREPLY"); - + char *name = packet->options[DHO_DHCP_MESSAGE_TYPE].len ? + "DHCPOFFER" : "BOOTREPLY"; + #ifdef DEBUG_PACKET - dump_packet (packet); -#endif + dump_packet(packet); +#endif /* If we're not receptive to an offer right now, or if the offer has an unrecognizable transaction id, then just drop it. */ @@ -840,8 +845,8 @@ dhcpoffer(struct packet *packet) (packet->interface->hw_address.hlen != packet->raw->hlen) || (memcmp(packet->interface->hw_address.haddr, packet->raw->chaddr, packet->raw->hlen))) { -#if defined (DEBUG) - debug ("%s in wrong transaction.", name); +#ifdef DEBUG + debug("%s in wrong transaction.", name); #endif return; } @@ -862,15 +867,15 @@ dhcpoffer(struct packet *packet) /* If we've already seen this lease, don't record it again. */ for (lease = ip->client->offered_leases; lease; lease = lease->next) { - if (lease->address.len == sizeof packet->raw->yiaddr && - !memcmp (lease->address.iabuf, + if (lease->address.len == sizeof(packet->raw->yiaddr) && + !memcmp(lease->address.iabuf, &packet->raw->yiaddr, lease->address.len)) { - debug ("%s already seen.", name); + debug("%s already seen.", name); return; } } - lease = packet_to_lease (packet); + lease = packet_to_lease(packet); if (!lease) { note("packet_to_lease failed."); return; @@ -887,7 +892,7 @@ dhcpoffer(struct packet *packet) /* Send out an ARP Request for the offered IP address. */ script_init(ip, "ARPSEND", lease->medium); script_write_params(ip, "check_", lease); - /* If the script can't send an ARP request without waiting, + /* If the script can't send an ARP request without waiting, we'll be waiting when we do the ARPCHECK, so don't wait now. */ if (script_go(ip)) arp_timeout_needed = 0; @@ -896,7 +901,7 @@ dhcpoffer(struct packet *packet) /* Figure out when we're supposed to stop selecting. */ stop_selecting = - (ip->client->first_sending + ip->client->config->select_interval); + ip->client->first_sending + ip->client->config->select_interval; /* If this is the lease we asked for, put it at the head of the list, and don't mess with the arp request timeout. */ @@ -937,10 +942,10 @@ dhcpoffer(struct packet *packet) state_selecting(). Otherwise, time out into state_selecting at the select interval. */ if (stop_selecting <= 0) - state_selecting (ip); + state_selecting(ip); else { - add_timeout (stop_selecting, state_selecting, ip); - cancel_timeout (send_discover, ip); + add_timeout(stop_selecting, state_selecting, ip); + cancel_timeout(send_discover, ip); } } @@ -960,7 +965,7 @@ packet_to_lease(struct packet *packet) return (NULL); } - memset(lease, 0, sizeof *lease); + memset(lease, 0, sizeof(*lease)); /* Copy the lease options. */ for (i = 0; i < 256; i++) { @@ -968,7 +973,7 @@ packet_to_lease(struct packet *packet) lease->options[i].data = malloc(packet->options[i].len + 1); if (!lease->options[i].data) { - warn ("dhcpoffer: no memory for option %d", i); + warn("dhcpoffer: no memory for option %d", i); free_client_lease(lease); return (NULL); } else { @@ -982,7 +987,7 @@ packet_to_lease(struct packet *packet) } if (!check_option(lease,i)) { /* ignore a bogus lease offer */ - warn ("Invalid lease option - ignoring offer"); + warn("Invalid lease option - ignoring offer"); free_client_lease(lease); return (NULL); } @@ -1001,15 +1006,15 @@ packet_to_lease(struct packet *packet) warn("dhcpoffer: no memory for server name."); free_client_lease(lease); return (NULL); - } + } memcpy(lease->server_name, packet->raw->sname, DHCP_SNAME_LEN); lease->server_name[DHCP_SNAME_LEN]='\0'; if (!res_hnok(lease->server_name) ) { warn("Bogus server name %s", lease->server_name ); free_client_lease(lease); return (NULL); - } - + } + } /* Ditto for the filename. */ @@ -1040,8 +1045,8 @@ dhcpnak(struct packet *packet) (packet->interface->hw_address.hlen != packet->raw->hlen) || (memcmp(packet->interface->hw_address.haddr, packet->raw->chaddr, packet->raw->hlen))) { -#if defined (DEBUG) - debug ("DHCPNAK in wrong transaction."); +#ifdef DEBUG + debug("DHCPNAK in wrong transaction."); #endif return; } @@ -1050,13 +1055,13 @@ dhcpnak(struct packet *packet) ip->client->state != S_REQUESTING && ip->client->state != S_RENEWING && ip->client->state != S_REBINDING) { -#if defined (DEBUG) - debug ("DHCPNAK in wrong state."); +#ifdef DEBUG + debug("DHCPNAK in wrong state."); #endif return; } - note("DHCPNAK from %s", piaddr (packet->client_addr)); + note("DHCPNAK from %s", piaddr(packet->client_addr)); if (!ip->client->active) { note("DHCPNAK with no active lease.\n"); @@ -1092,7 +1097,7 @@ send_discover(void *ipp) /* If we're past the panic timeout, call the script and tell it we haven't found anything for this interface yet. */ if (interval > ip->client->config->timeout) { - state_panic (ip); + state_panic(ip); return; } @@ -1106,34 +1111,35 @@ again: if (ip->client->medium) { ip->client->medium = ip->client->medium->next; increase = 0; - } + } if (!ip->client->medium) { if (fail) error("No valid media types for %s!", ip->name); ip->client->medium = ip->client->config->media; increase = 1; } - + note("Trying medium \"%s\" %d", ip->client->medium->string, increase); script_init(ip, "MEDIUM", ip->client->medium); - if (script_go (ip)) + if (script_go(ip)) goto again; } - /* If we're supposed to increase the interval, do so. If it's - currently zero (i.e., we haven't sent any packets yet), set - it to one; otherwise, add to it a random number between - zero and two times itself. On average, this means that it - will double with every transmission. */ + /* + * If we're supposed to increase the interval, do so. If it's + * currently zero (i.e., we haven't sent any packets yet), set + * it to one; otherwise, add to it a random number between zero + * and two times itself. On average, this means that it will + * double with every transmission. + */ if (increase) { if (!ip->client->interval) ip->client->interval = - ip->client->config->initial_interval; + ip->client->config->initial_interval; else { - ip->client->interval += - ((random () >> 2) % - (2 * ip->client->interval)); + ip->client->interval += (random() >> 2) % + (2 * ip->client->interval); } /* Don't backoff past cutoff. */ @@ -1146,7 +1152,7 @@ again: } else if (!ip->client->interval) ip->client->interval = ip->client->config->initial_interval; - + /* If the backoff would take us to the panic timeout, just use that as the interval. */ if (cur_time + ip->client->interval > @@ -1157,15 +1163,15 @@ again: /* Record the number of seconds since we started sending. */ if (interval < 65536) - ip->client->packet.secs = htons (interval); + ip->client->packet.secs = htons(interval); else - ip->client->packet.secs = htons (65535); + ip->client->packet.secs = htons(65535); ip->client->secs = ip->client->packet.secs; - note ("DHCPDISCOVER on %s to %s port %d interval %d", + note("DHCPDISCOVER on %s to %s port %d interval %d", ip->name, - inet_ntoa (sockaddr_broadcast.sin_addr), - ntohs (sockaddr_broadcast.sin_port), ip->client->interval); + inet_ntoa(sockaddr_broadcast.sin_addr), + ntohs(sockaddr_broadcast.sin_port), ip->client->interval); /* Send out a packet. */ result = send_packet(ip, NULL, &ip->client->packet, @@ -1174,13 +1180,14 @@ again: add_timeout(cur_time + ip->client->interval, send_discover, ip); } -/* state_panic gets called if we haven't received any offers in a preset - amount of time. When this happens, we try to use existing leases that - haven't yet expired, and failing that, we call the client script and - hope it can do something. */ - +/* + * state_panic gets called if we haven't received any offers in a preset + * amount of time. When this happens, we try to use existing leases + * that haven't yet expired, and failing that, we call the client script + * and hope it can do something. + */ void -state_panic (void *ipp) +state_panic(void *ipp) { struct interface_info *ip = ipp; @@ -1211,11 +1218,11 @@ state_panic (void *ipp) /* If the old lease is still good and doesn't yet need renewal, go into BOUND state and timeout at the renewal time. */ - if (!script_go (ip)) { + if (!script_go(ip)) { if (cur_time < ip->client->active->renewal) { ip->client->state = S_BOUND; - note ("bound: renewal in %d seconds.", + note("bound: renewal in %d seconds.", ip->client->active->renewal - cur_time); add_timeout( @@ -1268,7 +1275,7 @@ activate_next: script_init(ip, "FAIL", NULL); if (ip->client->alias) script_write_params(ip, "alias_", ip->client->alias); - script_go (ip); + script_go(ip); ip->client->state = S_INIT; add_timeout(cur_time + ip->client->config->retry_interval, state_init, ip); @@ -1331,7 +1338,7 @@ cancel: script_init(ip, "EXPIRE", NULL); script_write_params(ip, "old_", ip->client->active); if (ip->client->alias) - script_write_params (ip, "alias_", ip->client->alias); + script_write_params(ip, "alias_", ip->client->alias); script_go(ip); /* Now do a preinit on the interface so that we can @@ -1352,7 +1359,7 @@ cancel: else ip->client->interval += ((random () >> 2) % (2 * ip->client->interval)); - + /* Don't backoff past cutoff. */ if (ip->client->interval > ip->client->config->backoff_cutoff) @@ -1378,13 +1385,14 @@ cancel: else memcpy(&destination.sin_addr.s_addr, ip->client->destination.iabuf, - sizeof destination.sin_addr.s_addr); + sizeof(destination.sin_addr.s_addr)); destination.sin_port = remote_port; destination.sin_family = AF_INET; - destination.sin_len = sizeof destination; + destination.sin_len = sizeof(destination); if (ip->client->state != S_REQUESTING) - memcpy(&from, ip->client->active->address.iabuf, sizeof from); + memcpy(&from, ip->client->active->address.iabuf, + sizeof(from)); else from.s_addr = INADDR_ANY; @@ -1393,13 +1401,13 @@ cancel: ip->client->packet.secs = ip->client->secs; else { if (interval < 65536) - ip->client->packet.secs = htons (interval); + ip->client->packet.secs = htons(interval); else - ip->client->packet.secs = htons (65535); + ip->client->packet.secs = htons(65535); } note("DHCPREQUEST on %s to %s port %d", ip->name, - inet_ntoa (destination.sin_addr), ntohs(destination.sin_port)); + inet_ntoa(destination.sin_addr), ntohs(destination.sin_port)); if (destination.sin_addr.s_addr != INADDR_BROADCAST && fallback_interface) @@ -1408,7 +1416,7 @@ cancel: &destination, NULL); else /* Send out a packet. */ - result = send_packet (ip, NULL, &ip->client->packet, + result = send_packet(ip, NULL, &ip->client->packet, ip->client->packet_length, from, &destination, NULL); add_timeout(cur_time + ip->client->interval, send_request, ip); @@ -1421,8 +1429,8 @@ send_decline(void *ipp) int result; note("DHCPDECLINE on %s to %s port %d", ip->name, - inet_ntoa (sockaddr_broadcast.sin_addr), - ntohs (sockaddr_broadcast.sin_port)); + inet_ntoa(sockaddr_broadcast.sin_addr), + ntohs(sockaddr_broadcast.sin_port)); /* Send out a packet. */ result = send_packet(ip, NULL, &ip->client->packet, @@ -1437,8 +1445,8 @@ send_release(void *ipp) int result; note("DHCPRELEASE on %s to %s port %d", ip->name, - inet_ntoa (sockaddr_broadcast.sin_addr), - ntohs (sockaddr_broadcast.sin_port)); + inet_ntoa(sockaddr_broadcast.sin_addr), + ntohs(sockaddr_broadcast.sin_port)); /* Send out a packet. */ result = send_packet(ip, NULL, &ip->client->packet, @@ -1455,15 +1463,15 @@ make_discover(struct interface_info *ip, struct client_lease *lease) struct tree_cache option_elements[256]; memset(option_elements, 0, sizeof(option_elements)); - memset(options, 0, sizeof options); + memset(options, 0, sizeof(options)); memset(&ip->client->packet, 0, sizeof(ip->client->packet)); /* Set DHCP_MESSAGE_TYPE to DHCPDISCOVER */ i = DHO_DHCP_MESSAGE_TYPE; options[i] = &option_elements[i]; options[i]->value = &discover; - options[i]->len = sizeof discover; - options[i]->buf_size = sizeof discover; + options[i]->len = sizeof(discover); + options[i]->buf_size = sizeof(discover); options[i]->timeout = 0xFFFFFFFF; options[i]->tree = NULL; @@ -1524,13 +1532,13 @@ make_discover(struct interface_info *ip, struct client_lease *lease) ip->client->packet.flags = htons(BOOTP_BROADCAST); memset(&(ip->client->packet.ciaddr), - 0, sizeof ip->client->packet.ciaddr); + 0, sizeof(ip->client->packet.ciaddr)); memset(&(ip->client->packet.yiaddr), - 0, sizeof ip->client->packet.yiaddr); + 0, sizeof(ip->client->packet.yiaddr)); memset(&(ip->client->packet.siaddr), - 0, sizeof ip->client->packet.siaddr); + 0, sizeof(ip->client->packet.siaddr)); memset(&(ip->client->packet.giaddr), - 0, sizeof ip->client->packet.giaddr); + 0, sizeof(ip->client->packet.giaddr)); memcpy(ip->client->packet.chaddr, ip->hw_address.haddr, ip->hw_address.hlen); @@ -1550,15 +1558,15 @@ make_request(struct interface_info *ip, struct client_lease * lease) struct tree_cache *options[256]; struct tree_cache option_elements[256]; - memset(options, 0, sizeof options); + memset(options, 0, sizeof(options)); memset(&ip->client->packet, 0, sizeof(ip->client->packet)); /* Set DHCP_MESSAGE_TYPE to DHCPREQUEST */ i = DHO_DHCP_MESSAGE_TYPE; options[i] = &option_elements[i]; options[i]->value = &request; - options[i]->len = sizeof request; - options[i]->buf_size = sizeof request; + options[i]->len = sizeof(request); + options[i]->buf_size = sizeof(request); options[i]->timeout = 0xFFFFFFFF; options[i]->tree = NULL; @@ -1635,20 +1643,20 @@ make_request(struct interface_info *ip, struct client_lease * lease) ip->client->packet.flags = 0; } else { memset(&ip->client->packet.ciaddr, 0, - sizeof ip->client->packet.ciaddr); + sizeof(ip->client->packet.ciaddr)); if (can_receive_unicast_unconfigured(ip)) ip->client->packet.flags = 0; else - ip->client->packet.flags = htons (BOOTP_BROADCAST); + ip->client->packet.flags = htons(BOOTP_BROADCAST); } - memset (&ip->client->packet.yiaddr, 0, - sizeof ip->client->packet.yiaddr); - memset (&ip->client->packet.siaddr, 0, - sizeof ip->client->packet.siaddr); - memset (&ip->client->packet.giaddr, 0, - sizeof ip->client->packet.giaddr); - memcpy (ip->client->packet.chaddr, + memset(&ip->client->packet.yiaddr, 0, + sizeof(ip->client->packet.yiaddr)); + memset(&ip->client->packet.siaddr, 0, + sizeof(ip->client->packet.siaddr)); + memset(&ip->client->packet.giaddr, 0, + sizeof(ip->client->packet.giaddr)); + memcpy(ip->client->packet.chaddr, ip->hw_address.haddr, ip->hw_address.hlen); #ifdef DEBUG_PACKET @@ -1669,15 +1677,15 @@ make_decline(struct interface_info *ip, struct client_lease *lease) struct tree_cache server_id_tree; struct tree_cache client_id_tree; - memset(options, 0, sizeof options); - memset(&ip->client->packet, 0, sizeof (ip->client->packet)); + memset(options, 0, sizeof(options)); + memset(&ip->client->packet, 0, sizeof(ip->client->packet)); /* Set DHCP_MESSAGE_TYPE to DHCPDECLINE */ i = DHO_DHCP_MESSAGE_TYPE; options[i] = &message_type_tree; options[i]->value = &decline; - options[i]->len = sizeof decline; - options[i]->buf_size = sizeof decline; + options[i]->len = sizeof(decline); + options[i]->buf_size = sizeof(decline); options[i]->timeout = 0xFFFFFFFF; options[i]->tree = NULL; @@ -1712,7 +1720,7 @@ make_decline(struct interface_info *ip, struct client_lease *lease) /* Set up the option buffer... */ - ip->client->packet_length = cons_options (NULL, &ip->client->packet, 0, + ip->client->packet_length = cons_options(NULL, &ip->client->packet, 0, options, 0, 0, 0, NULL, 0); if (ip->client->packet_length < BOOTP_MIN_LEN) ip->client->packet_length = BOOTP_MIN_LEN; @@ -1726,15 +1734,15 @@ make_decline(struct interface_info *ip, struct client_lease *lease) ip->client->packet.flags = 0; /* ciaddr must always be zero. */ - memset (&ip->client->packet.ciaddr, 0, - sizeof ip->client->packet.ciaddr); - memset (&ip->client->packet.yiaddr, 0, - sizeof ip->client->packet.yiaddr); - memset (&ip->client->packet.siaddr, 0, - sizeof ip->client->packet.siaddr); - memset (&ip->client->packet.giaddr, 0, - sizeof ip->client->packet.giaddr); - memcpy (ip->client->packet.chaddr, + memset(&ip->client->packet.ciaddr, 0, + sizeof(ip->client->packet.ciaddr)); + memset(&ip->client->packet.yiaddr, 0, + sizeof(ip->client->packet.yiaddr)); + memset(&ip->client->packet.siaddr, 0, + sizeof(ip->client->packet.siaddr)); + memset(&ip->client->packet.giaddr, 0, + sizeof(ip->client->packet.giaddr)); + memcpy(ip->client->packet.chaddr, ip->hw_address.haddr, ip->hw_address.hlen); #ifdef DEBUG_PACKET @@ -1753,15 +1761,15 @@ make_release(struct interface_info *ip, struct client_lease *lease) struct tree_cache message_type_tree; struct tree_cache server_id_tree; - memset(options, 0, sizeof options); + memset(options, 0, sizeof(options)); memset(&ip->client->packet, 0, sizeof(ip->client->packet)); /* Set DHCP_MESSAGE_TYPE to DHCPRELEASE */ i = DHO_DHCP_MESSAGE_TYPE; options[i] = &message_type_tree; options[i]->value = &request; - options[i]->len = sizeof request; - options[i]->buf_size = sizeof request; + options[i]->len = sizeof(request); + options[i]->buf_size = sizeof(request); options[i]->timeout = 0xFFFFFFFF; options[i]->tree = NULL; @@ -1788,15 +1796,15 @@ make_release(struct interface_info *ip, struct client_lease *lease) ip->client->packet.secs = 0; ip->client->packet.flags = 0; - memset (&ip->client->packet.ciaddr, 0, - sizeof ip->client->packet.ciaddr); - memset (&ip->client->packet.yiaddr, 0, - sizeof ip->client->packet.yiaddr); - memset (&ip->client->packet.siaddr, 0, - sizeof ip->client->packet.siaddr); - memset (&ip->client->packet.giaddr, 0, - sizeof ip->client->packet.giaddr); - memcpy (ip->client->packet.chaddr, + memset(&ip->client->packet.ciaddr, 0, + sizeof(ip->client->packet.ciaddr)); + memset(&ip->client->packet.yiaddr, 0, + sizeof(ip->client->packet.yiaddr)); + memset(&ip->client->packet.siaddr, 0, + sizeof(ip->client->packet.siaddr)); + memset(&ip->client->packet.giaddr, 0, + sizeof(ip->client->packet.giaddr)); + memcpy(ip->client->packet.chaddr, ip->hw_address.haddr, ip->hw_address.hlen); #ifdef DEBUG_PACKET @@ -1812,14 +1820,14 @@ free_client_lease(struct client_lease *lease) int i; if (lease->server_name) - free (lease->server_name); + free(lease->server_name); if (lease->filename) - free (lease->filename); + free(lease->filename); for (i = 0; i < 256; i++) { if (lease->options[i].len) - free (lease->options[i].data); + free(lease->options[i].data); } - free (lease); + free(lease); } FILE *leaseFile; @@ -1840,9 +1848,9 @@ rewrite_client_leases(void) we know about. */ for (ip = interfaces; ip; ip = ip->next) { for (lp = ip->client->leases; lp; lp = lp->next) - write_client_lease (ip, lp, 1); + write_client_lease(ip, lp, 1); if (ip->client->active) - write_client_lease (ip, ip->client->active, 1); + write_client_lease(ip, ip->client->active, 1); } /* Write out any leases that are attached to interfaces that aren't @@ -1866,7 +1874,7 @@ write_client_lease(struct interface_info *ip, struct client_lease *lease, if (!rewrite) { if (leases_written++ > 20) { - rewrite_client_leases (); + rewrite_client_leases(); leases_written = 0; } } @@ -1904,15 +1912,15 @@ write_client_lease(struct interface_info *ip, struct client_lease *lease, /* Note: the following is not a Y2K bug - it's a Y1.9K bug. Until somebody invents a time machine, I think we can safely disregard it. */ - t = gmtime (&lease->renewal); + t = gmtime(&lease->renewal); fprintf(leaseFile, " renew %d %d/%d/%d %02d:%02d:%02d;\n", t->tm_wday, t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec); - t = gmtime (&lease->rebind); + t = gmtime(&lease->rebind); fprintf(leaseFile, " rebind %d %d/%d/%d %02d:%02d:%02d;\n", t->tm_wday, t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec); - t = gmtime (&lease->expiry); + t = gmtime(&lease->expiry); fprintf(leaseFile, " expire %d %d/%d/%d %02d:%02d:%02d;\n", t->tm_wday, t->tm_year + 1900, t->tm_mon + 1, t->tm_mday, t->tm_hour, t->tm_min, t->tm_sec); @@ -1936,7 +1944,7 @@ script_init(struct interface_info *ip, char *reason, struct string_list *medium) malloc(ip->client->scriptEnvsize * sizeof(char *)); if (ip->client->scriptEnv == NULL) error("script_init: no memory for environment initialization"); - + ip->client->scriptEnv[0]=strdup(CLIENT_PATH); if (ip->client->scriptEnv[0] == NULL) error("script_init: no memory for environment initialization"); @@ -1954,7 +1962,7 @@ script_init(struct interface_info *ip, char *reason, struct string_list *medium) } void -script_write_params (struct interface_info *ip, char *prefix, +script_write_params(struct interface_info *ip, char *prefix, struct client_lease *lease) { int i; @@ -1974,24 +1982,24 @@ script_write_params (struct interface_info *ip, char *prefix, if (lease->options[DHO_SUBNET_MASK].len && (lease->options[DHO_SUBNET_MASK].len < - sizeof lease->address.iabuf)) { + sizeof(lease->address.iabuf))) { struct iaddr netmask, subnet, broadcast; - memcpy (netmask.iabuf, + memcpy(netmask.iabuf, lease->options[DHO_SUBNET_MASK].data, lease->options[DHO_SUBNET_MASK].len); netmask.len = lease->options[DHO_SUBNET_MASK].len; - subnet = subnet_number (lease->address, netmask); + subnet = subnet_number(lease->address, netmask); if (subnet.len) { script_set_env(ip->client, prefix, "network_number", - piaddr(subnet)); + piaddr(subnet)); if (!lease->options[DHO_BROADCAST_ADDRESS].len) { - broadcast = broadcast_addr (subnet, netmask); - if (broadcast.len) + broadcast = broadcast_addr(subnet, netmask); + if (broadcast.len) script_set_env(ip->client, prefix, "broadcast_address", - piaddr(broadcast)); + piaddr(broadcast)); } } } @@ -2014,48 +2022,48 @@ script_write_params (struct interface_info *ip, char *prefix, break; case ACTION_SUPERSEDE: supersede: - dp = ip->client -> + dp = ip->client-> config->defaults[i].data; - len = ip->client -> + len = ip->client-> config->defaults[i].len; break; case ACTION_PREPEND: - len = (ip->client -> + len = ip->client-> config->defaults[i].len + - lease->options[i].len); - if (len > sizeof dbuf) { - warn ("no space to %s %s", + lease->options[i].len; + if (len > sizeof(dbuf)) { + warn("no space to %s %s", "prepend option", dhcp_options[i].name); goto supersede; } dp = dbuf; - memcpy (dp, + memcpy(dp, ip->client-> config->defaults[i].data, ip->client-> config->defaults[i].len); - memcpy (dp + ip->client-> + memcpy(dp + ip->client-> config->defaults[i].len, lease->options[i].data, lease->options[i].len); - dp[len] = '\0'; + dp[len] = '\0'; break; case ACTION_APPEND: - len = (ip->client -> + len = ip->client-> config->defaults[i].len + - lease->options[i].len); - if (len > sizeof dbuf) { - warn ("no space to %s %s", + lease->options[i].len; + if (len > sizeof(dbuf)) { + warn("no space to %s %s", "append option", dhcp_options[i].name); goto supersede; } dp = dbuf; - memcpy (dp, + memcpy(dp, lease->options[i].data, lease->options[i].len); - memcpy (dp + lease->options[i].len, + memcpy(dp + lease->options[i].len, ip->client-> config->defaults[i].data, ip->client-> @@ -2063,9 +2071,9 @@ script_write_params (struct interface_info *ip, char *prefix, dp[len] = '\0'; } } else { - dp = ip->client -> + dp = ip->client-> config->defaults[i].data; - len = ip->client -> + len = ip->client-> config->defaults[i].len; } } else if (lease->options[i].len) { @@ -2076,14 +2084,14 @@ script_write_params (struct interface_info *ip, char *prefix, } if (len) { char name[256]; - if (dhcp_option_ev_name (name, sizeof name, - &dhcp_options[i])) + if (dhcp_option_ev_name(name, sizeof(name), + &dhcp_options[i])) script_set_env(ip->client, prefix, name, - pretty_print_option (i, dp, len, 0, 0)); + pretty_print_option(i, dp, len, 0, 0)); } } - snprintf(tbuf, sizeof(tbuf), "%d", (int) lease->expiry); - script_set_env(ip->client, prefix, "expiry", tbuf); + snprintf(tbuf, sizeof(tbuf), "%d", (int)lease->expiry); + script_set_env(ip->client, prefix, "expiry", tbuf); } int @@ -2096,10 +2104,10 @@ script_go(struct interface_info *ip) char reason[] = "REASON=NBI"; static char client_path[] = CLIENT_PATH; int pid, wpid, wstatus; - + if (ip) { scriptName = ip->client->config->script_name; - envp = ip->client ->scriptEnv; + envp = ip->client->scriptEnv; } else { scriptName = top_level_config.script_name; epp[0] = reason; @@ -2117,7 +2125,7 @@ script_go(struct interface_info *ip) wstatus = 0; } else if (pid) { do { - wpid = wait (&wstatus); + wpid = wait(&wstatus); } while (wpid != pid && wpid > 0); if (wpid < 0) { error("wait: %m"); @@ -2126,7 +2134,7 @@ script_go(struct interface_info *ip) } else { execve(scriptName, argv, envp); error("execve (%s, ...): %m", scriptName); - exit (0); + exit(0); } if (ip) @@ -2142,7 +2150,7 @@ script_set_env(struct client_state *client, const char *prefix, int i, namelen; namelen = strlen(name); - + for (i = 0; client->scriptEnv[i]; i++) if (strncmp(client->scriptEnv[i], name, namelen) == 0 && client->scriptEnv[i][namelen] == '=') @@ -2176,7 +2184,7 @@ script_set_env(struct client_state *client, const char *prefix, + strlen(value) + 1); if (client->scriptEnv[i] == NULL) error("script_set_env: no memory for variable assignment"); - + snprintf(client->scriptEnv[i], strlen(prefix) + strlen(name) + 1 + strlen(value) + 1, "%s%s=%s", prefix, name, value); } @@ -2185,7 +2193,7 @@ void script_flush_env(struct client_state *client) { int i; - + for (i = 0; client->scriptEnv[i]; i++) { free(client->scriptEnv[i]); client->scriptEnv[i] = NULL; @@ -2210,7 +2218,7 @@ dhcp_option_ev_name(char *buf, size_t buflen, struct option *option) buf[i] = 0; return 1; } - + void go_daemon(void) { @@ -2219,7 +2227,7 @@ go_daemon(void) /* Don't become a daemon if the user requested otherwise. */ if (no_daemon) { - write_client_pid_file (); + write_client_pid_file(); return; } @@ -2233,9 +2241,9 @@ go_daemon(void) /* Become a daemon... */ if ((pid = fork()) < 0) - error ("Can't fork daemon: %m"); + error("Can't fork daemon: %m"); else if (pid) - exit (0); + exit(0); /* Become session leader and get pid... */ pid = setsid(); @@ -2260,11 +2268,11 @@ write_client_pid_file() return; } - pf = fdopen (pfdesc, "w"); + pf = fdopen(pfdesc, "w"); if (!pf) warn("Can't fdopen %s: %m", path_dhclient_pid); else { - fprintf(pf, "%ld\n", (long)getpid ()); + fprintf(pf, "%ld\n", (long)getpid()); fclose(pf); } } @@ -2274,15 +2282,15 @@ check_option(struct client_lease *l, int option) { char *opbuf; char *sbuf; - + /* we use this, since this is what gets passed to dhclient-script */ - + opbuf = pretty_print_option(option, l->options[option].data, l->options[option].len, 0, 0); sbuf = option_as_string(option, l->options[option].data, l->options[option].len); - + switch(option) { case DHO_SUBNET_MASK : case DHO_TIME_SERVERS : @@ -2300,7 +2308,7 @@ check_option(struct client_lease *l, int option) case DHO_NTP_SERVERS : case DHO_NETBIOS_NAME_SERVERS : case DHO_NETBIOS_DD_SERVER : - case DHO_FONT_SERVERS : + case DHO_FONT_SERVERS : case DHO_DHCP_SERVER_IDENTIFIER : /* These should be a list of one or more IP addresses, * separated by spaces. If they aren't, this lease is not @@ -2308,9 +2316,9 @@ check_option(struct client_lease *l, int option) */ if (!ipv4addrs(opbuf)) { warn("Invalid IP address in option: %s", opbuf); - return(0); + return (0); } - return(1) ; + return (1) ; case DHO_HOST_NAME : case DHO_DOMAIN_NAME : case DHO_NIS_DOMAIN : @@ -2318,9 +2326,9 @@ check_option(struct client_lease *l, int option) if (!res_hnok(sbuf)) { warn("Bogus Host Name option %d: %s (%s)", option, sbuf, opbuf); - return(0); + return (0); } - return(1); + return (1); case DHO_PAD : case DHO_TIME_OFFSET : case DHO_BOOT_SIZE : @@ -2376,10 +2384,10 @@ int res_hnok(const char *dn) { int pch = PERIOD, ch = *dn++; - + while (ch != '\0') { int nch = *dn++; - + if (periodchar(ch)) { ; } else if (periodchar(pch)) { @@ -2397,8 +2405,8 @@ res_hnok(const char *dn) return (1); } -/* Does buf consist only of dotted decimal ipv4 addrs? - * return how many if so, +/* Does buf consist only of dotted decimal ipv4 addrs? + * return how many if so, * otherwise, return 0 */ int @@ -2406,12 +2414,12 @@ ipv4addrs(char * buf) { struct in_addr jnk; int count = 0; - + while (inet_aton(buf, &jnk) == 1){ count++; - while (periodchar(*buf) || digitchar(*buf)) + while (periodchar(*buf) || digitchar(*buf)) buf++; - if (*buf == '\0') + if (*buf == '\0') return(count); while (*buf == ' ') buf++; @@ -2432,11 +2440,11 @@ option_as_string(unsigned int code, unsigned char *data, int len) /* Code should be between 0 and 255. */ if (code > 255) - error ("option_as_string: bad code %d\n", code); + error("option_as_string: bad code %d\n", code); for (; dp < data + len; dp++) { - if (!isascii (*dp) || - !isprint (*dp)) { + if (!isascii(*dp) || + !isprint(*dp)) { if (dp + 1 != data + len || *dp != 0) { snprintf(op, opleft, @@ -2462,6 +2470,6 @@ option_as_string(unsigned int code, unsigned char *data, int len) *op = 0; return optbuf; toobig: - warn ("dhcp option too large"); - return "<error>"; + warn("dhcp option too large"); + return "<error>"; } diff --git a/sbin/dhclient/dhcp.h b/sbin/dhclient/dhcp.h index 0ea1991eddc..d90905b697a 100644 --- a/sbin/dhclient/dhcp.h +++ b/sbin/dhclient/dhcp.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dhcp.h,v 1.2 2004/02/04 12:16:56 henning Exp $ */ +/* $OpenBSD: dhcp.h,v 1.3 2004/02/07 13:26:35 henning Exp $ */ /* Protocol structures... */ @@ -40,8 +40,8 @@ * Enterprises, see ``http://www.vix.com''. */ -#define DHCP_UDP_OVERHEAD (14 + /* Ethernet header */ \ - 20 + /* IP header */ \ +#define DHCP_UDP_OVERHEAD (14 + /* Ethernet header */ \ + 20 + /* IP header */ \ 8) /* UDP header */ #define DHCP_SNAME_LEN 64 #define DHCP_FILE_LEN 128 @@ -66,16 +66,16 @@ struct dhcp_packet { struct in_addr yiaddr; /* Client IP address */ struct in_addr siaddr; /* IP address of next server to talk to */ struct in_addr giaddr; /* DHCP relay agent IP address */ - unsigned char chaddr [16]; /* Client hardware address */ - char sname [DHCP_SNAME_LEN]; /* Server name */ - char file [DHCP_FILE_LEN]; /* Boot filename */ - unsigned char options [DHCP_OPTION_LEN]; + unsigned char chaddr[16]; /* Client hardware address */ + char sname[DHCP_SNAME_LEN]; /* Server name */ + char file[DHCP_FILE_LEN]; /* Boot filename */ + unsigned char options[DHCP_OPTION_LEN]; /* Optional parameters (actual length dependent on MTU). */ }; /* BOOTP (rfc951) message types */ -#define BOOTREQUEST 1 +#define BOOTREQUEST 1 #define BOOTREPLY 2 /* Possible values for flags field... */ diff --git a/sbin/dhclient/dhcpd.h b/sbin/dhclient/dhcpd.h index 75a4a41cf5a..2e3397644c1 100644 --- a/sbin/dhclient/dhcpd.h +++ b/sbin/dhclient/dhcpd.h @@ -1,4 +1,4 @@ -/* $OpenBSD: dhcpd.h,v 1.3 2004/02/04 12:16:56 henning Exp $ */ +/* $OpenBSD: dhcpd.h,v 1.4 2004/02/07 13:26:35 henning Exp $ */ /* Definitions for dhcpd... */ @@ -98,7 +98,7 @@ struct packet { struct hardware *haddr; /* Physical link address of local sender (maybe gateway). */ struct shared_network *shared_network; - struct option_data options [256]; + struct option_data options[256]; int got_requested_address; /* True if client sent the dhcp-requested-address option. */ }; @@ -106,7 +106,7 @@ struct packet { struct hardware { u_int8_t htype; u_int8_t hlen; - u_int8_t haddr [16]; + u_int8_t haddr[16]; }; /* A dhcp lease declaration structure. */ @@ -121,7 +121,7 @@ struct lease { unsigned char *uid; int uid_len; int uid_max; - unsigned char uid_buf [32]; + unsigned char uid_buf[32]; char *hostname; char *client_hostname; struct host_decl *host; @@ -149,9 +149,9 @@ struct lease_state { TIME offered_expiry; - struct tree_cache *options [256]; + struct tree_cache *options[256]; u_int32_t expiry, renewal, rebind; - char filename [DHCP_FILE_LEN]; + char filename[DHCP_FILE_LEN]; char *server_name; struct iaddr from; @@ -175,12 +175,12 @@ struct lease_state { u_int8_t offer; }; -#define ROOT_GROUP 0 +#define ROOT_GROUP 0 #define HOST_DECL 1 #define SHARED_NET_DECL 2 #define SUBNET_DECL 3 #define CLASS_DECL 4 -#define GROUP_DECL 5 +#define GROUP_DECL 5 /* Possible modes in which discover_interfaces can run. */ @@ -203,7 +203,7 @@ struct group { TIME bootp_lease_length; char *filename; - char *server_name; + char *server_name; struct iaddr next_server; int boot_unknown_clients; @@ -217,7 +217,7 @@ struct group { int authoritative; int always_reply_rfc1048; - struct tree_cache *options [256]; + struct tree_cache *options[256]; }; /* A dhcp host declaration structure. */ @@ -269,9 +269,9 @@ struct client_lease { struct string_list *medium; /* Network medium. */ unsigned int is_static : 1; /* If set, lease is from config file. */ - unsigned int is_bootp: 1; /* If set, lease was aquired with BOOTP. */ + unsigned int is_bootp : 1; /* If set, lease was aquired with BOOTP. */ - struct option_data options [256]; /* Options supplied with lease. */ + struct option_data options[256]; /* Options supplied with lease. */ }; /* Possible states in which the client can be. */ @@ -279,7 +279,7 @@ enum dhcp_state { S_REBOOTING, S_INIT, S_SELECTING, - S_REQUESTING, + S_REQUESTING, S_BOUND, S_RENEWING, S_REBINDING @@ -287,18 +287,18 @@ enum dhcp_state { /* Configuration information from the config file... */ struct client_config { - struct option_data defaults [256]; /* Default values for options. */ + struct option_data defaults[256]; /* Default values for options. */ enum { ACTION_DEFAULT, /* Use server value if present, otherwise default. */ ACTION_SUPERSEDE, /* Always use default. */ ACTION_PREPEND, /* Prepend default to server. */ ACTION_APPEND /* Append default to server. */ - } default_actions [256]; + } default_actions[256]; - struct option_data send_options [256]; /* Send these to server. */ - u_int8_t required_options [256]; /* Options server must supply. */ - u_int8_t requested_options [256]; /* Options to request from server. */ + struct option_data send_options[256]; /* Send these to server. */ + u_int8_t required_options[256]; /* Options server must supply. */ + u_int8_t requested_options[256]; /* Options to request from server. */ int requested_option_count; /* Number of requested options. */ TIME timeout; /* Start to panic if we don't get a lease in this time period when @@ -366,7 +366,7 @@ struct interface_info { /* Networks connected to this interface. */ struct hardware hw_address; /* Its physical address. */ struct in_addr primary_address; /* Primary interface address. */ - char name [IFNAMSIZ]; /* Its name... */ + char name[IFNAMSIZ]; /* Its name... */ int rfdesc; /* Its read file descriptor. */ int wfdesc; /* Its write file descriptor, if different. */ @@ -385,12 +385,12 @@ struct interface_info { int noifmedia; int errors; int dead; - u_int16_t index; + u_int16_t index; }; struct hardware_link { struct hardware_link *next; - char name [IFNAMSIZ]; + char name[IFNAMSIZ]; struct hardware address; }; @@ -404,19 +404,19 @@ struct timeout { struct protocol { struct protocol *next; int fd; - void (*handler) (struct protocol *); + void (*handler)(struct protocol *); void *local; }; /* Bitmask of dhcp option codes. */ -typedef unsigned char option_mask [16]; +typedef unsigned char option_mask[16]; /* DHCP Option mask manipulation macros... */ -#define OPTION_ZERO(mask) (memset (mask, 0, 16)) -#define OPTION_SET(mask, bit) (mask [bit >> 8] |= (1 << (bit & 7))) -#define OPTION_CLR(mask, bit) (mask [bit >> 8] &= ~(1 << (bit & 7))) -#define OPTION_ISSET(mask, bit) (mask [bit >> 8] & (1 << (bit & 7))) -#define OPTION_ISCLR(mask, bit) (!OPTION_ISSET (mask, bit)) +#define OPTION_ZERO(mask) (memset(mask, 0, 16)) +#define OPTION_SET(mask, bit) (mask[bit >> 8] |= (1 << (bit & 7))) +#define OPTION_CLR(mask, bit) (mask[bit >> 8] &= ~(1 << (bit & 7))) +#define OPTION_ISSET(mask, bit) (mask[bit >> 8] & (1 << (bit & 7))) +#define OPTION_ISCLR(mask, bit) (!OPTION_ISSET(mask, bit)) /* An option occupies its length plus two header bytes (code and length) for every 255 bytes that must be stored. */ @@ -439,26 +439,24 @@ typedef unsigned char option_mask [16]; /* options.c */ -void parse_options (struct packet *); -void parse_option_buffer (struct packet *, unsigned char *, int); -int cons_options (struct packet *, struct dhcp_packet *, int, - struct tree_cache **, int, int, int, - u_int8_t *, int); -int store_options (unsigned char *, int, struct tree_cache **, - unsigned char *, int, int, int, int); -char *pretty_print_option (unsigned int, - unsigned char *, int, int, int); -void do_packet (struct interface_info *, - struct dhcp_packet *, int, - unsigned int, struct iaddr, struct hardware *); +void parse_options(struct packet *); +void parse_option_buffer(struct packet *, unsigned char *, int); +int cons_options(struct packet *, struct dhcp_packet *, int, + struct tree_cache **, int, int, int, u_int8_t *, int); +int store_options(unsigned char *, int, struct tree_cache **, + unsigned char *, int, int, int, int); +char *pretty_print_option(unsigned int, + unsigned char *, int, int, int); +void do_packet(struct interface_info *, struct dhcp_packet *, + int, unsigned int, struct iaddr, struct hardware *); /* errwarn.c */ extern int warnings_occurred; -void error (char *, ...) __attribute__ ((__format__ (__printf__, 1, 2))); -int warn (char *, ...) __attribute__ ((__format__ (__printf__, 1, 2))); -int note (char *, ...) __attribute__ ((__format__ (__printf__, 1, 2))); -int debug (char *, ...) __attribute__ ((__format__ (__printf__, 1, 2))); -int parse_warn (char *, ...) __attribute__ ((__format__ (__printf__, 1, 2))); +void error(char *, ...) __attribute__ ((__format__ (__printf__, 1, 2))); +int warn(char *, ...) __attribute__ ((__format__ (__printf__, 1, 2))); +int note(char *, ...) __attribute__ ((__format__ (__printf__, 1, 2))); +int debug(char *, ...) __attribute__ ((__format__ (__printf__, 1, 2))); +int parse_warn(char *, ...) __attribute__ ((__format__ (__printf__, 1, 2))); /* dhcpd.c */ extern TIME cur_time; @@ -469,289 +467,273 @@ extern u_int16_t remote_port; extern int log_priority; extern int log_perror; -int main (int, char **); -void cleanup (void); +int main(int, char **); +void cleanup(void); /* conflex.c */ extern int lexline, lexchar; extern char *token_line, *tlname; -extern char comments [4096]; +extern char comments[4096]; extern int comment_index; extern int eol_token; -void new_parse (char *); -int next_token (char **, FILE *); -int peek_token (char **, FILE *); +void new_parse(char *); +int next_token(char **, FILE *); +int peek_token(char **, FILE *); /* confpars.c */ -int readconf (void); -void read_leases (void); -int parse_statement (FILE *, - struct group *, int, struct host_decl *, int); -void parse_allow_deny (FILE *, struct group *, int); -void skip_to_semi (FILE *); -int parse_boolean (FILE *); -int parse_semi (FILE *); -int parse_lbrace (FILE *); -void parse_host_declaration (FILE *, struct group *); -char *parse_host_name (FILE *); -void parse_class_declaration (FILE *, struct group *, int); -void parse_lease_time (FILE *, TIME *); -void parse_shared_net_declaration (FILE *, struct group *); -void parse_subnet_declaration (FILE *, struct shared_network *); -void parse_group_declaration (FILE *, struct group *); -void parse_hardware_param (FILE *, struct hardware *); -char *parse_string (FILE *); -struct tree *parse_ip_addr_or_hostname (FILE *, int); -struct tree_cache *parse_fixed_addr_param (FILE *); -void parse_option_param (FILE *, struct group *); -TIME parse_timestamp (FILE *); -struct lease *parse_lease_declaration (FILE *); -void parse_address_range (FILE *, struct subnet *); -TIME parse_date (FILE *); -unsigned char *parse_numeric_aggregate (FILE *, - unsigned char *, int *, - int, int, int); -void convert_num (unsigned char *, char *, int, int); +int readconf(void); +void read_leases(void); +int parse_statement(FILE *, struct group *, int, struct host_decl *, int); +void parse_allow_deny(FILE *, struct group *, int); +void skip_to_semi(FILE *); +int parse_boolean(FILE *); +int parse_semi(FILE *); +int parse_lbrace(FILE *); +void parse_host_declaration(FILE *, struct group *); +char *parse_host_name(FILE *); +void parse_class_declaration(FILE *, struct group *, int); +void parse_lease_time(FILE *, TIME *); +void parse_shared_net_declaration(FILE *, struct group *); +void parse_subnet_declaration(FILE *, struct shared_network *); +void parse_group_declaration(FILE *, struct group *); +void parse_hardware_param(FILE *, struct hardware *); +char *parse_string(FILE *); +struct tree *parse_ip_addr_or_hostname(FILE *, int); +struct tree_cache *parse_fixed_addr_param(FILE *); +void parse_option_param(FILE *, struct group *); +TIME parse_timestamp(FILE *); +struct lease *parse_lease_declaration(FILE *); +void parse_address_range(FILE *, struct subnet *); +TIME parse_date(FILE *); +unsigned char *parse_numeric_aggregate(FILE *, unsigned char *, int *, + int, int, int); +void convert_num(unsigned char *, char *, int, int); /* tree.c */ -pair cons (caddr_t, pair); -struct tree_cache *tree_cache (struct tree *); -struct tree *tree_host_lookup (char *); -struct dns_host_entry *enter_dns_host (char *); -struct tree *tree_const (unsigned char *, int); -struct tree *tree_concat (struct tree *, struct tree *); -struct tree *tree_limit (struct tree *, int); -int tree_evaluate (struct tree_cache *); +pair cons(caddr_t, pair); +struct tree_cache *tree_cache(struct tree *); +struct tree *tree_host_lookup(char *); +struct dns_host_entry *enter_dns_host(char *); +struct tree *tree_const(unsigned char *, int); +struct tree *tree_concat(struct tree *, struct tree *); +struct tree *tree_limit(struct tree *, int); +int tree_evaluate(struct tree_cache *); /* dhcp.c */ extern int outstanding_pings; -void dhcp (struct packet *); -void dhcpdiscover (struct packet *); -void dhcprequest (struct packet *); -void dhcprelease (struct packet *); -void dhcpdecline (struct packet *); -void dhcpinform (struct packet *); -void nak_lease (struct packet *, struct iaddr *cip); -void ack_lease (struct packet *, struct lease *, unsigned int, TIME); -void dhcp_reply (struct lease *); -struct lease *find_lease (struct packet *, - struct shared_network *, int *); -struct lease *mockup_lease (struct packet *, - struct shared_network *, - struct host_decl *); +void dhcp(struct packet *); +void dhcpdiscover(struct packet *); +void dhcprequest(struct packet *); +void dhcprelease(struct packet *); +void dhcpdecline(struct packet *); +void dhcpinform(struct packet *); +void nak_lease(struct packet *, struct iaddr *cip); +void ack_lease(struct packet *, struct lease *, unsigned int, TIME); +void dhcp_reply(struct lease *); +struct lease *find_lease(struct packet *, struct shared_network *, int *); +struct lease *mockup_lease(struct packet *, struct shared_network *, + struct host_decl *); /* bootp.c */ -void bootp (struct packet *); +void bootp(struct packet *); /* memory.c */ -void enter_host (struct host_decl *); -struct host_decl *find_hosts_by_haddr (int, unsigned char *, int); -struct host_decl *find_hosts_by_uid (unsigned char *, int); -struct subnet *find_host_for_network (struct host_decl **, - struct iaddr *, - struct shared_network *); -void new_address_range (struct iaddr, struct iaddr, - struct subnet *, int); -extern struct subnet *find_grouped_subnet (struct shared_network *, - struct iaddr); -extern struct subnet *find_subnet (struct iaddr); -void enter_shared_network (struct shared_network *); -int subnet_inner_than (struct subnet *, struct subnet *, int); -void enter_subnet (struct subnet *); -void enter_lease (struct lease *); -int supersede_lease (struct lease *, struct lease *, int); -void release_lease (struct lease *); -void abandon_lease (struct lease *, char *); -struct lease *find_lease_by_uid (unsigned char *, int); -struct lease *find_lease_by_hw_addr (unsigned char *, int); -struct lease *find_lease_by_ip_addr (struct iaddr); -void uid_hash_add (struct lease *); -void uid_hash_delete (struct lease *); -void hw_hash_add (struct lease *); -void hw_hash_delete (struct lease *); -struct class *add_class (int, char *); -struct class *find_class (int, unsigned char *, int); -struct group *clone_group (struct group *, char *); -void write_leases (void); -void dump_subnets (void); +void enter_host(struct host_decl *); +struct host_decl *find_hosts_by_haddr(int, unsigned char *, int); +struct host_decl *find_hosts_by_uid(unsigned char *, int); +struct subnet *find_host_for_network(struct host_decl **, struct iaddr *, + struct shared_network *); +void new_address_range(struct iaddr, struct iaddr, struct subnet *, int); +extern struct subnet *find_grouped_subnet(struct shared_network *, + struct iaddr); +extern struct subnet *find_subnet(struct iaddr); +void enter_shared_network(struct shared_network *); +int subnet_inner_than(struct subnet *, struct subnet *, int); +void enter_subnet(struct subnet *); +void enter_lease(struct lease *); +int supersede_lease(struct lease *, struct lease *, int); +void release_lease(struct lease *); +void abandon_lease(struct lease *, char *); +struct lease *find_lease_by_uid(unsigned char *, int); +struct lease *find_lease_by_hw_addr(unsigned char *, int); +struct lease *find_lease_by_ip_addr(struct iaddr); +void uid_hash_add(struct lease *); +void uid_hash_delete(struct lease *); +void hw_hash_add(struct lease *); +void hw_hash_delete(struct lease *); +struct class *add_class(int, char *); +struct class *find_class(int, unsigned char *, int); +struct group *clone_group(struct group *, char *); +void write_leases(void); +void dump_subnets(void); /* alloc.c */ -VOIDPTR dmalloc (int, char *); -void dfree (VOIDPTR, char *); -struct packet *new_packet (char *); -struct dhcp_packet *new_dhcp_packet (char *); -struct tree *new_tree (char *); -struct tree_cache *new_tree_cache (char *); -struct hash_table *new_hash_table (int, char *); -struct hash_bucket *new_hash_bucket (char *); -struct lease *new_lease (char *); -struct lease *new_leases (int, char *); -struct subnet *new_subnet (char *); -struct class *new_class (char *); -struct shared_network *new_shared_network (char *); -struct group *new_group (char *); -struct protocol *new_protocol (char *); -struct lease_state *new_lease_state (char *); -struct domain_search_list *new_domain_search_list (char *); -struct name_server *new_name_server (char *); -struct string_list *new_string_list (size_t size, char * name); -void free_name_server (struct name_server *, char *); -void free_domain_search_list (struct domain_search_list *, char *); -void free_lease_state (struct lease_state *, char *); -void free_protocol (struct protocol *, char *); -void free_group (struct group *, char *); -void free_shared_network (struct shared_network *, char *); -void free_class (struct class *, char *); -void free_subnet (struct subnet *, char *); -void free_lease (struct lease *, char *); -void free_hash_bucket (struct hash_bucket *, char *); -void free_hash_table (struct hash_table *, char *); -void free_tree_cache (struct tree_cache *, char *); -void free_packet (struct packet *, char *); -void free_dhcp_packet (struct dhcp_packet *, char *); -void free_tree (struct tree *, char *); -void free_string_list (struct string_list *, char *); +VOIDPTR dmalloc(int, char *); +void dfree(VOIDPTR, char *); +struct packet *new_packet(char *); +struct dhcp_packet *new_dhcp_packet(char *); +struct tree *new_tree(char *); +struct tree_cache *new_tree_cache(char *); +struct hash_table *new_hash_table(int, char *); +struct hash_bucket *new_hash_bucket(char *); +struct lease *new_lease(char *); +struct lease *new_leases(int, char *); +struct subnet *new_subnet(char *); +struct class *new_class(char *); +struct shared_network *new_shared_network(char *); +struct group *new_group(char *); +struct protocol *new_protocol(char *); +struct lease_state *new_lease_state(char *); +struct domain_search_list *new_domain_search_list(char *); +struct name_server *new_name_server(char *); +struct string_list *new_string_list(size_t size, char * name); +void free_name_server(struct name_server *, char *); +void free_domain_search_list(struct domain_search_list *, char *); +void free_lease_state(struct lease_state *, char *); +void free_protocol(struct protocol *, char *); +void free_group(struct group *, char *); +void free_shared_network(struct shared_network *, char *); +void free_class(struct class *, char *); +void free_subnet(struct subnet *, char *); +void free_lease(struct lease *, char *); +void free_hash_bucket(struct hash_bucket *, char *); +void free_hash_table(struct hash_table *, char *); +void free_tree_cache(struct tree_cache *, char *); +void free_packet(struct packet *, char *); +void free_dhcp_packet(struct dhcp_packet *, char *); +void free_tree(struct tree *, char *); +void free_string_list(struct string_list *, char *); /* print.c */ -char *print_hw_addr (int, int, unsigned char *); -void print_lease (struct lease *); -void dump_raw (unsigned char *, int); -void dump_packet (struct packet *); -void hash_dump (struct hash_table *); +char *print_hw_addr(int, int, unsigned char *); +void print_lease(struct lease *); +void dump_raw(unsigned char *, int); +void dump_packet(struct packet *); +void hash_dump(struct hash_table *); /* socket.c */ -#if defined (USE_SOCKET_SEND) || defined (USE_SOCKET_RECEIVE) \ - || defined (USE_SOCKET_FALLBACK) -int if_register_socket (struct interface_info *); +#if defined(USE_SOCKET_SEND) || defined(USE_SOCKET_RECEIVE) \ + || defined(USE_SOCKET_FALLBACK) +int if_register_socket(struct interface_info *); #endif -#if defined (USE_SOCKET_FALLBACK) && !defined (USE_SOCKET_SEND) -void if_reinitialize_fallback (struct interface_info *); -void if_register_fallback (struct interface_info *); -ssize_t send_fallback (struct interface_info *, - struct packet *, struct dhcp_packet *, size_t, - struct in_addr, - struct sockaddr_in *, struct hardware *); +#if defined(USE_SOCKET_FALLBACK) && !defined(USE_SOCKET_SEND) +void if_reinitialize_fallback(struct interface_info *); +void if_register_fallback(struct interface_info *); +ssize_t send_fallback(struct interface_info *, + struct packet *, struct dhcp_packet *, size_t, struct in_addr, + struct sockaddr_in *, struct hardware *); #endif #ifdef USE_SOCKET_SEND -void if_reinitialize_send (struct interface_info *); -void if_register_send (struct interface_info *); -ssize_t send_packet (struct interface_info *, - struct packet *, struct dhcp_packet *, size_t, - struct in_addr, - struct sockaddr_in *, struct hardware *); +void if_reinitialize_send(struct interface_info *); +void if_register_send(struct interface_info *); +ssize_t send_packet(struct interface_info *, + struct packet *, struct dhcp_packet *, size_t, struct in_addr, + struct sockaddr_in *, struct hardware *); #endif -#if defined (USE_SOCKET_FALLBACK) -void fallback_discard (struct protocol *); +#ifdef USE_SOCKET_FALLBACK +void fallback_discard(struct protocol *); #endif #ifdef USE_SOCKET_RECEIVE -void if_reinitialize_receive (struct interface_info *); -void if_register_receive (struct interface_info *); -ssize_t receive_packet (struct interface_info *, - unsigned char *, size_t, - struct sockaddr_in *, struct hardware *); +void if_reinitialize_receive(struct interface_info *); +void if_register_receive(struct interface_info *); +ssize_t receive_packet(struct interface_info *, unsigned char *, size_t, + struct sockaddr_in *, struct hardware *); #endif -#if defined (USE_SOCKET_SEND) -int can_unicast_without_arp (void); -int can_receive_unicast_unconfigured (struct interface_info *); -void maybe_setup_fallback (void); +#ifdef USE_SOCKET_SEND +int can_unicast_without_arp(void); +int can_receive_unicast_unconfigured(struct interface_info *); +void maybe_setup_fallback(void); #endif /* bpf.c */ -#if defined (USE_BPF_SEND) || defined (USE_BPF_RECEIVE) -int if_register_bpf (struct interface_info *); +#if defined(USE_BPF_SEND) || defined(USE_BPF_RECEIVE) +int if_register_bpf(struct interface_info *); #endif #ifdef USE_BPF_SEND -void if_reinitialize_send (struct interface_info *); -void if_register_send (struct interface_info *); -ssize_t send_packet (struct interface_info *, - struct packet *, struct dhcp_packet *, size_t, - struct in_addr, - struct sockaddr_in *, struct hardware *); +void if_reinitialize_send(struct interface_info *); +void if_register_send(struct interface_info *); +ssize_t send_packet(struct interface_info *, + struct packet *, struct dhcp_packet *, size_t, struct in_addr, + struct sockaddr_in *, struct hardware *); #endif #ifdef USE_BPF_RECEIVE -void if_reinitialize_receive (struct interface_info *); -void if_register_receive (struct interface_info *); -ssize_t receive_packet (struct interface_info *, - unsigned char *, size_t, - struct sockaddr_in *, struct hardware *); +void if_reinitialize_receive(struct interface_info *); +void if_register_receive(struct interface_info *); +ssize_t receive_packet(struct interface_info *, unsigned char *, size_t, + struct sockaddr_in *, struct hardware *); #endif -#if defined (USE_BPF_SEND) -int can_unicast_without_arp (void); -int can_receive_unicast_unconfigured (struct interface_info *); -void maybe_setup_fallback (void); +#ifdef USE_BPF_SEND +int can_unicast_without_arp(void); +int can_receive_unicast_unconfigured(struct interface_info *); +void maybe_setup_fallback(void); #endif /* raw.c */ #ifdef USE_RAW_SEND -void if_reinitialize_send (struct interface_info *); -void if_register_send (struct interface_info *); -ssize_t send_packet (struct interface_info *, - struct packet *, struct dhcp_packet *, size_t, - struct in_addr, - struct sockaddr_in *, struct hardware *); -int can_unicast_without_arp (void); -int can_receive_unicast_unconfigured (struct interface_info *); -void maybe_setup_fallback (void); +void if_reinitialize_send(struct interface_info *); +void if_register_send(struct interface_info *); +ssize_t send_packet(struct interface_info *, + struct packet *, struct dhcp_packet *, size_t, struct in_addr, + struct sockaddr_in *, struct hardware *); +int can_unicast_without_arp(void); +int can_receive_unicast_unconfigured(struct interface_info *); +void maybe_setup_fallback(void); #endif /* dispatch.c */ extern struct interface_info *interfaces, - *dummy_interfaces, *fallback_interface; + *dummy_interfaces, *fallback_interface; extern struct protocol *protocols; extern int quiet_interface_discovery; -extern void (*bootp_packet_handler) (struct interface_info *, - struct dhcp_packet *, int, - unsigned int, - struct iaddr, struct hardware *); +extern void (*bootp_packet_handler)(struct interface_info *, + struct dhcp_packet *, int, unsigned int, struct iaddr, struct hardware *); extern struct timeout *timeouts; -void discover_interfaces (int); -struct interface_info *setup_fallback (void); -void reinitialize_interfaces (void); -void dispatch (void); -int locate_network (struct packet *); -void got_one (struct protocol *); -void add_timeout (TIME, void (*)(void *), void *); -void cancel_timeout (void (*) (void *), void *); -void add_protocol (char *, int, void (*)(struct protocol *), void *); - -void remove_protocol (struct protocol *); +void discover_interfaces(int); +struct interface_info *setup_fallback(void); +void reinitialize_interfaces(void); +void dispatch(void); +int locate_network(struct packet *); +void got_one(struct protocol *); +void add_timeout(TIME, void (*)(void *), void *); +void cancel_timeout(void (*)(void *), void *); +void add_protocol(char *, int, void (*)(struct protocol *), void *); +void remove_protocol(struct protocol *); /* hash.c */ -struct hash_table *new_hash (void); -void add_hash (struct hash_table *, unsigned char *, - int, unsigned char *); -void delete_hash_entry (struct hash_table *, unsigned char *, int); -unsigned char *hash_lookup (struct hash_table *, unsigned char *, int); +struct hash_table *new_hash(void); +void add_hash(struct hash_table *, unsigned char *, int, unsigned char *); +void delete_hash_entry(struct hash_table *, unsigned char *, int); +unsigned char *hash_lookup(struct hash_table *, unsigned char *, int); /* tables.c */ -extern struct option dhcp_options [256]; -extern unsigned char dhcp_option_default_priority_list []; +extern struct option dhcp_options[256]; +extern unsigned char dhcp_option_default_priority_list[]; extern int sizeof_dhcp_option_default_priority_list; -extern char *hardware_types [256]; +extern char *hardware_types[256]; extern struct hash_table universe_hash; extern struct universe dhcp_universe; -void initialize_universes (void); +void initialize_universes(void); /* convert.c */ -u_int32_t getULong (unsigned char *); -int32_t getLong (unsigned char *); -u_int16_t getUShort (unsigned char *); -int16_t getShort (unsigned char *); -void putULong (unsigned char *, u_int32_t); -void putLong (unsigned char *, int32_t); -void putUShort (unsigned char *, unsigned int); -void putShort (unsigned char *, int); +u_int32_t getULong(unsigned char *); +int32_t getLong(unsigned char *); +u_int16_t getUShort(unsigned char *); +int16_t getShort(unsigned char *); +void putULong(unsigned char *, u_int32_t); +void putLong(unsigned char *, int32_t); +void putUShort(unsigned char *, unsigned int); +void putShort(unsigned char *, int); /* inet.c */ -struct iaddr subnet_number (struct iaddr, struct iaddr); -struct iaddr ip_addr (struct iaddr, struct iaddr, u_int32_t); -struct iaddr broadcast_addr (struct iaddr, struct iaddr); -u_int32_t host_addr (struct iaddr, struct iaddr); -int addr_eq (struct iaddr, struct iaddr); -char *piaddr (struct iaddr); +struct iaddr subnet_number(struct iaddr, struct iaddr); +struct iaddr ip_addr(struct iaddr, struct iaddr, u_int32_t); +struct iaddr broadcast_addr(struct iaddr, struct iaddr); +u_int32_t host_addr(struct iaddr, struct iaddr); +int addr_eq(struct iaddr, struct iaddr); +char *piaddr(struct iaddr); /* dhclient.c */ extern char *path_dhclient_conf; @@ -761,161 +743,152 @@ extern int interfaces_requested; extern struct client_config top_level_config; -void dhcpoffer (struct packet *); -void dhcpack (struct packet *); -void dhcpnak (struct packet *); - -void send_discover (void *); -void send_request (void *); -void send_release (void *); -void send_decline (void *); - -void state_reboot (void *); -void state_init (void *); -void state_selecting (void *); -void state_requesting (void *); -void state_bound (void *); -void state_panic (void *); - -void bind_lease (struct interface_info *); - -void make_discover (struct interface_info *, struct client_lease *); -void make_request (struct interface_info *, struct client_lease *); -void make_decline (struct interface_info *, struct client_lease *); -void make_release (struct interface_info *, struct client_lease *); - -void free_client_lease (struct client_lease *); -void rewrite_client_leases (void); -void write_client_lease (struct interface_info *, - struct client_lease *, int); - -void script_init (struct interface_info *, char *, - struct string_list *); -void script_write_params (struct interface_info *, - char *, struct client_lease *); -int script_go (struct interface_info *); -void client_envadd (struct client_state *, - const char *, const char *, const char *, ...); -void script_set_env (struct client_state *, const char *, const char *, - const char *); +void dhcpoffer(struct packet *); +void dhcpack(struct packet *); +void dhcpnak(struct packet *); + +void send_discover(void *); +void send_request(void *); +void send_release(void *); +void send_decline(void *); + +void state_reboot(void *); +void state_init(void *); +void state_selecting(void *); +void state_requesting(void *); +void state_bound(void *); +void state_panic(void *); + +void bind_lease(struct interface_info *); + +void make_discover(struct interface_info *, struct client_lease *); +void make_request(struct interface_info *, struct client_lease *); +void make_decline(struct interface_info *, struct client_lease *); +void make_release(struct interface_info *, struct client_lease *); + +void free_client_lease(struct client_lease *); +void rewrite_client_leases(void); +void write_client_lease(struct interface_info *, struct client_lease *, int); + +void script_init(struct interface_info *, char *, struct string_list *); +void script_write_params(struct interface_info *, + char *, struct client_lease *); +int script_go(struct interface_info *); +void client_envadd(struct client_state *, + const char *, const char *, const char *, ...); +void script_set_env(struct client_state *, const char *, const char *, + const char *); void script_flush_env(struct client_state *); -int dhcp_option_ev_name (char *, size_t, struct option *); +int dhcp_option_ev_name(char *, size_t, struct option *); -struct client_lease *packet_to_lease (struct packet *); -void go_daemon (void); -void write_client_pid_file (void); -void client_location_changed (void); +struct client_lease *packet_to_lease(struct packet *); +void go_daemon(void); +void write_client_pid_file(void); +void client_location_changed(void); /* db.c */ -int write_lease (struct lease *); -int commit_leases (void); -void db_startup (void); -void new_lease_file (void); +int write_lease(struct lease *); +int commit_leases(void); +void db_startup(void); +void new_lease_file(void); /* packet.c */ -u_int32_t checksum (unsigned char *, unsigned, u_int32_t); -u_int32_t wrapsum (u_int32_t); -void assemble_hw_header (struct interface_info *, unsigned char *, - int *, struct hardware *); -void assemble_udp_ip_header (struct interface_info *, unsigned char *, - int *, u_int32_t, u_int32_t, unsigned int, - unsigned char *, int); -ssize_t decode_hw_header (struct interface_info *, unsigned char *, - int, struct hardware *); -ssize_t decode_udp_ip_header (struct interface_info *, unsigned char *, - int, struct sockaddr_in *, - unsigned char *, int); +u_int32_t checksum(unsigned char *, unsigned, u_int32_t); +u_int32_t wrapsum(u_int32_t); +void assemble_hw_header(struct interface_info *, unsigned char *, + int *, struct hardware *); +void assemble_udp_ip_header(struct interface_info *, unsigned char *, + int *, u_int32_t, u_int32_t, unsigned int, unsigned char *, int); +ssize_t decode_hw_header(struct interface_info *, unsigned char *, + int, struct hardware *); +ssize_t decode_udp_ip_header(struct interface_info *, unsigned char *, + int, struct sockaddr_in *, unsigned char *, int); /* ethernet.c */ -void assemble_ethernet_header (struct interface_info *, unsigned char *, - int *, struct hardware *); -ssize_t decode_ethernet_header (struct interface_info *, - unsigned char *, - int, struct hardware *); +void assemble_ethernet_header(struct interface_info *, unsigned char *, + int *, struct hardware *); +ssize_t decode_ethernet_header(struct interface_info *, unsigned char *, + int, struct hardware *); /* tr.c */ -void assemble_tr_header (struct interface_info *, unsigned char *, - int *, struct hardware *); -ssize_t decode_tr_header (struct interface_info *, - unsigned char *, - int, struct hardware *); +void assemble_tr_header(struct interface_info *, unsigned char *, + int *, struct hardware *); +ssize_t decode_tr_header(struct interface_info *, + unsigned char *, int, struct hardware *); /* dhxpxlt.c */ -void convert_statement (FILE *); -void convert_host_statement (FILE *, jrefproto); -void convert_host_name (FILE *, jrefproto); -void convert_class_statement (FILE *, jrefproto, int); -void convert_class_decl (FILE *, jrefproto); -void convert_lease_time (FILE *, jrefproto, char *); -void convert_shared_net_statement (FILE *, jrefproto); -void convert_subnet_statement (FILE *, jrefproto); -void convert_subnet_decl (FILE *, jrefproto); -void convert_host_decl (FILE *, jrefproto); -void convert_hardware_decl (FILE *, jrefproto); -void convert_hardware_addr (FILE *, jrefproto); -void convert_filename_decl (FILE *, jrefproto); -void convert_servername_decl (FILE *, jrefproto); -void convert_ip_addr_or_hostname (FILE *, jrefproto, int); -void convert_fixed_addr_decl (FILE *, jrefproto); -void convert_option_decl (FILE *, jrefproto); -void convert_timestamp (FILE *, jrefproto); -void convert_lease_statement (FILE *, jrefproto); -void convert_address_range (FILE *, jrefproto); -void convert_date (FILE *, jrefproto, char *); -void convert_numeric_aggregate (FILE *, jrefproto, int, int, int, int); -void indent (int); +void convert_statement(FILE *); +void convert_host_statement(FILE *, jrefproto); +void convert_host_name(FILE *, jrefproto); +void convert_class_statement(FILE *, jrefproto, int); +void convert_class_decl(FILE *, jrefproto); +void convert_lease_time(FILE *, jrefproto, char *); +void convert_shared_net_statement(FILE *, jrefproto); +void convert_subnet_statement(FILE *, jrefproto); +void convert_subnet_decl(FILE *, jrefproto); +void convert_host_decl(FILE *, jrefproto); +void convert_hardware_decl(FILE *, jrefproto); +void convert_hardware_addr(FILE *, jrefproto); +void convert_filename_decl(FILE *, jrefproto); +void convert_servername_decl(FILE *, jrefproto); +void convert_ip_addr_or_hostname(FILE *, jrefproto, int); +void convert_fixed_addr_decl(FILE *, jrefproto); +void convert_option_decl(FILE *, jrefproto); +void convert_timestamp(FILE *, jrefproto); +void convert_lease_statement(FILE *, jrefproto); +void convert_address_range(FILE *, jrefproto); +void convert_date(FILE *, jrefproto, char *); +void convert_numeric_aggregate(FILE *, jrefproto, int, int, int, int); +void indent(int); /* route.c */ -void add_route_direct (struct interface_info *, struct in_addr); -void add_route_net (struct interface_info *, struct in_addr, - struct in_addr); -void add_route_default_gateway (struct interface_info *, - struct in_addr); -void remove_routes (struct in_addr); -void remove_if_route (struct interface_info *, struct in_addr); -void remove_all_if_routes (struct interface_info *); -void set_netmask (struct interface_info *, struct in_addr); -void set_broadcast_addr (struct interface_info *, struct in_addr); -void set_ip_address (struct interface_info *, struct in_addr); +void add_route_direct(struct interface_info *, struct in_addr); +void add_route_net(struct interface_info *, struct in_addr, struct in_addr); +void add_route_default_gateway(struct interface_info *, struct in_addr); +void remove_routes(struct in_addr); +void remove_if_route(struct interface_info *, struct in_addr); +void remove_all_if_routes(struct interface_info *); +void set_netmask(struct interface_info *, struct in_addr); +void set_broadcast_addr(struct interface_info *, struct in_addr); +void set_ip_address(struct interface_info *, struct in_addr); /* clparse.c */ -int read_client_conf (void); -void read_client_leases (void); -void parse_client_statement (FILE *, struct interface_info *, - struct client_config *); -int parse_X (FILE *, u_int8_t *, int); -int parse_option_list (FILE *, u_int8_t *); -void parse_interface_declaration (FILE *, struct client_config *); -struct interface_info *interface_or_dummy (char *); -void make_client_state (struct interface_info *); -void make_client_config (struct interface_info *, - struct client_config *); -void parse_client_lease_statement (FILE *, int); -void parse_client_lease_declaration (FILE *, struct client_lease *, - struct interface_info **); -struct option *parse_option_decl (FILE *, struct option_data *); -void parse_string_list (FILE *, struct string_list **, int); -int parse_ip_addr (FILE *, struct iaddr *); -void parse_reject_statement (FILE *, struct client_config *); +int read_client_conf(void); +void read_client_leases(void); +void parse_client_statement(FILE *, struct interface_info *, + struct client_config *); +int parse_X(FILE *, u_int8_t *, int); +int parse_option_list(FILE *, u_int8_t *); +void parse_interface_declaration(FILE *, struct client_config *); +struct interface_info *interface_or_dummy(char *); +void make_client_state(struct interface_info *); +void make_client_config(struct interface_info *, struct client_config *); +void parse_client_lease_statement(FILE *, int); +void parse_client_lease_declaration(FILE *, struct client_lease *, + struct interface_info **); +struct option *parse_option_decl(FILE *, struct option_data *); +void parse_string_list(FILE *, struct string_list **, int); +int parse_ip_addr(FILE *, struct iaddr *); +void parse_reject_statement(FILE *, struct client_config *); /* dhcrelay.c */ -void relay (struct interface_info *, struct dhcp_packet *, int, - unsigned int, struct iaddr, struct hardware *); +void relay(struct interface_info *, struct dhcp_packet *, int, + unsigned int, struct iaddr, struct hardware *); /* icmp.c */ -void icmp_startup (int, void (*)(struct iaddr, u_int8_t *, int)); -int icmp_echorequest (struct iaddr *); -void icmp_echoreply (struct protocol *); +void icmp_startup(int, void (*)(struct iaddr, u_int8_t *, int)); +int icmp_echorequest(struct iaddr *); +void icmp_echoreply(struct protocol *); /* dns.c */ -void dns_startup (void); -int ns_inaddr_lookup (u_int16_t, struct iaddr); -void dns_packet (struct protocol *); +void dns_startup(void); +int ns_inaddr_lookup(u_int16_t, struct iaddr); +void dns_packet(struct protocol *); /* resolv.c */ -extern char path_resolv_conf []; +extern char path_resolv_conf[]; struct name_server *name_servers; struct domain_search_list *domains; -void read_resolv_conf (TIME); +void read_resolv_conf(TIME); struct sockaddr_in *pick_name_server (void); diff --git a/sbin/dhclient/errwarn.c b/sbin/dhclient/errwarn.c index adc1dd60adb..eb6d0f55b1a 100644 --- a/sbin/dhclient/errwarn.c +++ b/sbin/dhclient/errwarn.c @@ -1,4 +1,4 @@ -/* $OpenBSD: errwarn.c,v 1.4 2004/02/04 12:16:56 henning Exp $ */ +/* $OpenBSD: errwarn.c,v 1.5 2004/02/07 13:26:35 henning Exp $ */ /* Errors and warnings... */ @@ -40,9 +40,10 @@ * with Vixie Laboratories. */ -#include "dhcpd.h" #include <errno.h> +#include "dhcpd.h" + static void do_percentm(char *obuf, size_t size, char *ibuf); static char mbuf[1024]; @@ -50,8 +51,9 @@ static char fbuf[1024]; int warnings_occurred; -/* Log an error message, then exit... */ - +/* + * Log an error message, then exit. + */ void error(char *fmt, ...) { @@ -60,7 +62,7 @@ error(char *fmt, ...) do_percentm(fbuf, sizeof(fbuf), fmt); va_start(list, fmt); - vsnprintf(mbuf, sizeof mbuf, fbuf, list); + vsnprintf(mbuf, sizeof(mbuf), fbuf, list); va_end(list); #ifndef DEBUG @@ -69,8 +71,8 @@ error(char *fmt, ...) /* Also log it to stderr? */ if (log_perror) { - write (2, mbuf, strlen(mbuf)); - write (2, "\n", 1); + write(2, mbuf, strlen(mbuf)); + write(2, "\n", 1); } syslog(LOG_CRIT, "exiting."); @@ -82,82 +84,87 @@ error(char *fmt, ...) exit(1); } -/* Log a warning message... */ - +/* + * Log a warning message... + */ int -warn(char * fmt, ...) +warn(char *fmt, ...) { va_list list; do_percentm(fbuf, sizeof(fbuf), fmt); va_start(list, fmt); - vsnprintf(mbuf, sizeof mbuf, fbuf, list); - va_end(list); + vsnprintf(mbuf, sizeof(mbuf), fbuf, list); + va_end(list); #ifndef DEBUG syslog(log_priority | LOG_ERR, "%s", mbuf); #endif if (log_perror) { - write (2, mbuf, strlen (mbuf)); - write (2, "\n", 1); + write(2, mbuf, strlen(mbuf)); + write(2, "\n", 1); } - return 0; + return (0); } -/* Log a note... */ +/* + * Log a note... + */ int -note(char * fmt, ...) +note(char *fmt, ...) { va_list list; do_percentm(fbuf, sizeof(fbuf), fmt); va_start(list, fmt); - vsnprintf(mbuf, sizeof mbuf, fbuf, list); - va_end(list); + vsnprintf(mbuf, sizeof(mbuf), fbuf, list); + va_end(list); #ifndef DEBUG - syslog (log_priority | LOG_INFO, "%s", mbuf); + syslog(log_priority | LOG_INFO, "%s", mbuf); #endif if (log_perror) { - write (2, mbuf, strlen (mbuf)); - write (2, "\n", 1); + write(2, mbuf, strlen(mbuf)); + write(2, "\n", 1); } - return 0; + return (0); } -/* Log a debug message... */ - +/* + * Log a debug message... + */ int -debug(char * fmt, ...) +debug(char *fmt, ...) { va_list list; do_percentm(fbuf, sizeof(fbuf), fmt); va_start(list, fmt); - vsnprintf(mbuf, sizeof mbuf, fbuf, list); + vsnprintf(mbuf, sizeof(mbuf), fbuf, list); va_end(list); #ifndef DEBUG - syslog (log_priority | LOG_DEBUG, "%s", mbuf); + syslog(log_priority | LOG_DEBUG, "%s", mbuf); #endif if (log_perror) { - write (2, mbuf, strlen (mbuf)); - write (2, "\n", 1); + write(2, mbuf, strlen(mbuf)); + write(2, "\n", 1); } - return 0; + return (0); } -/* Find %m in the input string and substitute an error message string. */ - +/* + * Find %m in the input string and substitute an error message string. + */ static void do_percentm(char *obuf, size_t size, char *ibuf) { @@ -168,8 +175,8 @@ do_percentm(char *obuf, size_t size, char *ibuf) size_t fmt_left; int saved_errno = errno; - /* - * We wouldn't need this mess if printf handled %m, or if + /* + * We wouldn't need this mess if printf handled %m, or if * strerror() had been invented before syslog(). */ for (fmt_left = size; (ch = *s); ++s) { @@ -191,17 +198,18 @@ do_percentm(char *obuf, size_t size, char *ibuf) *t = '\0'; } - int -parse_warn(char * fmt, ...) +parse_warn(char *fmt, ...) { va_list list; - static char spaces[] = " "; - + static char spaces[] = + " " + " "; /* 80 spaces */ + do_percentm(mbuf, sizeof(mbuf), fmt); - snprintf(fbuf, sizeof fbuf, "%s line %d: %s", tlname, lexline, mbuf); + snprintf(fbuf, sizeof(fbuf), "%s line %d: %s", tlname, lexline, mbuf); va_start(list, fmt); - vsnprintf(mbuf, sizeof mbuf, fbuf, list); + vsnprintf(mbuf, sizeof(mbuf), fbuf, list); va_end(list); #ifndef DEBUG @@ -209,19 +217,19 @@ parse_warn(char * fmt, ...) syslog(log_priority | LOG_ERR, "%s", token_line); if (lexline < 81) syslog(log_priority | LOG_ERR, - "%s^", &spaces [sizeof spaces - lexchar]); + "%s^", &spaces[sizeof(spaces) - lexchar]); #endif if (log_perror) { - write (2, mbuf, strlen (mbuf)); - write (2, "\n", 1); - write (2, token_line, strlen (token_line)); - write (2, "\n", 1); - write (2, spaces, lexchar - 1); - write (2, "^\n", 2); + write(2, mbuf, strlen(mbuf)); + write(2, "\n", 1); + write(2, token_line, strlen(token_line)); + write(2, "\n", 1); + write(2, spaces, lexchar - 1); + write(2, "^\n", 2); } warnings_occurred = 1; - return 0; + return (0); } diff --git a/sbin/dhclient/ethernet.c b/sbin/dhclient/ethernet.c index d2c83b9ce42..d15b9c8b92b 100644 --- a/sbin/dhclient/ethernet.c +++ b/sbin/dhclient/ethernet.c @@ -1,4 +1,4 @@ -/* $OpenBSD: ethernet.c,v 1.3 2004/02/04 12:16:56 henning Exp $ */ +/* $OpenBSD: ethernet.c,v 1.4 2004/02/07 13:26:35 henning Exp $ */ /* Packet assembly code, originally contributed by Archie Cobbs. */ @@ -43,10 +43,10 @@ #include "dhcpd.h" #include <netinet/if_ether.h> -#define ETHER_HEADER_SIZE (ETHER_ADDR_LEN * 2 + sizeof (u_int16_t)) +#define ETHER_HEADER_SIZE (ETHER_ADDR_LEN * 2 + sizeof(u_int16_t)) -/* Assemble an hardware header... */ -/* XXX currently only supports ethernet; doesn't check for other types. */ +/* Assemble a hardware header... */ +/* XXX: currently only supports ethernet; doesn't check for other types. */ void assemble_ethernet_header(struct interface_info *interface, unsigned char *buf, @@ -54,10 +54,10 @@ assemble_ethernet_header(struct interface_info *interface, unsigned char *buf, { struct ether_header eh; - if (to && to -> hlen == 6) /* XXX */ - memcpy(eh.ether_dhost, to -> haddr, sizeof eh.ether_dhost); + if (to != NULL && to->hlen == 6) /* XXX */ + memcpy(eh.ether_dhost, to->haddr, sizeof(eh.ether_dhost)); else - memset(eh.ether_dhost, 0xff, sizeof (eh.ether_dhost)); + memset(eh.ether_dhost, 0xff, sizeof(eh.ether_dhost)); if (interface->hw_address.hlen == sizeof(eh.ether_shost)) memcpy(eh.ether_shost, interface->hw_address.haddr, sizeof(eh.ether_shost)); @@ -82,7 +82,7 @@ decode_ethernet_header(struct interface_info *interface, unsigned char *buf, memcpy(from->haddr, eh.ether_shost, sizeof(eh.ether_shost)); from->htype = ARPHRD_ETHER; - from->hlen = sizeof eh.ether_shost; + from->hlen = sizeof(eh.ether_shost); - return sizeof eh; + return (sizeof(eh)); } diff --git a/sbin/dhclient/hash.c b/sbin/dhclient/hash.c index c8bec57baec..abf3673ccd1 100644 --- a/sbin/dhclient/hash.c +++ b/sbin/dhclient/hash.c @@ -1,4 +1,4 @@ -/* $OpenBSD: hash.c,v 1.3 2004/02/04 12:16:56 henning Exp $ */ +/* $OpenBSD: hash.c,v 1.4 2004/02/07 13:26:35 henning Exp $ */ /* Routines for manipulating hash tables... */ @@ -49,10 +49,10 @@ new_hash(void) { struct hash_table *rv = new_hash_table(DEFAULT_HASH_SIZE, "new_hash"); if (!rv) - return rv; - memset(&rv->buckets [0], 0, + return (rv); + memset(&rv->buckets[0], 0, DEFAULT_HASH_SIZE * sizeof(struct hash_bucket *)); - return rv; + return (rv); } static int @@ -81,7 +81,7 @@ void add_hash(struct hash_table *table, unsigned char *name, int len, if (!table) return; if (!len) - len = strlen ((char *)name); + len = strlen((char *)name); hashno = do_hash(name, len, table->hash_count); bp = new_hash_bucket("add_hash"); @@ -92,7 +92,7 @@ void add_hash(struct hash_table *table, unsigned char *name, int len, } bp->name = name; bp->value = pointer; - bp->next = table->buckets [hashno]; + bp->next = table->buckets[hashno]; bp->len = len; table->buckets[hashno] = bp; } @@ -101,25 +101,27 @@ void delete_hash_entry(struct hash_table *table, unsigned char *name, int len) { int hashno; - struct hash_bucket *bp, *pbp = (struct hash_bucket *)0; + struct hash_bucket *bp, *pbp = NULL; if (!table) return; if (!len) - len = strlen ((char *)name); + len = strlen((char *)name); hashno = do_hash(name, len, table->hash_count); - /* Go through the list looking for an entry that matches; - if we find it, delete it. */ - for (bp = table->buckets [hashno]; bp; bp = bp->next) { + /* + * Go through the list looking for an entry that matches; if we + * find it, delete it. + */ + for (bp = table->buckets[hashno]; bp; bp = bp->next) { if ((!bp->len && - !strcmp ((char *)bp->name, (char *)name)) || - (bp->len == len && !memcmp (bp->name, name, len))) { + !strcmp((char *)bp->name, (char *)name)) || + (bp->len == len && !memcmp(bp->name, name, len))) { if (pbp) pbp->next = bp->next; else - table->buckets [hashno] = bp->next; + table->buckets[hashno] = bp->next; free_hash_bucket(bp, "delete_hash_entry"); break; } @@ -134,16 +136,16 @@ hash_lookup (struct hash_table *table, unsigned char *name, int len) struct hash_bucket *bp; if (!table) - return (unsigned char *)0; + return (NULL); if (!len) - len = strlen ((char *)name); + len = strlen((char *)name); hashno = do_hash(name, len, table->hash_count); - for (bp = table->buckets [hashno]; bp; bp = bp->next) - if (len == bp->len && !memcmp (bp->name, name, len)) - return bp->value; + for (bp = table->buckets[hashno]; bp; bp = bp->next) + if (len == bp->len && !memcmp(bp->name, name, len)) + return (bp->value); return (NULL); } diff --git a/sbin/dhclient/hash.h b/sbin/dhclient/hash.h index ba30b8477f1..0f5ff56273c 100644 --- a/sbin/dhclient/hash.h +++ b/sbin/dhclient/hash.h @@ -1,4 +1,4 @@ -/* $OpenBSD: hash.h,v 1.2 2004/02/04 12:16:56 henning Exp $ */ +/* $OpenBSD: hash.h,v 1.3 2004/02/07 13:26:35 henning Exp $ */ /* Definitions for hashing... */ @@ -40,7 +40,7 @@ * Enterprises, see ``http://www.vix.com''. */ -#define DEFAULT_HASH_SIZE 97 +#define DEFAULT_HASH_SIZE 97 struct hash_bucket { struct hash_bucket *next; @@ -51,6 +51,5 @@ struct hash_bucket { struct hash_table { int hash_count; - struct hash_bucket *buckets [DEFAULT_HASH_SIZE]; + struct hash_bucket *buckets[DEFAULT_HASH_SIZE]; }; - diff --git a/sbin/dhclient/icmp.c b/sbin/dhclient/icmp.c index 4d2486d86cf..fb59c04d09c 100644 --- a/sbin/dhclient/icmp.c +++ b/sbin/dhclient/icmp.c @@ -1,7 +1,8 @@ -/* $OpenBSD: icmp.c,v 1.3 2004/02/04 12:16:56 henning Exp $ */ +/* $OpenBSD: icmp.c,v 1.4 2004/02/07 13:26:35 henning Exp $ */ -/* ICMP Protocol engine - for sending out pings and receiving - responses. */ +/* + * ICMP Protocol engine - for sending out pings and receiving responses. + */ /* * Copyright (c) 1997, 1998 The Internet Software Consortium. @@ -49,8 +50,9 @@ static int icmp_protocol_initialized; static int icmp_protocol_fd; -/* Initialize the ICMP protocol. */ - +/* + * Initialize the ICMP protocol. + */ void icmp_startup(int routep, void (*handler)(struct iaddr, u_int8_t *, int)) { @@ -64,19 +66,19 @@ icmp_startup(int routep, void (*handler)(struct iaddr, u_int8_t *, int)) icmp_protocol_initialized = 1; /* Get the protocol number (should be 1). */ - proto = getprotobyname ("icmp"); + proto = getprotobyname("icmp"); if (proto) protocol = proto->p_proto; /* Get a raw socket for the ICMP protocol. */ - icmp_protocol_fd = socket (AF_INET, SOCK_RAW, protocol); + icmp_protocol_fd = socket(AF_INET, SOCK_RAW, protocol); if (icmp_protocol_fd < 0) - error ("unable to create icmp socket: %m"); + error("unable to create icmp socket: %m"); /* Make sure it does routing... */ state = 0; if (setsockopt(icmp_protocol_fd, SOL_SOCKET, SO_DONTROUTE, - (char *)&state, sizeof state) < 0) + (char *)&state, sizeof(state)) < 0) error("Unable to disable SO_DONTROUTE on ICMP socket: %m"); add_protocol("icmp", icmp_protocol_fd, icmp_echoreply, (void *)handler); @@ -92,35 +94,35 @@ icmp_echorequest (struct iaddr *addr) if (!icmp_protocol_initialized) error("attempt to use ICMP protocol before initialization."); - memset(&to, 0, sizeof to); - to.sin_len = sizeof to; + memset(&to, 0, sizeof(to)); + to.sin_len = sizeof(to); to.sin_family = AF_INET; to.sin_port = 0; - memcpy (&to.sin_addr, addr->iabuf, sizeof to.sin_addr); /* XXX */ + memcpy(&to.sin_addr, addr->iabuf, sizeof(to.sin_addr)); /* XXX */ icmp.icmp_type = ICMP_ECHO; icmp.icmp_code = 0; icmp.icmp_cksum = 0; icmp.icmp_seq = 0; #ifdef PTRSIZE_64BIT - icmp.icmp_id = (((u_int32_t)(u_int64_t)addr) ^ - (u_int32_t)(((u_int64_t)addr) >> 32)); + icmp.icmp_id = ((u_int32_t)(u_int64_t)addr) ^ + (u_int32_t)(((u_int64_t)addr) >> 32); #else icmp.icmp_id = (u_int32_t)addr; #endif icmp.icmp_cksum = wrapsum(checksum((unsigned char *)&icmp, - sizeof icmp, 0)); + sizeof(icmp), 0)); /* Send the ICMP packet... */ - status = sendto (icmp_protocol_fd, (char *)&icmp, sizeof icmp, 0, - (struct sockaddr *)&to, sizeof to); + status = sendto(icmp_protocol_fd, (char *)&icmp, sizeof(icmp), 0, + (struct sockaddr *)&to, sizeof(to)); if (status < 0) warn("icmp_echorequest %s: %m", inet_ntoa(to.sin_addr)); - if (status != sizeof icmp) - return 0; - return 1; + if (status != sizeof(icmp)) + return (0); + return (1); } void @@ -128,26 +130,26 @@ icmp_echoreply(struct protocol *protocol) { struct icmp *icfrom; struct sockaddr_in from; - u_int8_t icbuf [1500]; + u_int8_t icbuf[1500]; int status, len; socklen_t salen; struct iaddr ia; void (*handler)(struct iaddr, u_int8_t *, int); - salen = sizeof from; - status = recvfrom (protocol->fd, (char *)icbuf, sizeof icbuf, 0, - (struct sockaddr *)&from, &salen); + salen = sizeof(from); + status = recvfrom(protocol->fd, (char *)icbuf, sizeof(icbuf), 0, + (struct sockaddr *)&from, &salen); if (status < 0) { - warn ("icmp_echoreply: %m"); + warn("icmp_echoreply: %m"); return; } /* Probably not for us. */ - if (status < (sizeof (struct ip)) + (sizeof *icfrom)) + if (status < sizeof(struct ip) + sizeof(*icfrom)) return; - len = status - sizeof (struct ip); - icfrom = (struct icmp *)(icbuf + sizeof (struct ip)); + len = status - sizeof(struct ip); + icfrom = (struct icmp *)(icbuf + sizeof(struct ip)); /* Silently discard ICMP packets that aren't echoreplies. */ if (icfrom->icmp_type != ICMP_ECHOREPLY) @@ -155,11 +157,11 @@ icmp_echoreply(struct protocol *protocol) /* If we were given a second-stage handler, call it. */ if (protocol->local) { - handler = ((void (*)(struct iaddr, u_int8_t *, int)) - protocol->local); - memcpy (ia.iabuf, &from.sin_addr, sizeof from.sin_addr); - ia.len = sizeof from.sin_addr; + handler = (void (*)(struct iaddr, u_int8_t *, int)) + protocol->local; + memcpy(ia.iabuf, &from.sin_addr, sizeof(from.sin_addr)); + ia.len = sizeof(from.sin_addr); - (*handler) (ia, icbuf, len); + (*handler)(ia, icbuf, len); } } diff --git a/sbin/dhclient/inet.c b/sbin/dhclient/inet.c index 31580c6a139..20494bd500a 100644 --- a/sbin/dhclient/inet.c +++ b/sbin/dhclient/inet.c @@ -1,7 +1,9 @@ -/* $OpenBSD: inet.c,v 1.3 2004/02/04 12:16:56 henning Exp $ */ +/* $OpenBSD: inet.c,v 1.4 2004/02/07 13:26:35 henning Exp $ */ -/* Subroutines to manipulate internet addresses in a safely portable - way... */ +/* + * Subroutines to manipulate internet addresses in a safely portable + * way... + */ /* * Copyright (c) 1996 The Internet Software Consortium. All rights reserved. @@ -42,8 +44,9 @@ #include "dhcpd.h" -/* Return just the network number of an internet address... */ - +/* + * Return just the network number of an internet address... + */ struct iaddr subnet_number(struct iaddr addr, struct iaddr mask) { @@ -54,59 +57,62 @@ subnet_number(struct iaddr addr, struct iaddr mask) /* Both addresses must have the same length... */ if (addr.len != mask.len) - return rv; + return (rv); rv.len = addr.len; for (i = 0; i < rv.len; i++) - rv.iabuf [i] = addr.iabuf [i] & mask.iabuf [i]; - return rv; + rv.iabuf[i] = addr.iabuf[i] & mask.iabuf[i]; + return (rv); } -/* Combine a network number and a integer to produce an internet address. +/* + * Combine a network number and a integer to produce an internet address. * This won't work for subnets with more than 32 bits of host address, but - * maybe this isn't a problem. + * maybe this isn't a problem. */ - struct iaddr ip_addr(struct iaddr subnet, struct iaddr mask, u_int32_t host_address) { int i, j, k; u_int32_t swaddr; struct iaddr rv; - unsigned char habuf [sizeof swaddr]; + unsigned char habuf[sizeof(swaddr)]; swaddr = htonl(host_address); - memcpy(habuf, &swaddr, sizeof swaddr); + memcpy(habuf, &swaddr, sizeof(swaddr)); - /* Combine the subnet address and the host address. If - the host address is bigger than can fit in the subnet, - return a zero-length iaddr structure. */ + /* + * Combine the subnet address and the host address. If the + * host address is bigger than can fit in the subnet, return a + * zero-length iaddr structure. + */ rv = subnet; - j = rv.len - sizeof habuf; - for (i = sizeof habuf - 1; i >= 0; i--) { - if (mask.iabuf [i + j]) { - if (habuf [i] > (mask.iabuf [i + j] ^ 0xFF)) { + j = rv.len - sizeof(habuf); + for (i = sizeof(habuf) - 1; i >= 0; i--) { + if (mask.iabuf[i + j]) { + if (habuf[i] > (mask.iabuf[i + j] ^ 0xFF)) { rv.len = 0; - return rv; + return (rv); } for (k = i - 1; k >= 0; k--) - if (habuf [k]) { + if (habuf[k]) { rv.len = 0; - return rv; + return (rv); } rv.iabuf[i + j] |= habuf[i]; break; } else rv.iabuf[i + j] = habuf[i]; } - - return rv; -} -/* Given a subnet number and netmask, return the address on that subnet - for which the host portion of the address is all ones (the standard - broadcast address). */ + return (rv); +} +/* + * Given a subnet number and netmask, return the address on that subnet + * for which the host portion of the address is all ones (the standard + * broadcast address). + */ struct iaddr broadcast_addr(struct iaddr subnet, struct iaddr mask) { @@ -115,14 +121,14 @@ broadcast_addr(struct iaddr subnet, struct iaddr mask) if (subnet.len != mask.len) { rv.len = 0; - return rv; + return (rv); } for (i = 0; i < subnet.len; i++) - rv.iabuf [i] = subnet.iabuf [i] | (~mask.iabuf [i] & 255); + rv.iabuf[i] = subnet.iabuf[i] | (~mask.iabuf[i] & 255); rv.len = subnet.len; - return rv; + return (rv); } u_int32_t @@ -137,21 +143,21 @@ host_addr(struct iaddr addr, struct iaddr mask) /* Mask out the network bits... */ rv.len = addr.len; for (i = 0; i < rv.len; i++) - rv.iabuf [i] = addr.iabuf [i] & ~mask.iabuf [i]; + rv.iabuf[i] = addr.iabuf[i] & ~mask.iabuf[i]; /* Copy out up to 32 bits... */ - memcpy(&swaddr, &rv.iabuf [rv.len - sizeof swaddr], sizeof swaddr); + memcpy(&swaddr, &rv.iabuf[rv.len - sizeof(swaddr)], sizeof(swaddr)); /* Swap it and return it. */ - return ntohl(swaddr); + return (ntohl(swaddr)); } int addr_eq(struct iaddr addr1, struct iaddr addr2) { if (addr1.len != addr2.len) - return 0; - return memcmp(addr1.iabuf, addr2.iabuf, addr1.len) == 0; + return (0); + return (memcmp(addr1.iabuf, addr2.iabuf, addr1.len) == 0); } char *piaddr(struct iaddr addr) @@ -159,17 +165,17 @@ char *piaddr(struct iaddr addr) static char pbuf[32]; char *s; struct in_addr a; - + memcpy(&a, &(addr.iabuf), sizeof(struct in_addr)); if (addr.len == 0) - strlcpy (pbuf, "<null address>", sizeof(pbuf)); + strlcpy(pbuf, "<null address>", sizeof(pbuf)); else { s = inet_ntoa(a); if (s != NULL) strlcpy(pbuf, s, sizeof(pbuf)); else - strlcpy (pbuf, "<invalid address>", sizeof(pbuf)); - } - return(pbuf); + strlcpy(pbuf, "<invalid address>", sizeof(pbuf)); + } + return (pbuf); } diff --git a/sbin/dhclient/inet.h b/sbin/dhclient/inet.h index 9a6968f141d..639d401d6fc 100644 --- a/sbin/dhclient/inet.h +++ b/sbin/dhclient/inet.h @@ -1,4 +1,4 @@ -/* $OpenBSD: inet.h,v 1.2 2004/02/04 12:16:56 henning Exp $ */ +/* $OpenBSD: inet.h,v 1.3 2004/02/07 13:26:35 henning Exp $ */ /* Portable definitions for internet addresses */ @@ -43,7 +43,7 @@ struct iaddr { int len; - unsigned char iabuf [16]; + unsigned char iabuf[16]; }; struct iaddrlist { diff --git a/sbin/dhclient/options.c b/sbin/dhclient/options.c index 66fd0fad7d0..1a713e93029 100644 --- a/sbin/dhclient/options.c +++ b/sbin/dhclient/options.c @@ -1,4 +1,4 @@ -/* $OpenBSD: options.c,v 1.3 2004/02/06 11:33:22 henning Exp $ */ +/* $OpenBSD: options.c,v 1.4 2004/02/07 13:26:35 henning Exp $ */ /* DHCP options parsing and reassembly. */ @@ -105,7 +105,7 @@ parse_option_buffer(struct packet *packet, /* Pad options don't have a length - just skip them. */ if (code == DHO_PAD) { - ++s; + s++; continue; } if (s + 2 > end) { @@ -150,8 +150,7 @@ parse_option_buffer(struct packet *packet, * space for it and copy it there. */ if (!packet->options[code].data) { - if (!(t = ((unsigned char *)dmalloc(len + 1, - "parse_option_buffer")))) + if (!(t = dmalloc(len + 1, "parse_option_buffer"))) error("Can't allocate storage for option %s.", dhcp_options[code].name); /* @@ -168,15 +167,14 @@ parse_option_buffer(struct packet *packet, * we last saw. This is really only required * for clients, but what the heck... */ - t = ((unsigned char *)dmalloc(len + - packet->options[code].len + 1, - "parse_option_buffer")); + t = dmalloc(len + packet->options[code].len + 1, + "parse_option_buffer"); if (!t) error("Can't expand storage for option %s.", dhcp_options[code].name); memcpy(t, packet->options[code].data, packet->options[code].len); - memcpy(t + packet->options [code].len, + memcpy(t + packet->options[code].len, &s[2], len); packet->options[code].len += len; t[packet->options[code].len] = 0; @@ -220,7 +218,7 @@ cons_options(struct packet *inpacket, struct dhcp_packet *outpacket, inpacket && inpacket->options[DHO_DHCP_MAX_MESSAGE_SIZE].data && (inpacket->options[DHO_DHCP_MAX_MESSAGE_SIZE].len >= - sizeof (u_int16_t))) + sizeof(u_int16_t))) mms = getUShort( inpacket->options[DHO_DHCP_MAX_MESSAGE_SIZE].data); @@ -348,7 +346,7 @@ store_options(unsigned char *buffer, int buflen, struct tree_cache **options, int second_cutoff, int terminate) { int bufix = 0; - int option_stored [256]; + int option_stored[256]; int i; int ix; int tto; @@ -389,10 +387,10 @@ store_options(unsigned char *buffer, int buflen, struct tree_cache **options, continue; /* We should now have a constant length for the option. */ - length = options[code] -> len; + length = options[code]->len; /* Do we add a NUL? */ - if (terminate && dhcp_options[code].format [0] == 't') { + if (terminate && dhcp_options[code].format[0] == 't') { length++; tto = 1; } else @@ -492,12 +490,12 @@ pretty_print_option(unsigned int code, unsigned char *data, int len, numelem++; fmtbuf[i] = dhcp_options[code].format[i]; switch (dhcp_options[code].format[i]) { - case 'A': + case 'A': --numelem; fmtbuf[i] = 0; numhunk = 0; break; - case 'X': + case 'X': for (k = 0; k < len; k++) if (!isascii(data[k]) || !isprint(data[k])) @@ -513,28 +511,28 @@ pretty_print_option(unsigned int code, unsigned char *data, int len, } fmtbuf[i + 1] = 0; break; - case 't': + case 't': fmtbuf[i] = 't'; fmtbuf[i + 1] = 0; numhunk = -2; break; - case 'I': - case 'l': - case 'L': + case 'I': + case 'l': + case 'L': hunksize += 4; break; - case 's': - case 'S': + case 's': + case 'S': hunksize += 2; break; - case 'b': - case 'B': - case 'f': + case 'b': + case 'B': + case 'f': hunksize++; break; - case 'e': + case 'e': break; - default: + default: warn("%s: garbage in format string: %s", dhcp_options[code].name, &(dhcp_options[code].format[i])); @@ -570,7 +568,7 @@ pretty_print_option(unsigned int code, unsigned char *data, int len, for (j = 0; j < numelem; j++) { int opcount; switch (fmtbuf[j]) { - case 't': + case 't': if (emit_quotes) { *op++ = '"'; opleft--; @@ -605,7 +603,7 @@ pretty_print_option(unsigned int code, unsigned char *data, int len, *op = 0; break; - case 'I': + case 'I': foo.s_addr = htonl(getULong(dp)); opcount = strlcpy(op, inet_ntoa(foo), opleft); if (opcount >= opleft) @@ -613,7 +611,7 @@ pretty_print_option(unsigned int code, unsigned char *data, int len, opleft -= opcount; dp += 4; break; - case 'l': + case 'l': opcount = snprintf(op, opleft, "%ld", (long)getLong(dp)); if (opcount >= opleft) @@ -621,7 +619,7 @@ pretty_print_option(unsigned int code, unsigned char *data, int len, opleft -= opcount; dp += 4; break; - case 'L': + case 'L': opcount = snprintf(op, opleft, "%ld", (unsigned long)getULong(dp)); if (opcount >= opleft) @@ -629,7 +627,7 @@ pretty_print_option(unsigned int code, unsigned char *data, int len, opleft -= opcount; dp += 4; break; - case 's': + case 's': opcount = snprintf(op, opleft, "%d", getShort(dp)); if (opcount >= opleft) @@ -637,7 +635,7 @@ pretty_print_option(unsigned int code, unsigned char *data, int len, opleft -= opcount; dp += 2; break; - case 'S': + case 'S': opcount = snprintf(op, opleft, "%d", getUShort(dp)); if (opcount >= opleft) @@ -645,33 +643,33 @@ pretty_print_option(unsigned int code, unsigned char *data, int len, opleft -= opcount; dp += 2; break; - case 'b': + case 'b': opcount = snprintf(op, opleft, "%d", *(char *)dp++); if (opcount >= opleft) goto toobig; opleft -= opcount; break; - case 'B': + case 'B': opcount = snprintf(op, opleft, "%d", *dp++); if (opcount >= opleft) goto toobig; opleft -= opcount; break; - case 'x': + case 'x': opcount = snprintf(op, opleft, "%x", *dp++); if (opcount >= opleft) goto toobig; opleft -= opcount; break; - case 'f': + case 'f': opcount = strlcpy(op, *dp++ ? "true" : "false", opleft); if (opcount >= opleft) goto toobig; opleft -= opcount; break; - default: + default: warn("Unexpected format code %c", fmtbuf[j]); } op += strlen(op); diff --git a/sbin/dhclient/packet.c b/sbin/dhclient/packet.c index 0c8e706a100..008aa027f28 100644 --- a/sbin/dhclient/packet.c +++ b/sbin/dhclient/packet.c @@ -1,4 +1,4 @@ -/* $OpenBSD: packet.c,v 1.3 2004/02/06 11:33:22 henning Exp $ */ +/* $OpenBSD: packet.c,v 1.4 2004/02/07 13:26:35 henning Exp $ */ /* Packet assembly code, originally contributed by Archie Cobbs. */ @@ -267,7 +267,7 @@ decode_udp_ip_header(struct interface_info *interface, unsigned char *buf, sum = wrapsum(checksum((unsigned char *)udp, sizeof(*udp), checksum(data, len, checksum((unsigned char *)&ip->ip_src, 2 * sizeof(ip->ip_src), - IPPROTO_UDP + (u_int32_t)ntohs(udp -> uh_ulen))))); + IPPROTO_UDP + (u_int32_t)ntohs(udp->uh_ulen))))); udp_packets_seen++; if (usum && usum != sum) { diff --git a/sbin/dhclient/parse.c b/sbin/dhclient/parse.c index c4d11e636dd..2eff01142a7 100644 --- a/sbin/dhclient/parse.c +++ b/sbin/dhclient/parse.c @@ -1,4 +1,4 @@ -/* $OpenBSD: parse.c,v 1.3 2004/02/06 11:33:22 henning Exp $ */ +/* $OpenBSD: parse.c,v 1.4 2004/02/07 13:26:35 henning Exp $ */ /* Common parser code for dhcpd and dhclient. */ @@ -123,7 +123,7 @@ parse_string(FILE *cfile) skip_to_semi(cfile); return (NULL); } - s = (char *)malloc(strlen(val) + 1); + s = malloc(strlen(val) + 1); if (!s) error("no memory for string %s.", val); strlcpy(s, val, strlen(val) + 1); @@ -156,7 +156,7 @@ parse_host_name(FILE *cfile) return (NULL); } /* Store this identifier... */ - if (!(s = (char *)malloc(strlen(val) + 1))) + if (!(s = malloc(strlen(val) + 1))) error("can't allocate temp space for hostname."); strlcpy(s, val, strlen(val) + 1); c = cons((caddr_t)s, c); @@ -171,7 +171,7 @@ parse_host_name(FILE *cfile) } while (token == DOT); /* Assemble the hostname together into a string. */ - if (!(s = (char *)malloc(len))) + if (!(s = malloc(len))) error("can't allocate space for hostname."); t = s + len; *--t = '\0'; @@ -304,7 +304,7 @@ parse_numeric_aggregate(FILE *cfile, unsigned char *buf, int *max, pair c = NULL; if (!bufp && *max) { - bufp = (unsigned char *)malloc(*max * size / 8); + bufp = malloc(*max * size / 8); if (!bufp) error("can't allocate space for numeric aggregate"); } else @@ -347,7 +347,7 @@ parse_numeric_aggregate(FILE *cfile, unsigned char *buf, int *max, convert_num(s, val, base, size); s += size / 8; } else { - t = (char *)malloc(strlen(val) + 1); + t = malloc(strlen(val) + 1); if (!t) error("no temp space for number."); strlcpy(t, val, strlen(val) + 1); @@ -357,7 +357,7 @@ parse_numeric_aggregate(FILE *cfile, unsigned char *buf, int *max, /* If we had to cons up a list, convert it now. */ if (c) { - bufp = (unsigned char *)malloc(count * size / 8); + bufp = malloc(count * size / 8); if (!bufp) error("can't allocate space for numeric aggregate."); s = bufp + count - size / 8; @@ -620,7 +620,7 @@ parse_date(FILE *cfile) guess = ((((((365 * (tm.tm_year - 70) + /* Days in years since '70 */ (tm.tm_year - 69) / 4 + /* Leap days since '70 */ (tm.tm_mon /* Days in months this year */ - ? months [tm.tm_mon - 1] + ? months[tm.tm_mon - 1] : 0) + (tm.tm_mon > 1 && /* Leap day this year */ !((tm.tm_year - 72) & 3)) + diff --git a/sbin/dhclient/socket.c b/sbin/dhclient/socket.c index e7e965af677..7428fe97386 100644 --- a/sbin/dhclient/socket.c +++ b/sbin/dhclient/socket.c @@ -1,4 +1,4 @@ -/* $OpenBSD: socket.c,v 1.3 2004/02/06 11:33:22 henning Exp $ */ +/* $OpenBSD: socket.c,v 1.4 2004/02/07 13:26:35 henning Exp $ */ /* BSD socket interface code... */ @@ -121,7 +121,7 @@ send_fallback(struct interface_info *interface, struct packet *packet, int result; result = sendto(interface->wfdesc, (char *)raw, len, 0, - (struct sockaddr *)to, sizeof(*to)); + (struct sockaddr *)to, sizeof(*to)); if (result == -1) { warn("send_fallback: %m"); diff --git a/sbin/dhclient/tables.c b/sbin/dhclient/tables.c index dcb60b140d4..faec6306c9d 100644 --- a/sbin/dhclient/tables.c +++ b/sbin/dhclient/tables.c @@ -1,4 +1,4 @@ -/* $OpenBSD: tables.c,v 1.2 2004/02/04 12:16:56 henning Exp $ */ +/* $OpenBSD: tables.c,v 1.3 2004/02/07 13:26:35 henning Exp $ */ /* Tables of information... */ @@ -42,25 +42,26 @@ #include "dhcpd.h" -/* DHCP Option names, formats and codes, from RFC1533. - - Format codes: - - e - end of data - I - IP address - l - 32-bit signed integer - L - 32-bit unsigned integer - s - 16-bit signed integer - S - 16-bit unsigned integer - b - 8-bit signed integer - B - 8-bit unsigned integer - t - ASCII text - f - flag (true or false) - A - array of whatever precedes (e.g., IA means array of IP addresses) -*/ +/* + * DHCP Option names, formats and codes, from RFC1533. + * + * Format codes: + * + * e - end of data + * I - IP address + * l - 32-bit signed integer + * L - 32-bit unsigned integer + * s - 16-bit signed integer + * S - 16-bit unsigned integer + * b - 8-bit signed integer + * B - 8-bit unsigned integer + * t - ASCII text + * f - flag (true or false) + * A - array of whatever precedes (e.g., IA means array of IP addresses) + */ struct universe dhcp_universe; -struct option dhcp_options [256] = { +struct option dhcp_options[256] = { { "pad", "", &dhcp_universe, 0 }, { "subnet-mask", "I", &dhcp_universe, 1 }, { "time-offset", "l", &dhcp_universe, 2 }, @@ -319,9 +320,11 @@ struct option dhcp_options [256] = { { "option-end", "e", &dhcp_universe, 255 }, }; -/* Default dhcp option priority list (this is ad hoc and should not be - mistaken for a carefully crafted and optimized list). */ -unsigned char dhcp_option_default_priority_list [] = { +/* + * Default dhcp option priority list (this is ad hoc and should not be + * mistaken for a carefully crafted and optimized list). + */ +unsigned char dhcp_option_default_priority_list[] = { DHO_DHCP_REQUESTED_ADDRESS, DHO_DHCP_OPTION_OVERLOAD, DHO_DHCP_MAX_MESSAGE_SIZE, @@ -401,10 +404,10 @@ unsigned char dhcp_option_default_priority_list [] = { }; int sizeof_dhcp_option_default_priority_list = - sizeof dhcp_option_default_priority_list; + sizeof(dhcp_option_default_priority_list); -char *hardware_types [] = { +char *hardware_types[] = { "unknown-0", "ethernet", "unknown-2", @@ -660,28 +663,30 @@ char *hardware_types [] = { "unknown-252", "unknown-253", "unknown-254", - "unknown-255" }; + "unknown-255" +}; struct hash_table universe_hash; -void initialize_universes() +void +initialize_universes(void) { int i; dhcp_universe.name = "dhcp"; - dhcp_universe.hash = new_hash (); + dhcp_universe.hash = new_hash(); if (!dhcp_universe.hash) - error ("Can't allocate dhcp option hash table."); + error("Can't allocate dhcp option hash table."); for (i = 0; i < 256; i++) { - dhcp_universe.options [i] = &dhcp_options [i]; - add_hash (dhcp_universe.hash, - (unsigned char *)dhcp_options [i].name, 0, - (unsigned char *)&dhcp_options [i]); + dhcp_universe.options[i] = &dhcp_options[i]; + add_hash(dhcp_universe.hash, + (unsigned char *)dhcp_options[i].name, 0, + (unsigned char *)&dhcp_options[i]); } universe_hash.hash_count = DEFAULT_HASH_SIZE; - add_hash (&universe_hash, - (unsigned char *)dhcp_universe.name, 0, - (unsigned char *)&dhcp_universe); + add_hash(&universe_hash, + (unsigned char *)dhcp_universe.name, 0, + (unsigned char *)&dhcp_universe); } diff --git a/sbin/dhclient/tree.c b/sbin/dhclient/tree.c index f2280f59369..5aafc01767a 100644 --- a/sbin/dhclient/tree.c +++ b/sbin/dhclient/tree.c @@ -1,6 +1,6 @@ -/* $OpenBSD: tree.c,v 1.3 2004/02/04 12:16:56 henning Exp $ */ +/* $OpenBSD: tree.c,v 1.4 2004/02/07 13:26:35 henning Exp $ */ -/* Routines for manipulating parse trees... */ +/* Routines for manipulating parse trees... */ /* * Copyright (c) 1995, 1996, 1997 The Internet Software Consortium. @@ -42,350 +42,350 @@ #include "dhcpd.h" -static TIME tree_evaluate_recurse (int *, unsigned char **, int *, struct tree *); -static TIME do_host_lookup (int *, unsigned char **, int *, - struct dns_host_entry *); -static void do_data_copy (int *, unsigned char **, int *, - unsigned char *, int); +static TIME tree_evaluate_recurse( + int *, unsigned char **, int *, struct tree *); +static TIME do_host_lookup( + int *, unsigned char **, int *, struct dns_host_entry *); +static void do_data_copy( + int *, unsigned char **, int *, unsigned char *, int); -pair cons (car, cdr) - caddr_t car; - pair cdr; +pair +cons(caddr_t car, pair cdr) { - pair foo = (pair)dmalloc (sizeof *foo, "cons"); + pair foo = dmalloc(sizeof(*foo), "cons"); if (!foo) - error ("no memory for cons."); - foo -> car = car; - foo -> cdr = cdr; - return foo; + error("no memory for cons."); + foo->car = car; + foo->cdr = cdr; + return (foo); } -struct tree_cache *tree_cache (tree) - struct tree *tree; +struct tree_cache * +tree_cache(struct tree *tree) { struct tree_cache *tc; - tc = new_tree_cache ("tree_cache"); + tc = new_tree_cache("tree_cache"); if (!tc) - return 0; - tc -> value = (unsigned char *)0; - tc -> len = tc -> buf_size = 0; - tc -> timeout = 0; - tc -> tree = tree; - return tc; + return (NULL); + tc->value = NULL; + tc->len = tc->buf_size = 0; + tc->timeout = 0; + tc->tree = tree; + return (tc); } -struct tree *tree_host_lookup (name) - char *name; +struct tree * +tree_host_lookup(char *name) { struct tree *nt; - nt = new_tree ("tree_host_lookup"); + nt = new_tree("tree_host_lookup"); if (!nt) - error ("No memory for host lookup tree node."); - nt -> op = TREE_HOST_LOOKUP; - nt -> data.host_lookup.host = enter_dns_host (name); - return nt; + error("No memory for host lookup tree node."); + nt->op = TREE_HOST_LOOKUP; + nt->data.host_lookup.host = enter_dns_host(name); + return (nt); } -struct dns_host_entry *enter_dns_host (name) - char *name; +struct dns_host_entry * +enter_dns_host(char *name) { struct dns_host_entry *dh; - int len = strlen (name) + 1; - - if (!(dh = (struct dns_host_entry *)dmalloc - (sizeof (struct dns_host_entry), "enter_dns_host")) - || !(dh -> hostname = dmalloc (len, "enter_dns_host"))) - error ("Can't allocate space for new host."); - strlcpy (dh -> hostname, name, len); - dh -> data = (unsigned char *)0; - dh -> data_len = 0; - dh -> buf_len = 0; - dh -> timeout = 0; - return dh; + int len = strlen(name) + 1; + + if (!(dh = dmalloc(sizeof(struct dns_host_entry), "enter_dns_host")) + || !(dh->hostname = dmalloc(len, "enter_dns_host"))) + error("Can't allocate space for new host."); + strlcpy(dh->hostname, name, len); + dh->data = NULL; + dh->data_len = 0; + dh->buf_len = 0; + dh->timeout = 0; + return (dh); } -struct tree *tree_const (data, len) - unsigned char *data; - int len; +struct tree * +tree_const(unsigned char *data, int len) { struct tree *nt; - if (!(nt = new_tree ("tree_const")) - || !(nt -> data.const_val.data = - (unsigned char *)dmalloc (len, "tree_const"))) - error ("No memory for constant data tree node."); - nt -> op = TREE_CONST; - memcpy (nt -> data.const_val.data, data, len); - nt -> data.const_val.len = len; - return nt; + if (!(nt = new_tree("tree_const")) + || !(nt->data.const_val.data = dmalloc(len, "tree_const"))) + error("No memory for constant data tree node."); + nt->op = TREE_CONST; + memcpy(nt->data.const_val.data, data, len); + nt->data.const_val.len = len; + return (nt); } -struct tree *tree_concat (left, right) - struct tree *left, *right; +struct tree * +tree_concat(struct tree *left, struct tree *right) { struct tree *nt; - /* If we're concatenating a null tree to a non-null tree, just - return the non-null tree; if both trees are null, return - a null tree. */ + /* + * If we're concatenating a null tree to a non-null tree, just + * return the non-null tree; if both trees are null, return a + * null tree. + */ if (!left) - return right; + return (right); if (!right) - return left; + return (left); /* If both trees are constant, combine them. */ - if (left -> op == TREE_CONST && right -> op == TREE_CONST) { - unsigned char *buf = dmalloc (left -> data.const_val.len - + right -> data.const_val.len, - "tree_concat"); + if (left->op == TREE_CONST && right->op == TREE_CONST) { + unsigned char *buf = dmalloc(left->data.const_val.len + + right->data.const_val.len, "tree_concat"); if (!buf) - error ("No memory to concatenate constants."); - memcpy (buf, left -> data.const_val.data, - left -> data.const_val.len); - memcpy (buf + left -> data.const_val.len, - right -> data.const_val.data, - right -> data.const_val.len); - dfree (left -> data.const_val.data, "tree_concat"); - dfree (right -> data.const_val.data, "tree_concat"); - left -> data.const_val.data = buf; - left -> data.const_val.len += right -> data.const_val.len; - free_tree (right, "tree_concat"); - return left; + error("No memory to concatenate constants."); + memcpy(buf, left->data.const_val.data, + left->data.const_val.len); + memcpy(buf + left->data.const_val.len, + right->data.const_val.data, + right->data.const_val.len); + dfree(left->data.const_val.data, "tree_concat"); + dfree(right->data.const_val.data, "tree_concat"); + left->data.const_val.data = buf; + left->data.const_val.len += right->data.const_val.len; + free_tree(right, "tree_concat"); + return (left); } - + /* Otherwise, allocate a new node to concatenate the two. */ - if (!(nt = new_tree ("tree_concat"))) - error ("No memory for data tree concatenation node."); - nt -> op = TREE_CONCAT; - nt -> data.concat.left = left; - nt -> data.concat.right = right; - return nt; + if (!(nt = new_tree("tree_concat"))) + error("No memory for data tree concatenation node."); + nt->op = TREE_CONCAT; + nt->data.concat.left = left; + nt->data.concat.right = right; + return (nt); } -struct tree *tree_limit (tree, limit) - struct tree *tree; - int limit; +struct tree * +tree_limit(struct tree *tree, int limit) { struct tree *rv; /* If the tree we're limiting is constant, limit it now. */ - if (tree -> op == TREE_CONST) { - if (tree -> data.const_val.len > limit) - tree -> data.const_val.len = limit; - return tree; + if (tree->op == TREE_CONST) { + if (tree->data.const_val.len > limit) + tree->data.const_val.len = limit; + return (tree); } /* Otherwise, put in a node which enforces the limit on evaluation. */ - rv = new_tree ("tree_limit"); + rv = new_tree("tree_limit"); if (!rv) - return (struct tree *)0; - rv -> op = TREE_LIMIT; - rv -> data.limit.tree = tree; - rv -> data.limit.limit = limit; - return rv; + return (NULL); + rv->op = TREE_LIMIT; + rv->data.limit.tree = tree; + rv->data.limit.limit = limit; + return (rv); } -int tree_evaluate (tree_cache) - struct tree_cache *tree_cache; +int +tree_evaluate(struct tree_cache *tree_cache) { - unsigned char *bp = tree_cache -> value; - int bc = tree_cache -> buf_size; + unsigned char *bp = tree_cache->value; + int bc = tree_cache->buf_size; int bufix = 0; - /* If there's no tree associated with this cache, it evaluates - to a constant and that was detected at startup. */ - if (!tree_cache -> tree) - return 1; + /* + * If there's no tree associated with this cache, it evaluates + * to a constant and that was detected at startup. + */ + if (!tree_cache->tree) + return (1); /* Try to evaluate the tree without allocating more memory... */ - tree_cache -> timeout = tree_evaluate_recurse (&bufix, &bp, &bc, - tree_cache -> tree); + tree_cache->timeout = tree_evaluate_recurse(&bufix, &bp, &bc, + tree_cache->tree); /* No additional allocation needed? */ if (bufix <= bc) { - tree_cache -> len = bufix; - return 1; + tree_cache->len = bufix; + return (1); } - /* If we can't allocate more memory, return with what we - have (maybe nothing). */ - if (!(bp = (unsigned char *)dmalloc (bufix, "tree_evaluate"))) - return 0; + /* + * If we can't allocate more memory, return with what we have + * (maybe nothing). + */ + if (!(bp = dmalloc(bufix, "tree_evaluate"))) + return (0); /* Record the change in conditions... */ bc = bufix; bufix = 0; - /* Note that the size of the result shouldn't change on the - second call to tree_evaluate_recurse, since we haven't - changed the ``current'' time. */ - tree_evaluate_recurse (&bufix, &bp, &bc, tree_cache -> tree); - - /* Free the old buffer if needed, then store the new buffer - location and size and return. */ - if (tree_cache -> value) - dfree (tree_cache -> value, "tree_evaluate"); - tree_cache -> value = bp; - tree_cache -> len = bufix; - tree_cache -> buf_size = bc; - return 1; + /* + * Note that the size of the result shouldn't change on the + * second call to tree_evaluate_recurse, since we haven't + * changed the ``current'' time. + */ + tree_evaluate_recurse(&bufix, &bp, &bc, tree_cache->tree); + + /* + * Free the old buffer if needed, then store the new buffer + * location and size and return. + */ + if (tree_cache->value) + dfree(tree_cache->value, "tree_evaluate"); + tree_cache->value = bp; + tree_cache->len = bufix; + tree_cache->buf_size = bc; + return (1); } -static TIME tree_evaluate_recurse (bufix, bufp, bufcount, tree) - int *bufix; - unsigned char **bufp; - int *bufcount; - struct tree *tree; +static TIME +tree_evaluate_recurse(int *bufix, unsigned char **bufp, int *bufcount, + struct tree *tree) { int limit; TIME t1, t2; - switch (tree -> op) { - case TREE_CONCAT: - t1 = tree_evaluate_recurse (bufix, bufp, bufcount, - tree -> data.concat.left); - t2 = tree_evaluate_recurse (bufix, bufp, bufcount, - tree -> data.concat.right); + switch (tree->op) { + case TREE_CONCAT: + t1 = tree_evaluate_recurse(bufix, bufp, bufcount, + tree->data.concat.left); + t2 = tree_evaluate_recurse(bufix, bufp, bufcount, + tree->data.concat.right); if (t1 > t2) - return t2; - return t1; + return (t2); + return (t1); - case TREE_HOST_LOOKUP: - return do_host_lookup (bufix, bufp, bufcount, - tree -> data.host_lookup.host); + case TREE_HOST_LOOKUP: + return (do_host_lookup(bufix, bufp, bufcount, + tree->data.host_lookup.host)); - case TREE_CONST: - do_data_copy (bufix, bufp, bufcount, - tree -> data.const_val.data, - tree -> data.const_val.len); + case TREE_CONST: + do_data_copy(bufix, bufp, bufcount, + tree->data.const_val.data, + tree->data.const_val.len); t1 = MAX_TIME; - return t1; + return (t1); - case TREE_LIMIT: - limit = *bufix + tree -> data.limit.limit; - t1 = tree_evaluate_recurse (bufix, bufp, bufcount, - tree -> data.limit.tree); + case TREE_LIMIT: + limit = *bufix + tree->data.limit.limit; + t1 = tree_evaluate_recurse(bufix, bufp, bufcount, + tree->data.limit.tree); *bufix = limit; - return t1; + return (t1); - default: - warn ("Bad node id in tree: %d.", tree -> op); + default: + warn("Bad node id in tree: %d.", tree->op); t1 = MAX_TIME; - return t1; + return (t1); } } -static TIME do_host_lookup (bufix, bufp, bufcount, dns) - int *bufix; - unsigned char **bufp; - int *bufcount; - struct dns_host_entry *dns; +static TIME +do_host_lookup(int *bufix, unsigned char **bufp, int *bufcount, + struct dns_host_entry *dns) { struct hostent *h; int i; int new_len; #ifdef DEBUG_EVAL - debug ("time: now = %d dns = %d %d diff = %d", - cur_time, dns -> timeout, cur_time - dns -> timeout); + debug("time: now = %d dns = %d %d diff = %d", + cur_time, dns->timeout, cur_time - dns->timeout); #endif /* If the record hasn't timed out, just copy the data and return. */ - if (cur_time <= dns -> timeout) { + if (cur_time <= dns->timeout) { #ifdef DEBUG_EVAL - debug ("easy copy: %x %d %x", - dns -> data, dns -> data_len, - dns -> data ? *(int *)(dns -> data) : 0); + debug("easy copy: %x %d %x", + dns->data, dns->data_len, + dns->data ? *(int *)(dns->data) : 0); #endif - do_data_copy (bufix, bufp, bufcount, - dns -> data, dns -> data_len); - return dns -> timeout; + do_data_copy(bufix, bufp, bufcount, + dns->data, dns->data_len); + return (dns->timeout); } #ifdef DEBUG_EVAL - debug ("Looking up %s", dns -> hostname); + debug("Looking up %s", dns->hostname); #endif /* Otherwise, look it up... */ - h = gethostbyname (dns -> hostname); + h = gethostbyname(dns->hostname); if (h == NULL) { - switch (h_errno) { - case HOST_NOT_FOUND: - warn ("%s: host unknown.", dns -> hostname); + switch(h_errno) { + case HOST_NOT_FOUND: + warn("%s: host unknown.", dns->hostname); break; - case TRY_AGAIN: - warn ("%s: temporary name server failure", - dns -> hostname); + case TRY_AGAIN: + warn("%s: temporary name server failure", + dns->hostname); break; - case NO_RECOVERY: - warn ("%s: name server failed", dns -> hostname); + case NO_RECOVERY: + warn("%s: name server failed", dns->hostname); break; - case NO_DATA: - warn ("%s: no A record associated with address", - dns -> hostname); + case NO_DATA: + warn("%s: no A record associated with address", + dns->hostname); } /* Okay to try again after a minute. */ - return cur_time + 60; + return (cur_time + 60); } #ifdef DEBUG_EVAL - debug ("Lookup succeeded; first address is %x", - h -> h_addr_list [0]); + debug("Lookup succeeded; first address is %x", h->h_addr_list[0]); #endif /* Count the number of addresses we got... */ - for (i = 0; h -> h_addr_list [i]; i++) + for (i = 0; h->h_addr_list[i]; i++) ; - + /* Do we need to allocate more memory? */ - new_len = i * h -> h_length; - if (dns -> buf_len < i) { - unsigned char *buf = - (unsigned char *)dmalloc (new_len, "do_host_lookup"); + new_len = i * h->h_length; + if (dns->buf_len < i) { + unsigned char *buf = dmalloc(new_len, "do_host_lookup"); /* If we didn't get more memory, use what we have. */ if (!buf) { - new_len = dns -> buf_len; - if (!dns -> buf_len) { - dns -> timeout = cur_time + 60; - return dns -> timeout; + new_len = dns->buf_len; + if (!dns->buf_len) { + dns->timeout = cur_time + 60; + return (dns->timeout); } } else { - if (dns -> data) - dfree (dns -> data, "do_host_lookup"); - dns -> data = buf; - dns -> buf_len = new_len; + if (dns->data) + dfree(dns->data, "do_host_lookup"); + dns->data = buf; + dns->buf_len = new_len; } } - /* Addresses are conveniently stored one to the buffer, so we - have to copy them out one at a time... :'( */ - for (i = 0; i < new_len / h -> h_length; i++) { - memcpy (dns -> data + h -> h_length * i, - h -> h_addr_list [i], h -> h_length); + /* + * Addresses are conveniently stored one to the buffer, so we + * have to copy them out one at a time... :'( + */ + for (i = 0; i < new_len / h->h_length; i++) { + memcpy(dns->data + h->h_length * i, + h->h_addr_list[i], h->h_length); } #ifdef DEBUG_EVAL - debug ("dns -> data: %x h -> h_addr_list [0]: %x", - *(int *)(dns -> data), h -> h_addr_list [0]); + debug("dns -> data: %x h -> h_addr_list [0]: %x", + *(int *)(dns->data), h->h_addr_list[0]); #endif - dns -> data_len = new_len; + dns->data_len = new_len; - /* Set the timeout for an hour from now. - XXX This should really use the time on the DNS reply. */ - dns -> timeout = cur_time + 3600; + /* + * Set the timeout for an hour from now. + * XXX: This should really use the time on the DNS reply. + */ + dns->timeout = cur_time + 3600; #ifdef DEBUG_EVAL - debug ("hard copy: %x %d %x", - dns -> data, dns -> data_len, *(int *)(dns -> data)); + debug("hard copy: %x %d %x", + dns->data, dns->data_len, *(int *)(dns->data)); #endif - do_data_copy (bufix, bufp, bufcount, dns -> data, dns -> data_len); - return dns -> timeout; + do_data_copy(bufix, bufp, bufcount, dns->data, dns->data_len); + return (dns->timeout); } -static void do_data_copy (bufix, bufp, bufcount, data, len) - int *bufix; - unsigned char **bufp; - int *bufcount; - unsigned char *data; - int len; +static void +do_data_copy(int *bufix, unsigned char **bufp, int *bufcount, + unsigned char *data, int len) { int space = *bufcount - *bufix; @@ -393,9 +393,12 @@ static void do_data_copy (bufix, bufp, bufcount, data, len) if (space > len) space = len; - /* Copy as much data as will fit, then increment the buffer index - by the amount we actually had to copy, which could be more. */ + /* + * Copy as much data as will fit, then increment the buffer + * index by the amount we actually had to copy, which could be + * more. + */ if (space > 0) - memcpy (*bufp + *bufix, data, space); + memcpy(*bufp + *bufix, data, space); *bufix += len; } diff --git a/sbin/dhclient/tree.h b/sbin/dhclient/tree.h index 7424046c0e3..42ea06d5f8e 100644 --- a/sbin/dhclient/tree.h +++ b/sbin/dhclient/tree.h @@ -1,6 +1,6 @@ -/* $OpenBSD: tree.h,v 1.2 2004/02/04 12:16:56 henning Exp $ */ +/* $OpenBSD: tree.h,v 1.3 2004/02/07 13:26:35 henning Exp $ */ -/* Definitions for address trees... */ +/* Definitions for address trees... */ /* * Copyright (c) 1995 The Internet Software Consortium. All rights reserved. @@ -96,7 +96,7 @@ struct tree_cache { struct universe { char *name; struct hash_table *hash; - struct option *options [256]; + struct option *options[256]; }; struct option { |