10014 is WSAEFAULT
, which means "The buffer pointed to by the optval parameter is not in a valid part of the process address space or the optlen parameter is too small."
Read the documentation:
IP_ADD_SOURCE_MEMBERSHIP
expects a pointer to an ip_mreq_source
structure:
typedef struct ip_mreq_source {
struct in_addr imr_multiaddr;
struct in_addr imr_sourceaddr;
struct in_addr imr_interface;
} IP_MREQ_SOURCE, *PIP_MREQ_SOURCE;
You are passing it a pointer to an ip_mreq
structure instead:
typedef struct ip_mreq {
struct in_addr imr_multiaddr;
struct in_addr imr_interface;
} IP_MREQ, *PIP_MREQ;
ip_mreq
is smaller than ip_mreq_source
, thus sizeof(mreq)
is too small for IP_ADD_SOURCE_MEMBERSHIP
. You need to change your mreq
variable to ip_mreq_source
, and be sure to fill in its imr_sourceaddr
member.
ip_mreq
is used for IP_ADD_MEMBERSHIP
and IP_DROP_MEMBERSHIP
.
ip_mreq_source
is used for IP_ADD_SOURCE_MEMBERSHIP
, IP_DROP_SOURCE_MEMBERSHIP
, IP_BLOCK_SOURCE
, and IP_UNBLOCK_SOURCE
.