NPT_Result
NPT_BsdUdpMulticastSocket::JoinGroup(const NPT_IpAddress& group,
                                     const NPT_IpAddress& iface)
{
    struct ip_mreq mreq;

    // set the interface address
    mreq.imr_interface.s_addr = htonl(iface.AsLong());

    // set the group address
    mreq.imr_multiaddr.s_addr = htonl(group.AsLong());

    // set socket option
    NPT_LOG_FINE_2("joining multicast addr %s group %s",
                   iface.ToString().GetChars(), group.ToString().GetChars());
    int io_result = setsockopt(m_SocketFdReference->m_SocketFd,
                               IPPROTO_IP, IP_ADD_MEMBERSHIP,
                               (SocketOption)&mreq, sizeof(mreq));
    if (io_result == 0) {
        return NPT_SUCCESS;
    } else {
        NPT_Result result = MapErrorCode(GetSocketError());
        NPT_LOG_FINE_1("setsockopt error %d", result);
        return result;
    }
}

相关文章:

  • 2021-11-09
  • 2022-01-12
  • 2021-07-30
  • 2022-12-23
  • 2022-12-23
  • 2021-12-08
  • 2022-12-23
  • 2021-12-17
猜你喜欢
  • 2022-02-16
  • 2022-12-23
  • 2021-07-11
  • 2021-11-08
  • 2021-11-17
  • 2021-08-30
相关资源
相似解决方案