summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2009-07-08 16:52:45 +0000
committerRoy Marples <roy@marples.name>2009-07-08 16:52:45 +0000
commit9c2bf36ccef779d1242dd06a553c9c015c23f984 (patch)
treee380c119b2ddd1620f60f200f39f3389cd2b9020
parent57af27b81db2fb128d94b727061f9a3917d2c547 (diff)
downloaddhcpcd-9c2bf36ccef779d1242dd06a553c9c015c23f984.tar.xz
Change get_option_addr to accept struct in_addr * instead of uint32_t *
to fix an alignment issue on SGI MIPS. Thanks to Tim McIntosh.
-rw-r--r--client.c12
-rw-r--r--configure.c4
-rw-r--r--dhcp.c18
-rw-r--r--dhcp.h2
4 files changed, 19 insertions, 17 deletions
diff --git a/client.c b/client.c
index 394bde2d..55d7c8b9 100644
--- 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);
}
diff --git a/configure.c b/configure.c
index f7e0c164..1e6daebf 100644
--- a/configure.c
+++ b/configure.c
@@ -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 89ca9afb..aed06bf1 100644
--- 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 e584452c..09e8ecb1 100644
--- 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);