diff options
-rw-r--r-- | src/net/IPv4Address.cxx | 2 | ||||
-rw-r--r-- | src/net/IPv4Address.hxx | 11 | ||||
-rw-r--r-- | src/net/IPv6Address.cxx | 2 | ||||
-rw-r--r-- | src/net/IPv6Address.hxx | 11 |
4 files changed, 22 insertions, 4 deletions
diff --git a/src/net/IPv4Address.cxx b/src/net/IPv4Address.cxx index c7f2ec521..eeb4f553e 100644 --- a/src/net/IPv4Address.cxx +++ b/src/net/IPv4Address.cxx @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 Max Kellermann <max.kellermann@gmail.com> + * Copyright 2012-2020 Max Kellermann <max.kellermann@gmail.com> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/src/net/IPv4Address.hxx b/src/net/IPv4Address.hxx index 6137c120e..b55204397 100644 --- a/src/net/IPv4Address.hxx +++ b/src/net/IPv4Address.hxx @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 Max Kellermann <max.kellermann@gmail.com> + * Copyright 2012-2020 Max Kellermann <max.kellermann@gmail.com> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -158,6 +158,15 @@ public: } /** + * Cast a #sockaddr_in6 reference to an IPv6Address reference. + */ + static constexpr const IPv4Address &Cast(const struct sockaddr_in &src) noexcept { + /* this reinterpret_cast works because this class is + just a wrapper for struct sockaddr_in6 */ + return *(const IPv4Address *)(const void *)&src; + } + + /** * Return a downcasted reference to the address. This call is * only legal after verifying SocketAddress::GetFamily(). */ diff --git a/src/net/IPv6Address.cxx b/src/net/IPv6Address.cxx index de8b44c5b..1071c1a77 100644 --- a/src/net/IPv6Address.cxx +++ b/src/net/IPv6Address.cxx @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 Max Kellermann <max.kellermann@gmail.com> + * Copyright 2012-2020 Max Kellermann <max.kellermann@gmail.com> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions diff --git a/src/net/IPv6Address.hxx b/src/net/IPv6Address.hxx index 52606024f..3ef6f7319 100644 --- a/src/net/IPv6Address.hxx +++ b/src/net/IPv6Address.hxx @@ -1,5 +1,5 @@ /* - * Copyright 2012-2019 Max Kellermann <max.kellermann@gmail.com> + * Copyright 2012-2020 Max Kellermann <max.kellermann@gmail.com> * * Redistribution and use in source and binary forms, with or without * modification, are permitted provided that the following conditions @@ -127,6 +127,15 @@ public: } /** + * Cast a #sockaddr_in6 reference to an IPv6Address reference. + */ + static constexpr const IPv6Address &Cast(const struct sockaddr_in6 &src) noexcept { + /* this reinterpret_cast works because this class is + just a wrapper for struct sockaddr_in6 */ + return *(const IPv6Address *)(const void *)&src; + } + + /** * Return a downcasted reference to the address. This call is * only legal after verifying SocketAddress::GetFamily(). */ |