net/IPv[46]Address: add Cast(const sockaddr_in&)
This commit is contained in:
parent
ac4975cd7a
commit
34a070f5a6
@ -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
|
||||
|
@ -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
|
||||
@ -157,6 +157,15 @@ public:
|
||||
~uint16_t(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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().
|
||||
|
@ -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
|
||||
|
@ -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
|
||||
@ -126,6 +126,15 @@ public:
|
||||
~uint32_t(0));
|
||||
}
|
||||
|
||||
/**
|
||||
* 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().
|
||||
|
Loading…
Reference in New Issue
Block a user