diff options
author | Henning Brauer <henning@cvs.openbsd.org> | 2004-02-07 11:36:00 +0000 |
---|---|---|
committer | Henning Brauer <henning@cvs.openbsd.org> | 2004-02-07 11:36:00 +0000 |
commit | 641e30169b57c755fc894dd205100dfd76c0ed75 (patch) | |
tree | 60d2570f1873a3a04a68c329aaa960a0b44c116d /sbin/dhclient | |
parent | c5c7b3567806b74f2c8d0a7a5a239f22087666ef (diff) |
more style fixes from Emil Mikulic <emikulic@dmr.ath.cx>
Thank you very much for this excellent work, it helps a lot.
binary unchanged.
I am still convinced dhclient can be made readable.
Diffstat (limited to 'sbin/dhclient')
-rw-r--r-- | sbin/dhclient/alloc.c | 56 | ||||
-rw-r--r-- | sbin/dhclient/bpf.c | 124 | ||||
-rw-r--r-- | sbin/dhclient/clparse.c | 215 | ||||
-rw-r--r-- | sbin/dhclient/conflex.c | 31 | ||||
-rw-r--r-- | sbin/dhclient/convert.c | 28 | ||||
-rw-r--r-- | sbin/dhclient/dispatch.c | 291 |
6 files changed, 401 insertions, 344 deletions
diff --git a/sbin/dhclient/alloc.c b/sbin/dhclient/alloc.c index d940af6f28d..3f5b70aa63d 100644 --- a/sbin/dhclient/alloc.c +++ b/sbin/dhclient/alloc.c @@ -1,4 +1,4 @@ -/* $OpenBSD: alloc.c,v 1.3 2004/02/04 12:16:56 henning Exp $ */ +/* $OpenBSD: alloc.c,v 1.4 2004/02/07 11:35:59 henning Exp $ */ /* Memory allocation... */ @@ -52,7 +52,7 @@ dmalloc(int size, char *name) if (!foo) warn("No memory for %s.", name); - return foo; + return (foo); } void @@ -70,8 +70,8 @@ new_packet(char *name) { struct packet *rval; - rval = (struct packet *)dmalloc(sizeof(struct packet), name); - return rval; + rval = dmalloc(sizeof(struct packet), name); + return (rval); } struct dhcp_packet * @@ -79,9 +79,8 @@ new_dhcp_packet(char *name) { struct dhcp_packet *rval; - rval = (struct dhcp_packet *)dmalloc(sizeof(struct dhcp_packet), - name); - return rval; + rval = dmalloc(sizeof(struct dhcp_packet), name); + return (rval); } struct tree * @@ -89,7 +88,7 @@ new_tree(char *name) { struct tree *rval = dmalloc(sizeof(struct tree), name); - return rval; + return (rval); } struct string_list * @@ -100,7 +99,7 @@ new_string_list(size_t size, char * name) rval = dmalloc(sizeof(struct string_list) + size, name); if (rval != NULL) rval->string = ((char *)rval) + sizeof(struct string_list); - return rval; + return (rval); } struct tree_cache *free_tree_caches; @@ -118,7 +117,7 @@ new_tree_cache(char *name) if (!rval) error("unable to allocate tree cache for %s.", name); } - return rval; + return (rval); } struct hash_table * @@ -126,13 +125,13 @@ new_hash_table(int count, char *name) { struct hash_table *rval; - rval = dmalloc(sizeof (struct hash_table) - + rval = dmalloc(sizeof(struct hash_table) - (DEFAULT_HASH_SIZE * sizeof(struct hash_bucket *)) + (count * sizeof(struct hash_bucket *)), name); if (rval == NULL) - return NULL; + return (NULL); rval->hash_count = count; - return rval; + return (rval); } struct hash_bucket * @@ -140,7 +139,7 @@ new_hash_bucket(char *name) { struct hash_bucket *rval = dmalloc(sizeof(struct hash_bucket), name); - return rval; + return (rval); } struct lease * @@ -148,7 +147,7 @@ new_leases(int n, char *name) { struct lease *rval = dmalloc(n * sizeof(struct lease), name); - return rval; + return (rval); } struct lease * @@ -156,7 +155,7 @@ new_lease(char *name) { struct lease *rval = dmalloc(sizeof(struct lease), name); - return rval; + return (rval); } struct subnet * @@ -164,7 +163,7 @@ new_subnet(char *name) { struct subnet *rval = dmalloc(sizeof(struct subnet), name); - return rval; + return (rval); } struct class * @@ -172,7 +171,7 @@ new_class(char *name) { struct class *rval = dmalloc(sizeof(struct class), name); - return rval; + return (rval); } struct shared_network * @@ -181,16 +180,15 @@ new_shared_network(char *name) struct shared_network *rval = dmalloc(sizeof(struct shared_network), name); - return rval; + return (rval); } struct group * new_group(char *name) { - struct group *rval = - dmalloc(sizeof(struct group), name); + struct group *rval = dmalloc(sizeof(struct group), name); - return rval; + return (rval); } struct protocol * @@ -198,7 +196,7 @@ new_protocol(char *name) { struct protocol *rval = dmalloc(sizeof(struct protocol), name); - return rval; + return (rval); } struct lease_state *free_lease_states; @@ -213,26 +211,26 @@ new_lease_state(char *name) free_lease_states = (struct lease_state *)(free_lease_states->next); } else - rval = dmalloc(sizeof (struct lease_state), name); - return rval; + rval = dmalloc(sizeof(struct lease_state), name); + return (rval); } struct domain_search_list * new_domain_search_list(char *name) { struct domain_search_list *rval = - dmalloc(sizeof (struct domain_search_list), name); + dmalloc(sizeof(struct domain_search_list), name); - return rval; + return (rval); } struct name_server * new_name_server(char *name) { struct name_server *rval = - dmalloc(sizeof (struct name_server), name); + dmalloc(sizeof(struct name_server), name); - return rval; + return (rval); } void diff --git a/sbin/dhclient/bpf.c b/sbin/dhclient/bpf.c index ea192985ab0..a6f0cdc7831 100644 --- a/sbin/dhclient/bpf.c +++ b/sbin/dhclient/bpf.c @@ -1,4 +1,4 @@ -/* $OpenBSD: bpf.c,v 1.3 2004/02/04 12:16:56 henning Exp $ */ +/* $OpenBSD: bpf.c,v 1.4 2004/02/07 11:35:59 henning Exp $ */ /* BPF socket interface code, originally contributed by Archie Cobbs. */ @@ -43,16 +43,17 @@ #include "dhcpd.h" #include <sys/ioctl.h> #include <sys/uio.h> -#include <net/bpf.h> +#include <net/bpf.h> #include <netinet/in_systm.h> #include <netinet/ip.h> #include <netinet/udp.h> #include <netinet/if_ether.h> -/* Reinitializes the specified interface after an address change. This - is not required for packet-filter APIs. */ - +/* + * Reinitializes the specified interface after an address change. This + * is not required for packet-filter APIs. + */ void if_reinitialize_send(struct interface_info *info) { @@ -63,10 +64,11 @@ if_reinitialize_receive(struct interface_info *info) { } -/* Called by get_interface_list for each interface that's discovered. - Opens a packet filter for each interface and adds it to the select - mask. */ - +/* + * Called by get_interface_list for each interface that's discovered. + * Opens a packet filter for each interface and adds it to the select + * mask. + */ int if_register_bpf(struct interface_info *info) { @@ -103,9 +105,10 @@ if_register_bpf(struct interface_info *info) void if_register_send(struct interface_info *info) { - /* If we're using the bpf API for sending and receiving, - we don't need to register this interface twice. */ - + /* + * If we're using the bpf API for sending and receiving, we + * don't need to register this interface twice. + */ info->wfdesc = info->rfdesc; if (!quiet_interface_discovery) @@ -119,11 +122,13 @@ if_register_send(struct interface_info *info) info->shared_network->name : "")); } -/* Packet filter program... - XXX Changes to the filter program may require changes to the constant - offsets used in if_register_send to patch the BPF program! XXX */ - -struct bpf_insn dhcp_bpf_filter [] = { +/* + * Packet filter program... + * + * XXX: Changes to the filter program may require changes to the + * constant offsets used in if_register_send to patch the BPF program! + */ +struct bpf_insn dhcp_bpf_filter[] = { /* Make sure this is an IP packet... */ BPF_STMT(BPF_LD + BPF_H + BPF_ABS, 12), BPF_JUMP(BPF_JMP + BPF_JEQ + BPF_K, ETHERTYPE_IP, 0, 8), @@ -152,7 +157,7 @@ struct bpf_insn dhcp_bpf_filter [] = { int dhcp_bpf_filter_len = sizeof(dhcp_bpf_filter) / sizeof(struct bpf_insn); -struct bpf_insn dhcp_bpf_tr_filter [] = { +struct bpf_insn dhcp_bpf_tr_filter[] = { /* accept all token ring packets due to variable length header */ /* if we want to get clever, insert the program here */ @@ -164,7 +169,7 @@ struct bpf_insn dhcp_bpf_tr_filter [] = { }; int dhcp_bpf_tr_filter_len = - (sizeof(dhcp_bpf_tr_filter) / sizeof(struct bpf_insn)); + sizeof(dhcp_bpf_tr_filter) / sizeof(struct bpf_insn); void if_register_receive(struct interface_info *info) @@ -184,9 +189,11 @@ if_register_receive(struct interface_info *info) v.bv_minor < BPF_MINOR_VERSION) error("Kernel BPF version out of range - recompile dhcpd!"); - /* Set immediate mode so that reads return as soon as a packet - comes in, rather than waiting for the input buffer to fill with - packets. */ + /* + * Set immediate mode so that reads return as soon as a packet + * comes in, rather than waiting for the input buffer to fill + * with packets. + */ if (ioctl(info->rfdesc, BIOCIMMEDIATE, &flag) < 0) error("Can't set immediate mode on bpf device: %m"); @@ -205,9 +212,11 @@ if_register_receive(struct interface_info *info) p.bf_len = dhcp_bpf_filter_len; p.bf_insns = dhcp_bpf_filter; - /* Patch the server port into the BPF program... - XXX changes to filter program may require changes - to the insn number(s) used below! XXX */ + /* Patch the server port into the BPF program... + * + * XXX: changes to filter program may require changes to the + * insn number(s) used below! + */ dhcp_bpf_filter[8].k = ntohs(local_port); if (ioctl(info->rfdesc, BIOCSETF, &p) < 0) @@ -223,7 +232,6 @@ if_register_receive(struct interface_info *info) info->shared_network->name : "")); } - ssize_t send_packet(struct interface_info *interface, struct packet *packet, struct dhcp_packet *raw, size_t len, struct in_addr from, @@ -252,7 +260,7 @@ send_packet(struct interface_info *interface, struct packet *packet, result = writev(interface->wfdesc, iov, 2); if (result < 0) warn("send_packet: %m"); - return result; + return (result); } ssize_t @@ -263,14 +271,16 @@ receive_packet(struct interface_info *interface, unsigned char *buf, int offset = 0; struct bpf_hdr hdr; - /* All this complexity is because BPF doesn't guarantee - that only one packet will be returned at a time. We're - getting what we deserve, though - this is a terrible abuse - of the BPF interface. Sigh. */ + /* + * All this complexity is because BPF doesn't guarantee that + * only one packet will be returned at a time. We're getting + * what we deserve, though - this is a terrible abuse of the BPF + * interface. Sigh. + */ /* Process packets until we get one we can return or until we've - done a read and gotten nothing we can return... */ - + * done a read and gotten nothing we can return... + */ do { /* If the buffer is empty, fill it. */ if (interface->rbuf_offset == interface->rbuf_len) { @@ -282,28 +292,36 @@ receive_packet(struct interface_info *interface, unsigned char *buf, interface->rbuf_len = length; } - /* If there isn't room for a whole bpf header, something went - wrong, but we'll ignore it and hope it goes away... XXX */ - if (interface->rbuf_len - interface->rbuf_offset < sizeof hdr) { + /* + * If there isn't room for a whole bpf header, something + * went wrong, but we'll ignore it and hope it goes + * away... XXX + */ + if (interface->rbuf_len - interface->rbuf_offset < + sizeof(hdr)) { interface->rbuf_offset = interface->rbuf_len; continue; } /* Copy out a bpf header... */ - memcpy(&hdr, &interface->rbuf [interface->rbuf_offset], + memcpy(&hdr, &interface->rbuf[interface->rbuf_offset], sizeof(hdr)); - /* If the bpf header plus data doesn't fit in what's left - of the buffer, stick head in sand yet again... */ + /* + * If the bpf header plus data doesn't fit in what's + * left of the buffer, stick head in sand yet again... + */ if (interface->rbuf_offset + hdr.bh_hdrlen + hdr.bh_caplen > interface->rbuf_len) { interface->rbuf_offset = interface->rbuf_len; continue; } - /* If the captured data wasn't the whole packet, or if - the packet won't fit in the input buffer, all we - can do is drop it. */ + /* + * If the captured data wasn't the whole packet, or if + * the packet won't fit in the input buffer, all we can + * do is drop it. + */ if (hdr.bh_caplen != hdr.bh_datalen) { interface->rbuf_offset += hdr.bh_hdrlen = hdr.bh_caplen; continue; @@ -313,12 +331,14 @@ receive_packet(struct interface_info *interface, unsigned char *buf, interface->rbuf_offset += hdr.bh_hdrlen; /* Decode the physical header... */ - offset = decode_hw_header (interface, + offset = decode_hw_header(interface, interface->rbuf, interface->rbuf_offset, hfrom); - /* If a physical layer checksum failed (dunno of any - physical layer that supports this, but WTH), skip this - packet. */ + /* + * If a physical layer checksum failed (dunno of any + * physical layer that supports this, but WTH), skip + * this packet. + */ if (offset < 0) { interface->rbuf_offset += hdr.bh_caplen; continue; @@ -327,7 +347,7 @@ receive_packet(struct interface_info *interface, unsigned char *buf, hdr.bh_caplen -= offset; /* Decode the IP and UDP headers... */ - offset = decode_udp_ip_header (interface, interface->rbuf, + offset = decode_udp_ip_header(interface, interface->rbuf, interface->rbuf_offset, from, NULL, hdr.bh_caplen); /* If the IP or UDP checksum was bad, skip the packet... */ @@ -338,9 +358,11 @@ receive_packet(struct interface_info *interface, unsigned char *buf, interface->rbuf_offset += offset; hdr.bh_caplen -= offset; - /* If there's not enough room to stash the packet data, - we have to skip it (this shouldn't happen in real - life, though). */ + /* + * If there's not enough room to stash the packet data, + * we have to skip it (this shouldn't happen in real + * life, though). + */ if (hdr.bh_caplen > len) { interface->rbuf_offset += hdr.bh_caplen; continue; @@ -350,7 +372,7 @@ receive_packet(struct interface_info *interface, unsigned char *buf, memcpy(buf, interface->rbuf + interface->rbuf_offset, hdr.bh_caplen); interface->rbuf_offset += hdr.bh_caplen; - return hdr.bh_caplen; + return (hdr.bh_caplen); } while (!length); return (0); } diff --git a/sbin/dhclient/clparse.c b/sbin/dhclient/clparse.c index 77929fe2bad..119fd9a7e88 100644 --- a/sbin/dhclient/clparse.c +++ b/sbin/dhclient/clparse.c @@ -1,4 +1,4 @@ -/* $OpenBSD: clparse.c,v 1.5 2004/02/04 12:16:56 henning Exp $ */ +/* $OpenBSD: clparse.c,v 1.6 2004/02/07 11:35:59 henning Exp $ */ /* Parser for dhclient config and lease files... */ @@ -47,11 +47,12 @@ struct client_config top_level_config; char client_script_name[] = "/sbin/dhclient-script"; -/* client-conf-file :== client-declarations EOF - client-declarations :== <nil> - | client-declaration - | client-declarations client-declaration */ - +/* + * client-conf-file :== client-declarations EOF + * client-declarations :== <nil> + * | client-declaration + * | client-declarations client-declaration + */ int read_client_conf(void) { @@ -67,7 +68,7 @@ read_client_conf(void) initialize_universes(); /* Initialize the top level client configuration. */ - memset(&top_level_config, 0, sizeof top_level_config); + memset(&top_level_config, 0, sizeof(top_level_config)); /* Set some defaults... */ top_level_config.timeout = 60; @@ -105,15 +106,17 @@ read_client_conf(void) fclose(cfile); } - /* Set up state and config structures for clients that don't - have per-interface configuration declarations. */ + /* + * Set up state and config structures for clients that don't + * have per-interface configuration declarations. + */ config = NULL; for (ip = interfaces; ip; ip = ip->next) { if (!ip->client) { ip->client = malloc(sizeof(struct client_state)); if (!ip->client) error("no memory for client state."); - memset(ip->client, 0, sizeof *(ip->client)); + memset(ip->client, 0, sizeof(*(ip->client))); } if (!ip->client->config) { if (!config) { @@ -130,10 +133,11 @@ read_client_conf(void) return (!warnings_occurred); } -/* lease-file :== client-lease-statements EOF - client-lease-statements :== <nil> - | client-lease-statements LEASE client-lease-statement */ - +/* + * lease-file :== client-lease-statements EOF + * client-lease-statements :== <nil> + * | client-lease-statements LEASE client-lease-statement + */ void read_client_leases(void) { @@ -161,24 +165,25 @@ read_client_leases(void) } while (1); } -/* client-declaration :== - SEND option-decl | - DEFAULT option-decl | - SUPERSEDE option-decl | - PREPEND option-decl | - APPEND option-decl | - hardware-declaration | - REQUEST option-list | - REQUIRE option-list | - TIMEOUT number | - RETRY number | - REBOOT number | - SELECT_TIMEOUT number | - SCRIPT string | - interface-declaration | - LEASE client-lease-statement | - ALIAS client-lease-statement */ - +/* + * client-declaration :== + * SEND option-decl | + * DEFAULT option-decl | + * SUPERSEDE option-decl | + * PREPEND option-decl | + * APPEND option-decl | + * hardware-declaration | + * REQUEST option-list | + * REQUIRE option-list | + * TIMEOUT number | + * RETRY number | + * REBOOT number | + * SELECT_TIMEOUT number | + * SCRIPT string | + * interface-declaration | + * LEASE client-lease-statement | + * ALIAS client-lease-statement + */ void parse_client_statement(FILE *cfile, struct interface_info *ip, struct client_config *config) @@ -212,7 +217,6 @@ parse_client_statement(FILE *cfile, struct interface_info *ip, if (option) config->default_actions[option->code] = ACTION_PREPEND; return; - case MEDIA: parse_string_list(cfile, &config->media, 1); return; @@ -304,7 +308,7 @@ parse_X(FILE *cfile, u_int8_t *buf, int max) skip_to_semi(cfile); return (0); } - token = peek_token (&val, cfile); + token = peek_token(&val, cfile); if (token == COLON) token = next_token(&val, cfile); } while (token == COLON); @@ -326,9 +330,10 @@ parse_X(FILE *cfile, u_int8_t *buf, int max) return (len); } -/* option-list :== option_name | - option_list COMMA option_name */ - +/* + * option-list :== option_name | + * option_list COMMA option_name + */ int parse_option_list(FILE *cfile, u_int8_t *list) { @@ -369,9 +374,10 @@ parse_option_list(FILE *cfile, u_int8_t *list) return (ix); } -/* interface-declaration :== - INTERFACE string LBRACE client-declarations RBRACE */ - +/* + * interface-declaration :== + * INTERFACE string LBRACE client-declarations RBRACE + */ void parse_interface_declaration(FILE *cfile, struct client_config *outer_config) { @@ -424,23 +430,25 @@ interface_or_dummy(char *name) /* Find the interface (if any) that matches the name. */ for (ip = interfaces; ip; ip = ip->next) - if (!strcmp (ip->name, name)) + if (!strcmp(ip->name, name)) break; /* If it's not a real interface, see if it's on the dummy list. */ if (!ip) for (ip = dummy_interfaces; ip; ip = ip->next) - if (!strcmp (ip->name, name)) + if (!strcmp(ip->name, name)) break; - /* If we didn't find an interface, make a dummy interface as - a placeholder. */ + /* + * If we didn't find an interface, make a dummy interface as a + * placeholder. + */ if (!ip) { - ip = malloc(sizeof *ip); + ip = malloc(sizeof(*ip)); if (!ip) error("Insufficient memory to record interface %s", name); - memset(ip, 0, sizeof *ip); + memset(ip, 0, sizeof(*ip)); strlcpy(ip->name, name, IFNAMSIZ); ip->next = dummy_interfaces; dummy_interfaces = ip; @@ -451,10 +459,10 @@ interface_or_dummy(char *name) void make_client_state(struct interface_info *ip) { - ip->client = malloc(sizeof *(ip->client)); + ip->client = malloc(sizeof(*(ip->client))); if (!ip->client) error("no memory for state on %s\n", ip->name); - memset(ip->client, 0, sizeof *(ip->client)); + memset(ip->client, 0, sizeof(*(ip->client))); } void @@ -463,19 +471,19 @@ make_client_config(struct interface_info *ip, struct client_config *config) ip->client->config = malloc(sizeof(struct client_config)); if (!ip->client->config) error("no memory for config for %s\n", ip->name); - memset(ip->client->config, 0, sizeof *(ip->client->config)); - memcpy(ip->client->config, config, sizeof *config); + memset(ip->client->config, 0, sizeof(*(ip->client->config))); + memcpy(ip->client->config, config, sizeof(*config)); } -/* client-lease-statement :== - RBRACE client-lease-declarations LBRACE - - client-lease-declarations :== - <nil> | - client-lease-declaration | - client-lease-declarations client-lease-declaration */ - - +/* + * client-lease-statement :== + * RBRACE client-lease-declarations LBRACE + * + * client-lease-declarations :== + * <nil> | + * client-lease-declaration | + * client-lease-declarations client-lease-declaration + */ void parse_client_lease_statement(FILE *cfile, int is_static) { @@ -494,7 +502,7 @@ parse_client_lease_statement(FILE *cfile, int is_static) lease = malloc(sizeof(struct client_lease)); if (!lease) error("no memory for lease.\n"); - memset(lease, 0, sizeof *lease); + memset(lease, 0, sizeof(*lease)); lease->is_static = is_static; ip = NULL; @@ -512,7 +520,8 @@ parse_client_lease_statement(FILE *cfile, int is_static) token = next_token(&val, cfile); /* If the lease declaration didn't include an interface - declaration that we recognized, it's of no use to us. */ + * declaration that we recognized, it's of no use to us. + */ if (!ip) { free_client_lease(lease); return; @@ -528,10 +537,12 @@ parse_client_lease_statement(FILE *cfile, int is_static) return; } - /* The new lease may supersede a lease that's not the - active lease but is still on the lease list, so scan the - lease list looking for a lease with the same address, and - if we find it, toss it. */ + /* + * The new lease may supersede a lease that's not the active + * lease but is still on the lease list, so scan the lease list + * looking for a lease with the same address, and if we find it, + * toss it. + */ pl = NULL; for (lp = ip->client->leases; lp; lp = lp->next) { if (lp->address.len == lease->address.len && @@ -546,25 +557,30 @@ parse_client_lease_statement(FILE *cfile, int is_static) } } - /* If this is a preloaded lease, just put it on the list of recorded - leases - don't make it the active lease. */ + /* + * If this is a preloaded lease, just put it on the list of + * recorded leases - don't make it the active lease. + */ if (is_static) { lease->next = ip->client->leases; ip->client->leases = lease; return; } - /* The last lease in the lease file on a particular interface is - the active lease for that interface. Of course, we don't know - what the last lease in the file is until we've parsed the whole - file, so at this point, we assume that the lease we just parsed - is the active lease for its interface. If there's already - an active lease for the interface, and this lease is for the same - ip address, then we just toss the old active lease and replace - it with this one. If this lease is for a different address, - then if the old active lease has expired, we dump it; if not, - we put it on the list of leases for this interface which are - still valid but no longer active. */ + /* + * The last lease in the lease file on a particular interface is + * the active lease for that interface. Of course, we don't + * know what the last lease in the file is until we've parsed + * the whole file, so at this point, we assume that the lease we + * just parsed is the active lease for its interface. If + * there's already an active lease for the interface, and this + * lease is for the same ip address, then we just toss the old + * active lease and replace it with this one. If this lease is + * for a different address, then if the old active lease has + * expired, we dump it; if not, we put it on the list of leases + * for this interface which are still valid but no longer + * active. + */ if (ip->client->active) { if (ip->client->active->expiry < cur_time) free_client_lease(ip->client->active); @@ -580,20 +596,21 @@ parse_client_lease_statement(FILE *cfile, int is_static) } ip->client->active = lease; - /* phew. */ + /* Phew. */ } -/* client-lease-declaration :== - BOOTP | - INTERFACE string | - FIXED_ADDR ip_address | - FILENAME string | - SERVER_NAME string | - OPTION option-decl | - RENEW time-decl | - REBIND time-decl | - EXPIRE time-decl */ - +/* + * client-lease-declaration :== + * BOOTP | + * INTERFACE string | + * FIXED_ADDR ip_address | + * FILENAME string | + * SERVER_NAME string | + * OPTION option-decl | + * RENEW time-decl | + * REBIND time-decl | + * EXPIRE time-decl + */ void parse_client_lease_declaration(FILE *cfile, struct client_lease *lease, struct interface_info **ipp) @@ -602,7 +619,7 @@ parse_client_lease_declaration(FILE *cfile, struct client_lease *lease, char *val; struct interface_info *ip; - switch (next_token (&val, cfile)) { + switch (next_token(&val, cfile)) { case BOOTP: lease->is_bootp = 1; break; @@ -680,14 +697,14 @@ parse_option_decl(FILE *cfile, struct option_data *options) if (asprintf(&vendor, "%s", val) == -1) error("no memory for vendor information."); - token = peek_token (&val, cfile); + token = peek_token(&val, cfile); if (token == DOT) { /* Go ahead and take the DOT token... */ token = next_token(&val, cfile); /* The next token should be an identifier... */ token = next_token(&val, cfile); - if (!is_identifier (token)) { + if (!is_identifier(token)) { parse_warn("expecting identifier after '.'"); if (token != SEMI) skip_to_semi(cfile); @@ -738,7 +755,7 @@ parse_option_decl(FILE *cfile, struct option_data *options) switch (*fmt) { case 'X': len = parse_X(cfile, &hunkbuf[hunkix], - sizeof hunkbuf - hunkix); + sizeof(hunkbuf) - hunkix); hunkix += len; break; case 't': /* Text string... */ @@ -749,7 +766,7 @@ parse_option_decl(FILE *cfile, struct option_data *options) return (NULL); } len = strlen(val); - if (hunkix + len + 1 > sizeof hunkbuf) { + if (hunkix + len + 1 > sizeof(hunkbuf)) { parse_warn("option data buffer %s", "overflow"); skip_to_semi(cfile); @@ -760,12 +777,12 @@ parse_option_decl(FILE *cfile, struct option_data *options) hunkix += len; break; case 'I': /* IP address. */ - if (!parse_ip_addr (cfile, &ip_addr)) + if (!parse_ip_addr(cfile, &ip_addr)) return (NULL); len = ip_addr.len; dp = ip_addr.iabuf; alloc: - if (hunkix + len > sizeof hunkbuf) { + if (hunkix + len > sizeof(hunkbuf)) { parse_warn("option data buffer " "overflow"); skip_to_semi(cfile); @@ -819,7 +836,7 @@ bad_flag: !strcasecmp(val, "on")) buf[0] = 1; else if (!strcasecmp(val, "false") || - !strcasecmp (val, "off")) + !strcasecmp(val, "off")) buf[0] = 0; else { parse_warn("expecting boolean."); @@ -905,7 +922,7 @@ parse_reject_statement(FILE *cfile, struct client_config *config) struct iaddrlist *list; do { - if (!parse_ip_addr (cfile, &addr)) { + if (!parse_ip_addr(cfile, &addr)) { parse_warn("expecting IP address."); skip_to_semi(cfile); return; diff --git a/sbin/dhclient/conflex.c b/sbin/dhclient/conflex.c index 508b6dcfc10..6235c08cf3f 100644 --- a/sbin/dhclient/conflex.c +++ b/sbin/dhclient/conflex.c @@ -1,4 +1,4 @@ -/* $OpenBSD: conflex.c,v 1.4 2004/02/04 12:16:56 henning Exp $ */ +/* $OpenBSD: conflex.c,v 1.5 2004/02/07 11:35:59 henning Exp $ */ /* Lexical scanner for dhcpd config file... */ @@ -40,9 +40,10 @@ * Enterprises, see ``http://www.vix.com''. */ +#include <ctype.h> + #include "dhcpd.h" #include "dhctoken.h" -#include <ctype.h> int lexline; int lexchar; @@ -86,7 +87,7 @@ new_parse(char *name) static int get_char(FILE *cfile) { - int c = getc (cfile); + int c = getc(cfile); if (!ugflag) { if (c == EOL) { if (cur_line == line1) { @@ -108,7 +109,7 @@ get_char(FILE *cfile) } } else ugflag = 0; - return c; + return (c); } static int @@ -123,7 +124,7 @@ get_token(FILE *cfile) p = lpos; u = ugflag; - c = get_char (cfile); + c = get_char(cfile); if (!(c == '\n' && eol_token) && isascii(c) && isspace(c)) continue; @@ -157,7 +158,7 @@ get_token(FILE *cfile) break; } } while (1); - return ttok; + return (ttok); } int @@ -241,11 +242,13 @@ read_string(FILE *cfile) else tokbuf[i] = c; } - /* Normally, I'd feel guilty about this, but we're talking about - strings that'll fit in a DHCP packet here... */ + /* + * Normally, I'd feel guilty about this, but we're talking about + * strings that'll fit in a DHCP packet here... + */ if (i == sizeof(tokbuf)) { parse_warn("string constant larger than internal buffer"); - --i; + i--; } tokbuf[i] = 0; tval = tokbuf; @@ -271,7 +274,7 @@ read_number(int c, FILE *cfile) } if (i == sizeof(tokbuf)) { parse_warn("numeric token larger than internal buffer"); - --i; + i--; } tokbuf[i] = 0; tval = tokbuf; @@ -299,7 +302,7 @@ read_num_or_name(int c, FILE *cfile) } if (i == sizeof(tokbuf)) { parse_warn("token larger than internal buffer"); - --i; + i--; } tokbuf[i] = 0; tval = tokbuf; @@ -311,7 +314,7 @@ static int intern(char *atom, int dfv) { if (!isascii(atom[0])) - return dfv; + return (dfv); switch (tolower(atom[0])) { case 'a': @@ -414,7 +417,7 @@ intern(char *atom, int dfv) case 'm': if (!strcasecmp(atom + 1, "ax-lease-time")) return (MAX_LEASE_TIME); - if (!strncasecmp (atom + 1, "edi", 3)) { + if (!strncasecmp(atom + 1, "edi", 3)) { if (!strcasecmp(atom + 4, "a")) return (MEDIA); if (!strcasecmp(atom + 4, "um")) @@ -495,7 +498,7 @@ intern(char *atom, int dfv) return (TOKEN_RING); break; case 'u': - if (!strncasecmp (atom + 1, "se", 2)) { + if (!strncasecmp(atom + 1, "se", 2)) { if (!strcasecmp(atom + 3, "r-class")) return (USER_CLASS); if (!strcasecmp(atom + 3, "-host-decl-names")) diff --git a/sbin/dhclient/convert.c b/sbin/dhclient/convert.c index d97912dad40..0626dc4b3a8 100644 --- a/sbin/dhclient/convert.c +++ b/sbin/dhclient/convert.c @@ -1,7 +1,9 @@ -/* $OpenBSD: convert.c,v 1.4 2004/02/04 12:16:56 henning Exp $ */ +/* $OpenBSD: convert.c,v 1.5 2004/02/07 11:35:59 henning Exp $ */ -/* Safe copying of option values into and out of the option buffer, which - can't be assumed to be aligned. */ +/* + * Safe copying of option values into and out of the option buffer, + * which can't be assumed to be aligned. + */ /* * Copyright (c) 1995, 1996 The Internet Software Consortium. @@ -46,7 +48,7 @@ u_int32_t getULong(unsigned char *buf) { - u_int32_t ibuf; + u_int32_t ibuf; memcpy(&ibuf, buf, sizeof(ibuf)); return (ntohl(ibuf)); @@ -55,7 +57,7 @@ getULong(unsigned char *buf) int32_t getLong(unsigned char *(buf)) { - int32_t ibuf; + int32_t ibuf; memcpy(&ibuf, buf, sizeof(ibuf)); return (ntohl(ibuf)); @@ -64,7 +66,7 @@ getLong(unsigned char *(buf)) u_int16_t getUShort(unsigned char *buf) { - u_int16_t ibuf; + u_int16_t ibuf; memcpy(&ibuf, buf, sizeof(ibuf)); return (ntohs(ibuf)); @@ -73,25 +75,24 @@ getUShort(unsigned char *buf) int16_t getShort(unsigned char *buf) { - int16_t ibuf; + int16_t ibuf; memcpy(&ibuf, buf, sizeof(ibuf)); - return (ntohs(ibuf)); } void putULong(unsigned char *obuf, u_int32_t val) { - u_int32_t tmp = htonl(val); + u_int32_t tmp = htonl(val); - memcpy(obuf, &tmp, sizeof tmp); + memcpy(obuf, &tmp, sizeof(tmp)); } void putLong(unsigned char *obuf, int32_t val) { - int32_t tmp = htonl(val); + int32_t tmp = htonl(val); memcpy(obuf, &tmp, sizeof(tmp)); } @@ -99,7 +100,7 @@ putLong(unsigned char *obuf, int32_t val) void putUShort(unsigned char *obuf, unsigned int val) { - u_int16_t tmp = htons(val); + u_int16_t tmp = htons(val); memcpy(obuf, &tmp, sizeof(tmp)); } @@ -107,8 +108,7 @@ putUShort(unsigned char *obuf, unsigned int val) void putShort(unsigned char *obuf, int val) { - int16_t tmp = htons(val); + int16_t tmp = htons(val); memcpy(obuf, &tmp, sizeof(tmp)); } - diff --git a/sbin/dhclient/dispatch.c b/sbin/dhclient/dispatch.c index 1edc57b4dde..e7bbdcad13b 100644 --- a/sbin/dhclient/dispatch.c +++ b/sbin/dhclient/dispatch.c @@ -1,4 +1,4 @@ -/* $OpenBSD: dispatch.c,v 1.4 2004/02/04 12:16:56 henning Exp $ */ +/* $OpenBSD: dispatch.c,v 1.5 2004/02/07 11:35:59 henning Exp $ */ /* Network input dispatcher... */ @@ -41,10 +41,12 @@ */ #include "dhcpd.h" -#include <ifaddrs.h> + #include <sys/ioctl.h> -#include <poll.h> + #include <net/if_media.h> +#include <ifaddrs.h> +#include <poll.h> /* Most boxes has less than 16 interfaces, so this might be a good guess. */ #define INITIAL_IFREQ_COUNT 16 @@ -62,11 +64,12 @@ static int interface_status(struct interface_info *ifinfo); int quiet_interface_discovery; -/* Use getifaddrs() to get a list of all the attached interfaces. - For each interface that's of type INET and not the loopback interface, - register that interface with the network I/O software, figure out what - subnet it's on, and add it to the list of interfaces. */ - +/* + * Use getifaddrs() to get a list of all the attached interfaces. For + * each interface that's of type INET and not the loopback interface, + * register that interface with the network I/O software, figure out + * what subnet it's on, and add it to the list of interfaces. + */ void discover_interfaces(int state) { @@ -83,10 +86,12 @@ discover_interfaces(int state) #endif if (getifaddrs(&ifap) != 0) - error ("getifaddrs failed"); + error("getifaddrs failed"); - /* If we already have a list of interfaces, and we're running as - a DHCP server, the interfaces were requested. */ + /* + * If we already have a list of interfaces, and we're running as + * a DHCP server, the interfaces were requested. + */ if (interfaces && (state == DISCOVER_SERVER || state == DISCOVER_RELAY || state == DISCOVER_REQUESTED)) ir = 0; @@ -97,46 +102,52 @@ discover_interfaces(int state) /* Cycle through the list of interfaces looking for IP addresses. */ for (ifa = ifap; ifa != NULL; ifa = ifa->ifa_next) { - /* See if this is the sort of interface we want to - deal with. Skip loopback, point-to-point and down - interfaces, except don't skip down interfaces if we're - trying to get a list of configurable interfaces. */ + /* + * See if this is the sort of interface we want to deal + * with. Skip loopback, point-to-point and down + * interfaces, except don't skip down interfaces if + * we're trying to get a list of configurable + * interfaces. + */ if ((ifa->ifa_flags & IFF_LOOPBACK) || (ifa->ifa_flags & IFF_POINTOPOINT) || (!(ifa->ifa_flags & IFF_UP) && state != DISCOVER_UNCONFIGURED)) continue; - + /* See if we've seen an interface that matches this one. */ for (tmp = interfaces; tmp; tmp = tmp->next) - if (!strcmp (tmp->name, ifa->ifa_name)) + if (!strcmp(tmp->name, ifa->ifa_name)) break; - /* If there isn't already an interface by this name, - allocate one. */ + /* + * If there isn't already an interface by this name, + * allocate one. + */ if (!tmp) { - tmp = ((struct interface_info *) - dmalloc (sizeof *tmp, "discover_interfaces")); + tmp = dmalloc(sizeof(*tmp), "discover_interfaces"); if (!tmp) - error ("Insufficient memory to %s %s", - "record interface", ifa->ifa_name); - strlcpy (tmp->name, ifa->ifa_name, sizeof(tmp->name)); + error("Insufficient memory to %s %s", + "record interface", ifa->ifa_name); + strlcpy(tmp->name, ifa->ifa_name, sizeof(tmp->name)); tmp->next = interfaces; tmp->flags = ir; tmp->noifmedia = tmp->dead = tmp->errors = 0; interfaces = tmp; } - /* If we have the capability, extract link information - and record it in a linked list. */ + /* + * If we have the capability, extract link information + * and record it in a linked list. + */ if (ifa->ifa_addr->sa_family == AF_LINK) { - struct sockaddr_dl *foo = ((struct sockaddr_dl *) - (ifa->ifa_addr)); + struct sockaddr_dl *foo = + (struct sockaddr_dl *)ifa->ifa_addr; tmp->index = foo->sdl_index; tmp->hw_address.hlen = foo->sdl_alen; tmp->hw_address.htype = HTYPE_ETHER; /* XXX */ memcpy(tmp->hw_address.haddr, - LLADDR (foo), foo->sdl_alen); + LLADDR(foo), foo->sdl_alen); } else if (ifa->ifa_addr->sa_family == AF_INET) { struct iaddr addr; @@ -144,15 +155,17 @@ discover_interfaces(int state) bcopy(ifa->ifa_addr, &foo, sizeof(foo)); /* We don't want the loopback interface. */ - if (foo.sin_addr.s_addr == htonl (INADDR_LOOPBACK)) + if (foo.sin_addr.s_addr == htonl(INADDR_LOOPBACK)) continue; - /* If this is the first real IP address we've - found, keep a pointer to ifreq structure in - which we found it. */ + /* + * If this is the first real IP address we've + * found, keep a pointer to ifreq structure in + * which we found it. + */ if (!tmp->ifp) { - int len = (IFNAMSIZ + ifa->ifa_addr->sa_len); - tif = (struct ifreq *)malloc (len); + int len = IFNAMSIZ + ifa->ifa_addr->sa_len; + tif = malloc(len); if (!tif) error("no space to remember ifp."); strlcpy(tif->ifr_name, ifa->ifa_name, IFNAMSIZ); @@ -175,46 +188,47 @@ discover_interfaces(int state) if (!subnet->interface) { subnet->interface = tmp; subnet->interface_address = addr; - } else if (subnet->interface != tmp) { - warn ("Multiple %s %s: %s %s", - "interfaces match the", - "same subnet", - subnet->interface->name, - tmp->name); - } + } else if (subnet->interface != tmp) + warn("Multiple %s %s: %s %s", + "interfaces match the", + "same subnet", + subnet->interface->name, + tmp->name); share = subnet->shared_network; if (tmp->shared_network && - tmp->shared_network != share) { - warn ("Interface %s matches %s", - tmp->name, - "multiple shared networks"); - } else { + tmp->shared_network != share) + warn("Interface %s matches %s", + tmp->name, + "multiple shared networks"); + else tmp->shared_network = share; - } - if (!share->interface) { + if (!share->interface) share->interface = tmp; - } else if (share->interface != tmp) { - warn ("Multiple %s %s: %s %s", - "interfaces match the", - "same shared network", - share->interface->name, - tmp->name); - } + else if (share->interface != tmp) + warn("Multiple %s %s: %s %s", + "interfaces match the", + "same shared network", + share->interface->name, + tmp->name); } } } - /* Now cycle through all the interfaces we found, looking for - hardware addresses. */ + /* + * Now cycle through all the interfaces we found, looking for + * hardware addresses. + */ - /* If we're just trying to get a list of interfaces that we might - be able to configure, we can quit now. */ + /* + * If we're just trying to get a list of interfaces that we might + * be able to configure, we can quit now. + */ if (state == DISCOVER_UNCONFIGURED) return; /* Weed out the interfaces that did not have IP addresses. */ - last = (struct interface_info *)0; + last = NULL; for (tmp = interfaces; tmp; tmp = next) { next = tmp->next; if ((tmp->flags & INTERFACE_AUTOMATIC) && @@ -223,26 +237,28 @@ discover_interfaces(int state) INTERFACE_REQUESTED); if (!tmp->ifp || !(tmp->flags & INTERFACE_REQUESTED)) { if ((tmp->flags & INTERFACE_REQUESTED) != ir) - error ("%s: not found", tmp->name); + error("%s: not found", tmp->name); if (!last) interfaces = interfaces->next; else last->next = tmp->next; - /* Remember the interface in case we need to know - about it later. */ + /* + * Remember the interface in case we need to know + * about it later. + */ tmp->next = dummy_interfaces; dummy_interfaces = tmp; continue; } last = tmp; - memcpy (&foo, &tmp->ifp->ifr_addr, sizeof tmp->ifp->ifr_addr); + memcpy(&foo, &tmp->ifp->ifr_addr, sizeof(tmp->ifp->ifr_addr)); /* We must have a subnet declaration for each interface. */ if (!tmp->shared_network && (state == DISCOVER_SERVER)) { warn("No subnet declaration for %s (%s).", - tmp->name, inet_ntoa (foo.sin_addr)); + tmp->name, inet_ntoa(foo.sin_addr)); warn("Please write a subnet declaration in your %s", "dhcpd.conf file for the"); error("network segment to which interface %s %s", @@ -253,7 +269,7 @@ discover_interfaces(int state) addresses... */ for (subnet = (tmp->shared_network ? tmp->shared_network->subnets : NULL); - subnet; subnet = subnet->next_sibling) { + subnet; subnet = subnet->next_sibling) if (!subnet->interface_address.len) { /* Set the interface address for this subnet to the first address we found. */ @@ -261,7 +277,6 @@ discover_interfaces(int state) memcpy(subnet->interface_address.iabuf, &foo.sin_addr.s_addr, 4); } - } /* Register the interface... */ if_register_receive(tmp); @@ -270,7 +285,7 @@ discover_interfaces(int state) /* Now register all the remaining interfaces as protocols. */ for (tmp = interfaces; tmp; tmp = tmp->next) - add_protocol (tmp->name, tmp->rfdesc, got_one, tmp); + add_protocol(tmp->name, tmp->rfdesc, got_one, tmp); freeifaddrs(ifap); @@ -281,10 +296,10 @@ struct interface_info * setup_fallback(void) { fallback_interface = - dmalloc(sizeof *fallback_interface, "discover_interfaces"); + dmalloc(sizeof(*fallback_interface), "discover_interfaces"); if (!fallback_interface) error("Insufficient memory to record fallback interface."); - memset(fallback_interface, 0, sizeof *fallback_interface); + memset(fallback_interface, 0, sizeof(*fallback_interface)); strlcpy(fallback_interface->name, "fallback", IFNAMSIZ); fallback_interface->shared_network = new_shared_network("parse_statement"); @@ -293,7 +308,7 @@ setup_fallback(void) memset(fallback_interface->shared_network, 0, sizeof(struct shared_network)); fallback_interface->shared_network->name = "fallback-net"; - return fallback_interface; + return (fallback_interface); } void @@ -302,21 +317,22 @@ reinitialize_interfaces(void) struct interface_info *ip; for (ip = interfaces; ip; ip = ip->next) { - if_reinitialize_receive (ip); - if_reinitialize_send (ip); + if_reinitialize_receive(ip); + if_reinitialize_send(ip); } if (fallback_interface) - if_reinitialize_send (fallback_interface); + if_reinitialize_send(fallback_interface); interfaces_invalidated = 1; } -/* Wait for packets to come in using poll(). When a packet comes in, - call receive_packet to receive the packet and possibly strip hardware - addressing information from it, and then call through the - bootp_packet_handler hook to try to do something with it. */ - +/* + * Wait for packets to come in using poll(). When a packet comes in, + * call receive_packet to receive the packet and possibly strip hardware + * addressing information from it, and then call through the + * bootp_packet_handler hook to try to do something with it. + */ void dispatch(void) { @@ -330,34 +346,35 @@ dispatch(void) nfds = 0; for (l = protocols; l; l = l->next) - ++nfds; + nfds++; - fds = malloc((nfds) * sizeof (struct pollfd)); + fds = malloc(nfds * sizeof(struct pollfd)); if (fds == NULL) - error ("Can't allocate poll structures."); + error("Can't allocate poll structures."); do { - /* Call any expired timeouts, and then if there's - still a timeout registered, time out the select - call then. */ + /* + * Call any expired timeouts, and then if there's still + * a timeout registered, time out the select call then. + */ another: if (timeouts) { struct timeout *t; if (timeouts->when <= cur_time) { t = timeouts; timeouts = timeouts->next; - (*(t->func)) (t->what); + (*(t->func))(t->what); t->next = free_timeouts; free_timeouts = t; goto another; } + /* * Figure timeout in milliseconds, and check for - * potential overflow, so we can cram into an int - * for poll, while not polling with a negative - * timeout and blocking indefinetely. + * potential overflow, so we can cram into an + * int for poll, while not polling with a + * negative timeout and blocking indefinetely. */ - howlong = timeouts->when - cur_time; if (howlong > INT_MAX / 1000) howlong = INT_MAX / 1000; @@ -367,49 +384,49 @@ another: /* Set up the descriptors to be polled. */ i = 0; - + for (l = protocols; l; l = l->next) { struct interface_info *ip = l->local; if (ip && (l->handler != got_one || !ip->dead)) { - fds [i].fd = l->fd; - fds [i].events = POLLIN; - fds [i].revents = 0; - ++i; + fds[i].fd = l->fd; + fds[i].events = POLLIN; + fds[i].revents = 0; + i++; } } - if (i == 0) + if (i == 0) error("No live interfaces to poll on - exiting."); - + /* Wait for a packet or a timeout... XXX */ - count = poll (fds, nfds, to_msec); + count = poll(fds, nfds, to_msec); /* Not likely to be transitory... */ if (count == -1) { if (errno == EAGAIN || errno == EINTR) { - GET_TIME (&cur_time); + GET_TIME(&cur_time); continue; } else - error ("poll: %m"); + error("poll: %m"); } /* Get the current time... */ - GET_TIME (&cur_time); + GET_TIME(&cur_time); i = 0; for (l = protocols; l; l = l->next) { struct interface_info *ip; ip = l->local; - if ((fds [i].revents & POLLIN)) { - fds [i].revents = 0; + if ((fds[i].revents & POLLIN)) { + fds[i].revents = 0; if (ip && (l->handler != got_one || !ip->dead)) - (*(l->handler)) (l); + (*(l->handler))(l); if (interfaces_invalidated) break; } - ++i; + i++; } interfaces_invalidated = 0; } while (1); @@ -424,23 +441,25 @@ got_one(struct protocol *l) struct iaddr ifrom; size_t result; union { - unsigned char packbuf[4095]; /* Packet input buffer. - Must be as large as largest - possible MTU. */ + /* + * Packet input buffer. Must be as large as largest + * possible MTU. + */ + unsigned char packbuf[4095]; struct dhcp_packet packet; } u; struct interface_info *ip = l->local; if ((result = - receive_packet(ip, u.packbuf, sizeof u, &from, &hfrom)) == -1) { - warn("receive_packet failed on %s: %s", ip->name, + receive_packet(ip, u.packbuf, sizeof(u), &from, &hfrom)) == -1) { + warn("receive_packet failed on %s: %s", ip->name, strerror(errno)); ip->errors++; - if ((! interface_status(ip)) || + if ((!interface_status(ip)) || (ip->noifmedia && ip->errors > 20)) { /* our interface has gone away. */ warn("Interface %s no longer appears valid.", - ip->name); + ip->name); ip->dead = 1; interfaces_invalidated = 1; close(l->fd); @@ -464,17 +483,16 @@ got_one(struct protocol *l) int interface_status(struct interface_info *ifinfo) { - char * ifname = ifinfo->name; + char *ifname = ifinfo->name; int ifsock = ifinfo->rfdesc; struct ifreq ifr; struct ifmediareq ifmr; - + /* get interface flags */ memset(&ifr, 0, sizeof(ifr)); strlcpy(ifr.ifr_name, ifname, sizeof(ifr.ifr_name)); if (ioctl(ifsock, SIOCGIFFLAGS, &ifr) < 0) { - syslog(LOG_ERR, "ioctl(SIOCGIFFLAGS) on %s: %m", - ifname); + syslog(LOG_ERR, "ioctl(SIOCGIFFLAGS) on %s: %m", ifname); goto inactive; } /* @@ -485,7 +503,7 @@ interface_status(struct interface_info *ifinfo) goto inactive; } /* Next, check carrier on the interface, if possible */ - if (ifinfo->noifmedia) + if (ifinfo->noifmedia) goto active; memset(&ifmr, 0, sizeof(ifmr)); strlcpy(ifmr.ifm_name, ifname, sizeof(ifmr.ifm_name)); @@ -497,7 +515,7 @@ interface_status(struct interface_info *ifinfo) goto active; } /* - * EINVAL (or ENOTTY) simply means that the interface + * EINVAL (or ENOTTY) simply means that the interface * does not support the SIOCGIFMEDIA ioctl. We regard it alive. */ ifinfo->noifmedia = 1; @@ -516,9 +534,9 @@ interface_status(struct interface_info *ifinfo) } } inactive: - return(0); + return (0); active: - return(1); + return (1); } int @@ -530,19 +548,18 @@ locate_network(struct packet *packet) if (packet->raw->giaddr.s_addr) { struct subnet *subnet; ia.len = 4; - memcpy (ia.iabuf, &packet->raw->giaddr, 4); - subnet = find_subnet (ia); + memcpy(ia.iabuf, &packet->raw->giaddr, 4); + subnet = find_subnet(ia); if (subnet) packet->shared_network = subnet->shared_network; else - packet->shared_network = (struct shared_network *)0; + packet->shared_network = NULL; } else - packet->shared_network = - packet->interface->shared_network; + packet->shared_network = packet->interface->shared_network; if (packet->shared_network) - return 1; - return 0; + return (1); + return (0); } void @@ -551,7 +568,7 @@ add_timeout(TIME when, void (*where)(void *), void *what) struct timeout *t, *q; /* See if this timeout supersedes an existing timeout. */ - t = (struct timeout *)0; + t = NULL; for (q = timeouts; q; q = q->next) { if (q->func == where && q->what == what) { if (t) @@ -572,9 +589,9 @@ add_timeout(TIME when, void (*where)(void *), void *what) q->func = where; q->what = what; } else { - q = (struct timeout *)malloc (sizeof (struct timeout)); + q = malloc(sizeof(struct timeout)); if (!q) - error ("Can't allocate timeout structure!"); + error("Can't allocate timeout structure!"); q->func = where; q->what = what; } @@ -602,7 +619,7 @@ add_timeout(TIME when, void (*where)(void *), void *what) /* End of list. */ t->next = q; - q->next = (struct timeout *)0; + q->next = NULL; } void @@ -611,7 +628,7 @@ cancel_timeout(void (*where)(void *), void *what) struct timeout *t, *q; /* Look for this timeout on the list, and unlink it if we find it. */ - t = (struct timeout *)0; + t = NULL; for (q = timeouts; q; q = q->next) { if (q->func == where && q->what == what) { if (t) @@ -637,9 +654,9 @@ add_protocol(char *name, int fd, void (*handler)(struct protocol *), { struct protocol *p; - p = (struct protocol *)malloc (sizeof *p); + p = malloc(sizeof(*p)); if (!p) - error ("can't allocate protocol struct for %s", name); + error("can't allocate protocol struct for %s", name); p->fd = fd; p->handler = handler; @@ -654,7 +671,7 @@ remove_protocol(struct protocol *proto) { struct protocol *p, *next, *prev; - prev = (struct protocol *)0; + prev = NULL; for (p = protocols; p; p = next) { next = p->next; if (p == proto) { @@ -662,7 +679,7 @@ remove_protocol(struct protocol *proto) prev->next = p->next; else protocols = p->next; - free (p); + free(p); } } } |