src/net/base/network_interfaces_getifaddrs_unittest.cc
bool FillIfaddrs(ifaddrs* interfaces,
                 const char* ifname,
                 uint flags,
                 const IPAddress& ip_address,
                 const IPAddress& ip_netmask,
                 sockaddr_storage sock_addrs[2]) {
  interfaces->ifa_next = nullptr;
  interfaces->ifa_name = const_cast<char*>(ifname);
  interfaces->ifa_flags = flags;

  socklen_t sock_len = sizeof(sockaddr_storage);

  // Convert to sockaddr for next check.
  if (!IPEndPoint(ip_address, 0)
           .ToSockAddr(reinterpret_cast<sockaddr*>(&sock_addrs[0]),
                       &sock_len)) {
    return false;
  }
  interfaces->ifa_addr = reinterpret_cast<sockaddr*>(&sock_addrs[0]);

  sock_len = sizeof(sockaddr_storage);
  if (!IPEndPoint(ip_netmask, 0)
           .ToSockAddr(reinterpret_cast<sockaddr*>(&sock_addrs[1]),
                       &sock_len)) {
    return false;
  }
  interfaces->ifa_netmask = reinterpret_cast<sockaddr*>(&sock_addrs[1]);

  return true;
}
// Helper function to create a single valid ifaddrs
Helper function to create a single valid ifaddrs
Helper function to create a single valid ifaddrs
bool FillIfaddrs(ifaddrs* interfaces,
                 const char* ifname,
                 uint flags,
                 const IPAddress& ip_address,
                 const IPAddress& ip_netmask,
                 sockaddr_storage sock_addrs[2]) {
  interfaces->ifa_next = nullptr;
  interfaces->ifa_name = const_cast<char*>(ifname);
  interfaces->ifa_flags = flags;
  socklen_t sock_len = sizeof(sockaddr_storage);
  if (!IPEndPoint(ip_address, 0)
           .ToSockAddr(reinterpret_cast<sockaddr*>(&sock_addrs[0]),
                       &sock_len)) {
    return false;
  }
  interfaces->ifa_addr = reinterpret_cast<sockaddr*>(&sock_addrs[0]);
  sock_len = sizeof(sockaddr_storage);
  if (!IPEndPoint(ip_netmask, 0)
           .ToSockAddr(reinterpret_cast<sockaddr*>(&sock_addrs[1]),
                       &sock_len)) {
    return false;
  }
  interfaces->ifa_netmask = reinterpret_cast<sockaddr*>(&sock_addrs[1]);
  return true;
}
bool FillIfaddrs ( ifaddrs * interfaces , const char * ifname , uint flags , const IPAddress & ip_address , const IPAddress & ip_netmask , sockaddr_storage sock_addrs [ 2 ] ) { interfaces -> ifa_next = nullptr ; interfaces -> ifa_name = const_cast < char * > ( ifname ) ; interfaces -> ifa_flags = flags ; socklen_t sock_len = sizeof ( sockaddr_storage ) ; if ( ! IPEndPoint ( ip_address , 0 ) . ToSockAddr ( reinterpret_cast < sockaddr * > ( & sock_addrs [ 0 ] ) , & sock_len ) ) { return false ; } interfaces -> ifa_addr = reinterpret_cast < sockaddr * > ( & sock_addrs [ 0 ] ) ; sock_len = sizeof ( sockaddr_storage ) ; if ( ! IPEndPoint ( ip_netmask , 0 ) . ToSockAddr ( reinterpret_cast < sockaddr * > ( & sock_addrs [ 1 ] ) , & sock_len ) ) { return false ; } interfaces -> ifa_netmask = reinterpret_cast < sockaddr * > ( & sock_addrs [ 1 ] ) ; return true ; }
Helper function to create a single valid ifaddrs
Helper function to create a single valid ifaddrs
// Convert to sockaddr for next check.