我想用SOCKET的多播组功能,在MFC应用程序里面,用setsockopt(sok,IPPROTO_IP,IP_ADD_MEMBERSHIP,(char*)&ipmr,sizeof(ipmr))没问题,程序运行正常,想把这功能做到动态库里面,结果在动态库里面,同样的代码setsockopt(sok,IPPROTO_IP,IP_ADD_MEMBERSHIP,(char*)&ipmr,sizeof(ipmr)),却返回10042错误:Bad protocol option。有什么好的解决办法吗?

解决方案 »

  1.   

    参考winsock API setsockopt !
    显然你的套接字选项有误!
    The setsockopt function sets a socket option.
    int setsockopt(
      __in          SOCKET s,
      __in          int level,
      __in          int optname,
      __in          const char* optval,
      __in          int optlen
    );Parameters

    A descriptor that identifies a socket.level 
    The level at which the option is defined (for example, SOL_SOCKET).optname 
    The socket option for which the value is to be set (for example, SO_BROADCAST). The optname parameter must be a socket option defined within the specified level, or behavior is undefined.optval 
    A pointer to the buffer in which the value for the requested option is specified.optlen 
    The size, in bytes, of the optval buffer.
      

  2.   

    可是在应用程序中这样用为何没问题呢?SOCKET能正常使用,我用IPPROTO_IP和IP_ADD_MEMBERSHIP选项目的是实现多组播功能,其它选项可以实现吗?
      

  3.   


    你看下在你的应用程序里,有没有对IPPROTO_IP和IP_ADD_MEMBERSHIP的define,再看看和dll里的define是不是一样???