]> git.ipfire.org Git - thirdparty/dhcpcd.git/commitdiff
Change get_option_addr to accept struct in_addr * instead of uint32_t *
authorRoy Marples <roy@marples.name>
Wed, 8 Jul 2009 16:52:45 +0000 (16:52 +0000)
committerRoy Marples <roy@marples.name>
Wed, 8 Jul 2009 16:52:45 +0000 (16:52 +0000)
to fix an alignment issue on SGI MIPS.
Thanks to Tim McIntosh.

client.c
configure.c
dhcp.c
dhcp.h

index 394bde2d8fb4f8ee44cafb4279fa604a81071320..55d7c8b9ba305ccfcb084127f3b7f67c0545f67d 100644 (file)
--- a/client.c
+++ b/client.c
@@ -368,7 +368,7 @@ get_lease(struct dhcp_lease *lease, const struct dhcp_message *dhcp)
                return;
        lease->addr.s_addr = dhcp->yiaddr;
 
-       if (get_option_addr(&lease->net.s_addr, dhcp, DHO_SUBNETMASK) == -1)
+       if (get_option_addr(&lease->net, dhcp, DHO_SUBNETMASK) == -1)
                lease->net.s_addr = get_netmask(dhcp->yiaddr);
        if (get_option_uint32(&lease->leasetime, dhcp, DHO_LEASETIME) == 0) {
                /* Ensure that we can use the lease */
@@ -1361,7 +1361,7 @@ log_dhcp(int lvl, const char *msg, const struct dhcp_message *dhcp)
                addr.s_addr = dhcp->yiaddr;
                a = xstrdup(inet_ntoa(addr));
        }
-       r = get_option_addr(&addr.s_addr, dhcp, DHO_SERVERID);
+       r = get_option_addr(&addr, dhcp, DHO_SERVERID);
        if (dhcp->servername[0] && r == 0)
                logger(lvl, "%s %s from %s `%s'", msg, a,
                       inet_ntoa(addr), dhcp->servername);
@@ -1393,7 +1393,7 @@ handle_dhcp(struct if_state *state, struct dhcp_message **dhcpp,
                return 0;
        }
        /* Every DHCP message should include ServerID */
