int udpMCSocketCreate(char* cLocalName, char* cMultiCastAddr, int nPort)/*cLocalName为本机地址,cMultiCastAddr为组播地址,nPort为端口号*/
{
int nSocketID = -1;
struct sockaddr_in socketLocalAddr;
int nSockAddrSize = sizeof(struct sockaddr_in);
/* fill in the argument structure to join the multicast group */
/* initialize the multicast address to join */
ipMreq.imr_multiaddr.s_addr = inet_addr (cMultiCastAddr);
/* unicast interface addr from which to receive the multicast packets */
ipMreq.imr_interface.s_addr = inet_addr (cLocalName);
/* set the socket option to join the MULTICAST group */
if (setsockopt (nSocketID, IPPROTO_IP, IP_ADD_MEMBERSHIP, (char *)&ipMreq, sizeof (ipMreq)) == ERROR)
{
perror ("setsockopt IP_ADD_MEMBERSHIP error!\n");
return -1;
}