Can't get MCAST_JOIN_GROUP to work on Windows 7

This is a discussion on Can't get MCAST_JOIN_GROUP to work on Windows 7 within the Windows Programming forums, part of the Platform Specific Boards category; Calling setsockopt with MCAST_JOIN_GROUP results in error 10014: The system detected an invalid pointer address in attempting to use a ...

  1. #1
    Registered User
    Join Date
    Apr 2008
    Posts
    90

    Can't get MCAST_JOIN_GROUP to work on Windows 7

    Calling setsockopt with MCAST_JOIN_GROUP results in error 10014: The system detected an invalid pointer address in attempting to use a pointer argument in a call.

    Using similar code on Linux works fine, and using IPV6_JOIN_GROUP also works fine.

    Here's my test code:

    Code:
    #include <stdio.h>
    #include <stdlib.h>
    #include <string.h>
    #include <winsock2.h>
    #include <ws2tcpip.h>
    
    void sockerr(const char *message)
    {
        char errbuf[300];
        FormatMessage(FORMAT_MESSAGE_FROM_SYSTEM, NULL, WSAGetLastError(),
                      0, errbuf, sizeof(errbuf), NULL);
        fprintf(stderr, "%s: (%d) %s", message, WSAGetLastError(), errbuf);
    }
    
    int main(int argc, char *argv[])
    {
      int addr_len;
      struct sockaddr_in6 sin,sin_recv, *sreq;
      struct ipv6_mreq multi;
      struct group_req req;
      char mes[1500],name[100];
      int c,option,len;
      struct addrinfo *m_ai, *i_ai;
      struct WSAData data;
      SOCKET sock;
    
    
      if (WSAStartup(2,&data)) {
        sockerr("Error in WSAStartup");
        exit(1);
      }
    
      memset(&multi, 0, sizeof(multi));
      inet_pton(AF_INET6, "ff02::601:203", &multi.ipv6mr_multiaddr);
      multi.ipv6mr_interface = 11;
    
      memset(&req, 0, sizeof(req));
      sreq=(struct sockaddr_in6 *)&req.gr_group;
      sreq->sin6_family=AF_INET6;
      inet_pton(AF_INET6, "ff02::601:203", &sreq->sin6_addr);
      req.gr_interface = 11;
    
      memset(&sin,0,sizeof(sin));
      sin.sin6_family = AF_INET6;
      inet_pton(AF_INET6, "::", &sin.sin6_addr);
      sin.sin6_port = htons(1044);
      if ((sock=socket(AF_INET6,SOCK_DGRAM,0))==-1) {
        sockerr("Error creating socket");
        exit(1);
      }
      if (bind(sock,(struct sockaddr *)&sin,sizeof(sin))==-1) {
        sockerr("Error binding socket");
        closesocket(sock);
        exit(1);
      }
      //if (setsockopt(sock,IPPROTO_IPV6,IPV6_JOIN_GROUP,(char *)&multi,sizeof(multi))== -1) {
      if (setsockopt(sock,IPPROTO_IPV6,MCAST_JOIN_GROUP,(char *)&req,sizeof(req))== -1) {
        sockerr("Error joining multicast group");
        closesocket(sock);
        exit(1);
      }
    
      while (1) {
        memset(mes,0,sizeof(mes));
        memset(&sin_recv,0,sizeof(sin_recv));
        addr_len=sizeof(sin_recv);
        printf("%d: Waiting for packet...\n",getpid());
        if ((len=recvfrom(sock,mes,sizeof(mes),0,(struct sockaddr *)&sin_recv,&addr_len))==-1) {
          sockerr("error recving socket");
          closesocket(sock);
          exit(1);
        }
        if (inet_ntop(AF_INET6,&sin_recv.sin6_addr,name,sizeof(name))==NULL) {
          sockerr("inet_ntop failed");
          continue;
        }
        printf("%d: Got packet\n",getpid());
        printf("%d: Origin: %s port %d\n",getpid(),name,sin_recv.sin6_port);
        printf("%d: Len: %d, Message: %s\n",getpid(),len,mes);
      }
    }
    Any ideas?

  2. #2
    Registered User
    Join Date
    Apr 2008
    Posts
    90
    Also posted here and here

Popular pages Recent additions subscribe to a feed

Similar Threads

  1. Does \n work on Windows?
    By Programmer_P in forum C++ Programming
    Replies: 2
    Last Post: 06-11-2010, 01:32 PM
  2. How MS Windows keys work
    By ober in forum Tech Board
    Replies: 1
    Last Post: 01-07-2005, 01:02 PM
  3. Does graphics.h work with windows??
    By sundeeptuteja in forum C++ Programming
    Replies: 6
    Last Post: 09-13-2002, 10:08 AM
  4. compiled under windows, work for mac os?
    By Shadow12345 in forum C++ Programming
    Replies: 1
    Last Post: 05-09-2002, 10:55 AM
  5. Replies: 6
    Last Post: 01-07-2002, 02:46 AM

1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21