Internet Multicasting 
by Bob Quinn


Example 1: 

nRet = WSAStartup(0x0202, &stWSAData);
if (nRet) {
    printf ("WSAStartup failed: %d\r\n", nRet);
    exit (1);
}


Example 2:

hSocket = socket(AF_INET, SOCK_DGRAM, 0);
if (hSocket == INVALID_SOCKET) {
  printf ("socket() failed, Err: %d\n", WSAGetLastError());
  exit(1);
}


Example 3:

#define TIMECAST_PORT  8910

stLclAddr.sin_family      = AF_INET;
stLclAddr.sin_addr.s_addr = htonl(INADDR_ANY);
stLclAddr.sin_port        = htons(TIMECAST_PORT);
nRet = bind(hSocket, 
    (struct sockaddr*) &stLclAddr, 
    sizeof(stLclAddr));
if (nRet == SOCKET_ERROR) {
    printf ("bind() port: %d failed, Err: %d\n",
             nPort, WSAGetLastError());
}


Example 4:

#define TIMECAST_ADDR  "234.5.6.7"

stMreq.imr_multiaddr.s_addr = inet_addr(TIMECAST_ADDR);
stMreq.imr_interface.s_addr = INADDR_ANY;
nRet = setsockopt(hSocket, 
   IPPROTO_IP, 
   IP_ADD_MEMBERSHIP, 
   (char *)&stMreq, 
   sizeof(stMreq));
if (nRet == SOCKET_ERROR) {
  printf ("setsockopt() IP_ADD_MEMBERSHIP address %s failed, Err: %d\n",
    strMCAddr, WSAGetLastError());
}


Example 5:

nRet = setsockopt(hSocket, 
   IPPROTO_IP, 
   IP_MULTICAST_TTL, 
   (char *)&lTTL, 
   sizeof(lTTL));
if (nRet == SOCKET_ERROR) {
  printf ("setsockopt() IP_MULTICAST_TTL failed, Err: %d\n",
           WSAGetLastError());
}




