From: Mikko Rasa Date: Wed, 10 Aug 2011 19:30:29 +0000 (+0300) Subject: Fix storage order of InetAddr::addr X-Git-Url: http://git.tdb.fi/?p=libs%2Fnet.git;a=commitdiff_plain;h=c9d1cbb9325637c1dea59969d15c5e1fac395df4;hp=ebf4d62dd7d119b79cbd3c64570949dbdf9cdde9 Fix storage order of InetAddr::addr --- diff --git a/source/net/inet.cpp b/source/net/inet.cpp index 29e24aa..c78ea61 100644 --- a/source/net/inet.cpp +++ b/source/net/inet.cpp @@ -21,10 +21,8 @@ InetAddr::InetAddr(): InetAddr::InetAddr(const SysAddr &sa) { const sockaddr_in &sai = reinterpret_cast(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(&sai.sin_addr.s_addr); + std::copy(ptr, ptr+4, addr); port = ntohs(sai.sin_port); } @@ -34,7 +32,8 @@ SockAddr::SysAddr InetAddr::to_sys() const sa.size = sizeof(sockaddr_in); sockaddr_in &sai = reinterpret_cast(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(&sai.sin_addr.s_addr); + std::copy(addr, addr+4, ptr); sai.sin_port = htons(port); return sa;