3 Replies - 1840 Views - Last Post: 18 March 2013 - 05:21 AM Rate Topic: -----

#1 Clairvoyant1332  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 17-March 13

Can't get MCAST_JOIN_GROUP to work on Windows 7

Posted 17 March 2013 - 07:08 PM

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:

#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 here and here)

Is This A Good Question/Topic? 0
  • +

Replies To: Can't get MCAST_JOIN_GROUP to work on Windows 7

#2 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6064
  • View blog
  • Posts: 23,518
  • Joined: 23-August 08

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

Posted 18 March 2013 - 03:19 AM

First, thank you for letting us know of your questions on other forums; that is very thoughtful, and unfortunately too unusual.

I don't know anything about multicasting, but based on this code snippet from here, you might want to zero-out your gr struct and set some values in it before passing it along:

#ifndef NO_MCAST_JOIN_GROUP
    struct group_req gr;
    memset (&gr, 0, sizeof(gr));
    ((struct sockaddr*)&gr.gr_group)->sa_family = multicast_group.sin_family;
    ((struct sockaddr_in*)&gr.gr_group)->sin_addr.s_addr = multicast_group.sin_addr.s_addr;
    fail_unless (0 == setsockopt (recv_sock, SOL_IP, MCAST_JOIN_GROUP, (const char*)&gr, sizeof(gr)), "setsockopt(MCAST_JOIN_GROUP) failed");
#else


It's highly possible that the setsockopt for MCAST_JOIN_GROUP is expecting that sin_addr pointer to be valid.
Was This Post Helpful? 0
  • +
  • -

#3 Clairvoyant1332  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 2
  • Joined: 17-March 13

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

Posted 18 March 2013 - 04:09 AM

Actually, I'm already doing that, see lines 37 - 41, so I don't think that's it. This same code minus the Windows specific stuff works fine on Linux. Also, I tried with an IPv4 address and got the same error.
Was This Post Helpful? 0
  • +
  • -

#4 JackOfAllTrades  Icon User is offline

  • Saucy!
  • member icon

Reputation: 6064
  • View blog
  • Posts: 23,518
  • Joined: 23-August 08

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

Posted 18 March 2013 - 05:21 AM

Shit, sorry I missed that. Blame lack of sufficient coffee.

I don't do Windows, so I'm actually just totally useless here. Sorry.
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1