summaryrefslogtreecommitdiffhomepage
path: root/src/config.c
diff options
context:
space:
mode:
authorJason A. Donenfeld <Jason@zx2c4.com>2017-01-10 05:52:06 +0100
committerJason A. Donenfeld <Jason@zx2c4.com>2017-01-10 06:29:24 +0100
commit5685eb8ddb89fa0e5b117ef0f892b6783fdcefb4 (patch)
tree5df56b5397d082ef925e16b832780efe26d027b5 /src/config.c
parent7fcdda0253306475b5abc9318c1cff7022873d69 (diff)
uapi: use sockaddr union instead of sockaddr_storage
Signed-off-by: Jason A. Donenfeld <Jason@zx2c4.com>
Diffstat (limited to 'src/config.c')
-rw-r--r--src/config.c13
1 files changed, 5 insertions, 8 deletions
diff --git a/src/config.c b/src/config.c
index 6158cc8..5d2b825 100644
--- a/src/config.c
+++ b/src/config.c
@@ -74,12 +74,9 @@ static int set_peer(struct wireguard_device *wg, void __user *user_peer, size_t
goto out;
}
- if (in_peer.endpoint.ss_family == AF_INET || in_peer.endpoint.ss_family == AF_INET6) {
- struct endpoint endpoint = { { { 0 } } };
- if (in_peer.endpoint.ss_family == AF_INET)
- endpoint.addr4 = *(struct sockaddr_in *)&in_peer.endpoint;
- else if (in_peer.endpoint.ss_family == AF_INET6)
- endpoint.addr6 = *(struct sockaddr_in6 *)&in_peer.endpoint;
+ if (in_peer.endpoint.addr.sa_family == AF_INET || in_peer.endpoint.addr.sa_family == AF_INET6) {
+ struct endpoint endpoint = { 0 };
+ memcpy(&endpoint, &in_peer.endpoint, sizeof(in_peer.endpoint));
socket_set_peer_endpoint(peer, &endpoint);
}
@@ -242,9 +239,9 @@ static int populate_peer(struct wireguard_peer *peer, void *ctx)
memcpy(out_peer.public_key, peer->handshake.remote_static, NOISE_PUBLIC_KEY_LEN);
read_lock_bh(&peer->endpoint_lock);
if (peer->endpoint.addr.sa_family == AF_INET)
- *(struct sockaddr_in *)&out_peer.endpoint = peer->endpoint.addr4;
+ out_peer.endpoint.addr4 = peer->endpoint.addr4;
else if (peer->endpoint.addr.sa_family == AF_INET6)
- *(struct sockaddr_in6 *)&out_peer.endpoint = peer->endpoint.addr6;
+ out_peer.endpoint.addr6 = peer->endpoint.addr6;
read_unlock_bh(&peer->endpoint_lock);
out_peer.last_handshake_time = peer->walltime_last_handshake;
out_peer.tx_bytes = peer->tx_bytes;