Commit 34a070f5 authored by Max Kellermann's avatar Max Kellermann Committed by Max Kellermann

net/IPv[46]Address: add Cast(const sockaddr_in&)

parent ac4975cd
/*
* 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
......
/*
* 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().
*/
......
/*
* 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
......
/*
* 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().
*/
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment