Updated
Will this line of code work:
boost::shared_array<struct sockaddr> addr(
reinterpret_cast<struct sockaddr *>(
(ipv6 ? new unsigned char [sizeof(struct sockaddr_in6)]
: new unsigned char [sizeof(struct sockaddr_in)])
)
);
Note the two different data types between allocation and the type given in the <template>
.
The original question was with boost::shared_ptr
Will this line of code work:
boost::shared_ptr<struct sockaddr> addr(
reinterpret_cast<struct sockaddr *>(
(ipv6 ? new unsigned char [sizeof(struct sockaddr_in6)]
: new unsigned char [sizeof(struct sockaddr_in)])
)
);
Note the two different data types between allocation and the type given in the <template>
.
Solution
boost::shared_array<unsigned char> address(new unsigned char [sizeof(sockaddr_in)]);
NOTE: The same type of unsigned char is being used with a size exactly of the one that's needed.
and then when I am going to use it:
bind(, (sockaddr*)address.get(), );