summaryrefslogtreecommitdiffstats
path: root/src/peer.c
diff options
context:
space:
mode:
authorMatthias Schiffer <mschiffer@universe-factory.net>2012-12-13 17:51:00 +0100
committerMatthias Schiffer <mschiffer@universe-factory.net>2012-12-13 17:51:00 +0100
commit505eb464948d32f9ae5d7f8d48d89dde98972930 (patch)
treea3fb0226c8f00d7927227ea46d910a4c28f2647d /src/peer.c
parentda4d1d1586f36f1a4b69e19d39638676da3315d2 (diff)
downloadfastd-505eb464948d32f9ae5d7f8d48d89dde98972930.tar
fastd-505eb464948d32f9ae5d7f8d48d89dde98972930.zip
Add helper function to simplify v4-mapped addresses
Diffstat (limited to 'src/peer.c')
-rw-r--r--src/peer.c12
1 files changed, 12 insertions, 0 deletions
diff --git a/src/peer.c b/src/peer.c
index 9acedcb..a9855bf 100644
--- a/src/peer.c
+++ b/src/peer.c
@@ -369,6 +369,18 @@ bool fastd_peer_address_equal(const fastd_peer_address *addr1, const fastd_peer_
return true;
}
+void fastd_peer_address_simplify(fastd_peer_address *addr) {
+ if (addr->sa.sa_family == AF_INET6 && IN6_IS_ADDR_V4MAPPED(&addr->in6.sin6_addr)) {
+ struct sockaddr_in6 mapped = addr->in6;
+
+ memset(addr, 0, sizeof(fastd_peer_address));
+ addr->in.sin_family = AF_INET;
+ addr->in.sin_port = mapped.sin6_port;
+ memcpy(&addr->in.sin_addr.s_addr, &mapped.sin6_addr.s6_addr[12], 4);
+ }
+}
+
+
bool fastd_peer_claim_address(fastd_context *ctx, fastd_peer *new_peer, fastd_socket *sock, const fastd_peer_address *addr) {
if (addr->sa.sa_family == AF_UNSPEC) {
if (fastd_peer_is_established(new_peer))