Can't get MCAST_JOIN_GROUP to work on Windows 7
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 2 of 2

Thread: Can't get MCAST_JOIN_GROUP to work on Windows 7

Hybrid View

  1. #1
    Join Date
    Jul 2009
    Posts
    6

    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?

    (Also posted to http://cboard.cprogramming.com/windo...ndows-7-a.html)

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,606

    Re: Can't get MCAST_JOIN_GROUP to work on Windows 7

    Well, you are not the first one to get such a problem:
    http://social.msdn.microsoft.com/For...7-4ea5e8da26ae
    Victor Nijegorodov

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center