5 #include <netinet/in.h>
7 #include <msp/strings/format.h>
9 #include "sockaddr_private.h"
16 Inet6Addr::Inet6Addr():
19 fill(addr, addr+16, 0);
22 Inet6Addr::Inet6Addr(const SysAddr &sa)
24 const sockaddr_in6 &sai6 = reinterpret_cast<const sockaddr_in6 &>(sa.addr);
25 std::copy(sai6.sin6_addr.s6_addr, sai6.sin6_addr.s6_addr+16, addr);
26 port = htons(sai6.sin6_port);
29 SockAddr::SysAddr Inet6Addr::to_sys() const
32 sa.size = sizeof(sockaddr_in6);
33 sockaddr_in6 &sai6 = reinterpret_cast<sockaddr_in6 &>(sa.addr);
34 sai6.sin6_family = AF_INET6;
35 std::copy(addr, addr+16, sai6.sin6_addr.s6_addr);
36 sai6.sin6_port = htons(port);
37 sai6.sin6_flowinfo = 0;
38 sai6.sin6_scope_id = 0;
43 string Inet6Addr::str() const
46 for(unsigned i=0; i<16; i+=2)
48 unsigned short part = (addr[i]<<8) | addr[i+1];
51 result += format("%x", part);
55 result += format(":%d", port);