summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorRoy Marples <roy@marples.name>2020-05-05 19:03:49 +0000
committerRoy Marples <roy@marples.name>2020-05-05 19:03:49 +0000
commit904b0f7288119a7ddcd9aa862530746031cb9e36 (patch)
treeb619211829fb48f9eda1a40c1c71f6ce54baf0a2 /src
parentc0567cc03ec3a75d8edab2abb5789efda54d4c66 (diff)
downloaddhcpcd-904b0f7288119a7ddcd9aa862530746031cb9e36.tar.xz
DHCP: Use correct buffer for receiving UDP
Big wup! While here, ensure buffer is aligned to the structure we want to read.
Diffstat (limited to 'src')
-rw-r--r--src/dhcp.c13
-rw-r--r--src/dhcp6.c8
-rw-r--r--src/ipv6nd.c8
3 files changed, 18 insertions, 11 deletions
diff --git a/src/dhcp.c b/src/dhcp.c
index 927f2137..23ba8761 100644
--- a/src/dhcp.c
+++ b/src/dhcp.c
@@ -3599,7 +3599,7 @@ dhcp_recvmsg(struct dhcpcd_ctx *ctx, struct msghdr *msg)
}
#endif
- dhcp_handlebootp(ifp, (struct bootp *)iov->iov_base, iov->iov_len,
+ dhcp_handlebootp(ifp, iov->iov_base, iov->iov_len,
&from->sin_addr);
}
@@ -3608,10 +3608,13 @@ dhcp_readudp(struct dhcpcd_ctx *ctx, struct interface *ifp)
{
const struct dhcp_state *state;
struct sockaddr_in from;
- unsigned char buf[10 * 1024]; /* Maximum MTU */
+ union {
+ struct bootp bootp;
+ uint8_t buf[10 * 1024]; /* Maximum MTU */
+ } iovbuf;
struct iovec iov = {
- .iov_base = buf,
- .iov_len = sizeof(buf),
+ .iov_base = iovbuf.buf,
+ .iov_len = sizeof(iovbuf.buf),
};
union {
struct cmsghdr hdr;
@@ -3624,7 +3627,7 @@ dhcp_readudp(struct dhcpcd_ctx *ctx, struct interface *ifp)
struct msghdr msg = {
.msg_name = &from, .msg_namelen = sizeof(from),
.msg_iov = &iov, .msg_iovlen = 1,
- .msg_control = buf, .msg_controllen = sizeof(cmsgbuf.buf),
+ .msg_control = cmsgbuf.buf, .msg_controllen = sizeof(cmsgbuf.buf),
};
int s;
ssize_t bytes;
diff --git a/src/dhcp6.c b/src/dhcp6.c
index 0f2f324b..2c0fed52 100644
--- a/src/dhcp6.c
+++ b/src/dhcp6.c
@@ -3721,10 +3721,12 @@ static void
dhcp6_recv(struct dhcpcd_ctx *ctx, struct ipv6_addr *ia)
{
struct sockaddr_in6 from;
- unsigned char buf[64 * 1024]; /* Maximum UDP message size */
+ union {
+ struct dhcp6_message dhcp6;
+ uint8_t buf[64 * 1024]; /* Maximum UDP message size */
+ } iovbuf;
struct iovec iov = {
- .iov_base = buf,
- .iov_len = sizeof(buf),
+ .iov_base = iovbuf.buf, .iov_len = sizeof(iovbuf.buf),
};
union {
struct cmsghdr hdr;
diff --git a/src/ipv6nd.c b/src/ipv6nd.c
index 73df9109..ae267c7a 100644
--- a/src/ipv6nd.c
+++ b/src/ipv6nd.c
@@ -1937,10 +1937,12 @@ ipv6nd_handledata(void *arg)
struct dhcpcd_ctx *ctx;
int fd;
struct sockaddr_in6 from;
- unsigned char buf[64 * 1024]; /* Maximum ICMPv6 size */
+ union {
+ struct icmp6_hdr hdr;
+ uint8_t buf[64 * 1024]; /* Maximum ICMPv6 size */
+ } iovbuf;
struct iovec iov = {
- .iov_base = buf,
- .iov_len = sizeof(buf),
+ .iov_base = iovbuf.buf, .iov_len = sizeof(iovbuf.buf),
};
union {
struct cmsghdr hdr;