title: Multicast not received by networked computers
body: <p>I'm trying to send a multicast to all network computers.  I have my server set up on my computer and another computer on the network.  When I send out the multicast message, the server running on my computer picks it up fine.  The networked computer doesn't get anything though.  I've tried setting the TTL to its max value and that hasn't done anything.  I've also tried monitoring my packets using WireShark, but didn't see anything (I'm not very skilled with this).  I'm confused why my computer receives it, but not the other networked computer.  Here is the code I'm using to send the multicast:</p>
  
  <pre><code>#include &lt;sys/types.h&gt;   /* for type definitions */
  #include &lt;winsock2.h&gt;    /* for win socket API calls */
  #include &lt;ws2tcpip.h&gt;    /* for win socket structs */
  #include &lt;stdio.h&gt;       /* for printf() */
  #include &lt;stdlib.h&gt;      /* for atoi() */
  #include &lt;string.h&gt;      /* for strlen() */
  
  #define MAX_LEN  1024    /* maximum string size to send */
  #define MIN_PORT 1024    /* minimum port allowed */
  #define MAX_PORT 65535   /* maximum port allowed */
  
  int main(int argc, char *argv[]) {
  
    int sock;                   /* socket descriptor */
    char send_str[MAX_LEN];     /* string to send */
    struct sockaddr_in mc_addr; /* socket address structure */
    int send_len;               /* length of string to send */
    char* mc_addr_str;          /* multicast IP address */
    unsigned short mc_port;     /* multicast port */
    unsigned char mc_ttl=255;     /* time to live (hop count) */
    WSADATA wsaData;            /* Windows socket DLL structure */
  
    /* validate number of arguments */
    if (argc != 3) {
      fprintf(stderr, 
              "Usage: %s &lt;Multicast IP&gt; &lt;Multicast Port&gt;\n", 
              argv[0]);
      exit(1);
    }
  
    mc_addr_str = argv[1];       /* arg 1: multicast IP address */
    mc_port     = atoi(argv[2]); /* arg 2: multicast port number */
  
    /* validate the port range */
    if ((mc_port &lt; MIN_PORT) || (mc_port &gt; MAX_PORT)) {
      fprintf(stderr, "Invalid port number argument %d.\n",
              mc_port);
      fprintf(stderr, "Valid range is between %d and %d.\n",
              MIN_PORT, MAX_PORT);
      exit(1);
    }
  
    /* Load Winsock 2.0 DLL */
    if (WSAStartup(MAKEWORD(2, 0), &amp;wsaData) != 0) {
      fprintf(stderr, "WSAStartup() failed");
      exit(1);
    }
  
    /* create a socket for sending to the multicast address */
    if ((sock = socket(PF_INET, SOCK_DGRAM, IPPROTO_UDP)) &lt; 0) {
      perror("socket() failed");
      exit(1);
    }
  
    /* set the TTL (time to live/hop count) for the send */
    if ((setsockopt(sock, IPPROTO_IP, IP_MULTICAST_TTL, 
         (void*) &amp;mc_ttl, sizeof(mc_ttl))) &lt; 0) {
      perror("setsockopt() failed");
      exit(1);
    } 
  
    /* construct a multicast address structure */
    memset(&amp;mc_addr, 0, sizeof(mc_addr));
    mc_addr.sin_family      = AF_INET;
    mc_addr.sin_addr.s_addr = inet_addr(mc_addr_str);
    mc_addr.sin_port        = htons(mc_port);
  
    printf("Begin typing (return to send, ctrl-C to quit):\n");
  
    /* clear send buffer */
    memset(send_str, 0, sizeof(send_str));
  
    while (fgets(send_str, MAX_LEN, stdin)) {
      send_len = strlen(send_str);
  
      /* send string to multicast address */
      if ((sendto(sock, send_str, send_len, 0, 
           (struct sockaddr *) &amp;mc_addr, 
           sizeof(mc_addr))) != send_len) {
        perror("sendto() sent incorrect number of bytes");
        exit(1);
      }
  
      /* clear send buffer */
      memset(send_str, 0, sizeof(send_str));
    }
  
    closesocket(sock);  
    WSACleanup();  /* Cleanup Winsock */
  
    exit(0);
  }
  </code></pre>