-       if (get_option_addr(&addr.s_addr, dhcp, DHO_SERVERID) == -1) {
+       if (get_option_addr(&addr, dhcp, DHO_SERVERID) == -1) {
                logger(LOG_ERR, "ignoring message; no Server ID");
                return 0;
        }
@@ -1402,7 +1402,7 @@ handle_dhcp(struct if_state *state, struct dhcp_message **dhcpp,
         * We should expand this to check IP and/or hardware address
         * at the packet level. */
        if (options->blacklist_len != 0 &&
-           get_option_addr(&addr.s_addr, dhcp, DHO_SERVERID) == 0)
+           get_option_addr(&addr, dhcp, DHO_SERVERID) == 0)
        {
                for (i = 0; i < options->blacklist_len; i++) {
                        if (options->blacklist[i] != addr.s_addr)
@@ -1454,7 +1454,7 @@ handle_dhcp(struct if_state *state, struct dhcp_message **dhcpp,
 
        if (type == DHCP_OFFER && state->state == STATE_DISCOVERING) {
                lease->addr.s_addr = dhcp->yiaddr;
-               get_option_addr(&lease->server.s_addr, dhcp, DHO_SERVERID);
+               get_option_addr(&lease->server, dhcp, DHO_SERVERID);
                log_dhcp(LOG_INFO, "offered", dhcp);
                if (state->options & DHCPCD_TEST) {
                        run_script(options, iface->name, "TEST", dhcp, NULL);
@@ -1487,7 +1487,7 @@ handle_dhcp(struct if_state *state, struct dhcp_message **dhcpp,
        case STATE_RENEWING:
        case STATE_REBINDING:
                if (!(state->options & DHCPCD_INFORM)) {
-                       get_option_addr(&lease->server.s_addr,
+                       get_option_addr(&lease->server,
                                        dhcp, DHO_SERVERID);
                        log_dhcp(LOG_INFO, "acknowledged", dhcp);
                }
index f7e0c164790071c7546fa0aff07256b25b6d51f0..1e6daebfdf52c88035c26851d4dd84a6fc92b236 100644 (file)
@@ -357,9 +357,9 @@ configure(struct interface *iface, const char *reason,
                if (addr.s_addr == 0)
                        addr.s_addr = lease->addr.s_addr;
                /* Ensure we have all the needed values */
-               if (get_option_addr(&net.s_addr, dhcp, DHO_SUBNETMASK) == -1)
+               if (get_option_addr(&net, dhcp, DHO_SUBNETMASK) == -1)
                        net.s_addr = get_netmask(addr.s_addr);
-               if (get_option_addr(&brd.s_addr, dhcp, DHO_BROADCAST) == -1)
+               if (get_option_addr(&brd, dhcp, DHO_BROADCAST) == -1)
                        brd.s_addr = addr.s_addr | ~net.s_addr;
        }
 
diff --git a/dhcp.c b/dhcp.c
index 89ca9afb39cb8900418dc3bcd0126285a11abd2d..aed06bf103661c8aaf924418d9bca9da5103190f 100644 (file)
--- a/dhcp.c
+++ b/dhcp.c
@@ -327,25 +327,27 @@ exit:
 }
 
 int
-get_option_addr(uint32_t *a, const struct dhcp_message *dhcp, uint8_t option)
+get_option_addr(struct in_addr *a, const struct dhcp_message *dhcp,
+    uint8_t option)
 {
        const uint8_t *p = get_option_raw(dhcp, option);
 
        if (!p)
                return -1;
-       memcpy(a, p, sizeof(*a));
+       memcpy(&a->s_addr, p, sizeof(a->s_addr));
        return 0;
 }
 
 int
 get_option_uint32(uint32_t *i, const struct dhcp_message *dhcp, uint8_t option)
 {
-       uint32_t a;
+       const uint8_t *p = get_option_raw(dhcp, option);
+       uint32_t d;
 
-       if (get_option_addr(&a, dhcp, option) == -1)
+       if (!p)
                return -1;
-
-       *i = ntohl(a);
+       memcpy(&d, p, sizeof(d));
+       *i = ntohl(d);
        return 0;
 }
 
@@ -1231,14 +1233,14 @@ configure_env(char **env, const char *prefix, const struct dhcp_message *dhcp,
                 * message but are not necessarily in the options */
                addr.s_addr = dhcp->yiaddr;
                setvar(&ep, prefix, "ip_address", inet_ntoa(addr));
-               if (get_option_addr(&net.s_addr, dhcp, DHO_SUBNETMASK) == -1) {
+               if (get_option_addr(&net, dhcp, DHO_SUBNETMASK) == -1) {
                        net.s_addr = get_netmask(addr.s_addr);
                        setvar(&ep, prefix, "subnet_mask", inet_ntoa(net));
                }
                i = inet_ntocidr(net);
                snprintf(cidr, sizeof(cidr), "%d", inet_ntocidr(net));
                setvar(&ep, prefix, "subnet_cidr", cidr);
-               if (get_option_addr(&brd.s_addr, dhcp, DHO_BROADCAST) == -1) {
+               if (get_option_addr(&brd, dhcp, DHO_BROADCAST) == -1) {
                        brd.s_addr = addr.s_addr | ~net.s_addr;
                        setvar(&ep, prefix, "broadcast_address", inet_ntoa(brd));
                }
diff --git a/dhcp.h b/dhcp.h
index e584452c2a02240c3a02ccf8839515582daf16e1..09e8ecb156b25e73dec358f0260d3cb33086d70c 100644 (file)
--- a/dhcp.h
+++ b/dhcp.h
@@ -160,7 +160,7 @@ struct dhcp_lease {
 int make_option_mask(uint8_t *, char **, int);
 void print_options(void);
 char *get_option_string(const struct dhcp_message *, uint8_t);
-int get_option_addr(uint32_t *, const struct dhcp_message *, uint8_t);
+int get_option_addr(struct in_addr *, const struct dhcp_message *, uint8_t);
 int get_option_uint32(uint32_t *, const struct dhcp_message *, uint8_t);
 int get_option_uint16(uint16_t *, const struct dhcp_message *, uint8_t);
 int get_option_uint8(uint8_t *, const struct dhcp_message *, uint8_t);