// Netlink gives us the prefix length as a bit count. We need to turn
 // that into a BSD-compatible netmask represented by a sockaddr*.
 void SetNetmask(int family, size_t prefix_length) {
     // ...and work out the netmask from the prefix length.
     netmask.ss_family = family;
     uint8_t* dst = SockaddrBytes(family, &netmask);
     memset(dst, 0xff, prefix_length / 8);
     if ((prefix_length % 8) != 0) {
       dst[prefix_length/8] = (0xff << (8 - (prefix_length % 8)));
     }
     ifa.ifa_netmask = reinterpret_cast<sockaddr*>(&netmask);
 }
Beispiel #2
0
  sockaddr* CopyAddress(int family, const void* data, size_t byteCount, sockaddr_storage* ss) {
      // Netlink gives us the address family in the header, and the
      // sockaddr_in or sockaddr_in6 bytes as the payload. We need to
      // stitch the two bits together into the sockaddr that's part of
      // our portable interface.
      ss->ss_family = family;
      memcpy(SockaddrBytes(family, ss), data, byteCount);

      // For IPv6 we might also have to set the scope id.
      if (family == AF_INET6 && (IN6_IS_ADDR_LINKLOCAL(data) || IN6_IS_ADDR_MC_LINKLOCAL(data))) {
          reinterpret_cast<sockaddr_in6*>(ss)->sin6_scope_id = interface_index;
      }

      return reinterpret_cast<sockaddr*>(ss);
  }
 void SetBroadcastAddress(int family, const void* data, size_t byteCount) {
     ifa_ifu.ss_family = family;
     memcpy(SockaddrBytes(family, &ifa_ifu), data, byteCount);
     ifa.ifa_dstaddr = reinterpret_cast<sockaddr*>(&ifa_ifu);
 }
 // Netlink gives us the address family in the header, and the
 // sockaddr_in or sockaddr_in6 bytes as the payload. We need to
 // stitch the two bits together into the sockaddr that's part of
 // our portable interface.
 void SetAddress(int family, const void* data, size_t byteCount) {
     addr.ss_family = family;
     memcpy(SockaddrBytes(family, &addr), data, byteCount);
     ifa.ifa_addr = reinterpret_cast<sockaddr*>(&addr);
 }