InetAddr::InetAddr(const SysAddr &sa)
{
const sockaddr_in &sai = reinterpret_cast<const sockaddr_in &>(sa.addr);
- addr[0] = sai.sin_addr.s_addr>>24;
- addr[1] = sai.sin_addr.s_addr>>16;
- addr[2] = sai.sin_addr.s_addr>>8;
- addr[3] = sai.sin_addr.s_addr;
+ const char *ptr = reinterpret_cast<const char *>(&sai.sin_addr.s_addr);
+ std::copy(ptr, ptr+4, addr);
port = ntohs(sai.sin_port);
}
sa.size = sizeof(sockaddr_in);
sockaddr_in &sai = reinterpret_cast<sockaddr_in &>(sa.addr);
sai.sin_family = AF_INET;
- sai.sin_addr.s_addr = (addr[0]<<24) | (addr[1]<<16) | (addr[2]<<8) | (addr[3]);
+ char *ptr = reinterpret_cast<char *>(&sai.sin_addr.s_addr);
+ std::copy(addr, addr+4, ptr);
sai.sin_port = htons(port);
return sa;