In order to avoid clang error, just use memcpy() when reading
or setting variable according to memory buffer read from wire.
---
gdhcp/client.c | 14 +++++++-------
gdhcp/common.c | 2 +-
gdhcp/server.c | 9 ++++-----
3 files changed, 12 insertions(+), 13 deletions(-)
diff --git a/gdhcp/client.c b/gdhcp/client.c
index cf04ced..d5f1daa 100644
--- a/gdhcp/client.c
+++ b/gdhcp/client.c
@@ -1340,7 +1340,7 @@ static uint32_t get_lease(struct dhcp_packet *packet)
if (option_u8 == NULL)
return 3600;
- lease_seconds = dhcp_get_unaligned((uint32_t *) option_u8);
+ memcpy(&lease_seconds, option_u8, sizeof(lease_seconds));
lease_seconds = ntohl(lease_seconds);
/* paranoia: must not be prone to overflows */
lease_seconds &= 0x0fffffff;
@@ -1518,14 +1518,14 @@ static char *malloc_option_value_string(uint8_t
*option, GDHCPOptionType type)
dest += sprint_nip(dest, "", option);
break;
case OPTION_U16: {
- uint16_t val_u16 = dhcp_get_unaligned(
- (uint16_t *) option);
+ uint16_t val_u16;
+ memcpy(&val_u16, option, sizeof(val_u16));
dest += sprintf(dest, "%u", ntohs(val_u16));
break;
}
case OPTION_U32: {
- uint32_t val_u32 = dhcp_get_unaligned(
- (uint32_t *) option);
+ uint32_t val_u32;
+ memcpy(&val_u32, option, sizeof(val_u32));
dest += sprintf(dest, type == OPTION_U32 ? "%lu" :
"%ld", (unsigned long) ntohl(val_u32));
break;
@@ -1924,8 +1924,8 @@ static gboolean listener_event(GIOChannel *channel,
GIOCondition condition,
dhcp_client->retry_times = 0;
option_u8 = dhcp_get_option(&packet, DHCP_SERVER_ID);
- dhcp_client->server_ip =
- dhcp_get_unaligned((uint32_t *) option_u8);
+ memcpy(&dhcp_client->server_ip, option_u8,
+ sizeof(dhcp_client->server_ip));
dhcp_client->requested_ip = packet.yiaddr;
dhcp_client->state = REQUESTING;
diff --git a/gdhcp/common.c b/gdhcp/common.c
index 8d5c284..ae062f3 100644
--- a/gdhcp/common.c
+++ b/gdhcp/common.c
@@ -284,7 +284,7 @@ void dhcp_add_simple_option(struct dhcp_packet *packet,
uint8_t code,
data <<= 8 * (4 - len);
#endif
- dhcp_put_unaligned(data, (uint32_t *)(option + OPT_DATA));
+ memcpy(option + OPT_DATA, &data, len);
dhcp_add_binary_option(packet, option);
return;
diff --git a/gdhcp/server.c b/gdhcp/server.c
index a342985..6dec651 100644
--- a/gdhcp/server.c
+++ b/gdhcp/server.c
@@ -664,17 +664,16 @@ static gboolean listener_event(GIOChannel *channel,
GIOCondition condition,
server_id_option = dhcp_get_option(&packet, DHCP_SERVER_ID);
if (server_id_option) {
- uint32_t server_nid = dhcp_get_unaligned(
- (uint32_t *) server_id_option);
-
+ uint32_t server_nid;
+ memcpy(&server_nid, server_id_option, sizeof(server_nid));
if (server_nid != dhcp_server->server_nip)
return TRUE;
}
request_ip_option = dhcp_get_option(&packet, DHCP_REQUESTED_IP);
if (request_ip_option)
- requested_nip = dhcp_get_unaligned(
- (uint32_t *) request_ip_option);
+ memcpy(&requested_nip, request_ip_option,
+ sizeof(requested_nip));
lease = find_lease_by_mac(dhcp_server, packet.chaddr);
--
1.7.11.4
_______________________________________________
connman mailing list
[email protected]
http://lists.connman.net/listinfo/connman