This is the mail archive of the cygwin mailing list for the Cygwin project.


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]
Other format: [Raw text]

Re: Problem Adding Membership Multicast Errno 22




On Feb 20 13:48, Corinna Vinschen wrote:
> On Feb 20 04:05, victhor_1983 wrote:
> > 	status= setsockopt(Descriptor, IPPROTO_IP, IP_ADD_MEMBERSHIP, &Multic,
> > sizeof(Multic));
> >         if (status<0){
> >            printf("Fallo al aÃadir el grupo de Multicast, codigo %i\n",
> > errno);
> > 	}
> 
> I'm sorry, I can't tell you why this doesn't work.  Cygwin's setsockopt
> function is basically just a shim between application and Winsock's
> setsockopt call.  It only performs special actions on a very limited
> set of options, only two actually: (SOL_SOCKET, SO_REUSEADDR) and
> (IPPROTO_IP, IP_TOS).  I'm also quite multicast illiterate.  Is it
> possible that you have to use the IP_MULTICAST_IF option on Windows
> before you can use IP_ADD_MEMBERSHIP?!?

>Here's one idea:  Is it possible that your application includes
>winsock.h?  If so, don't do that, use the POSIX headers for socket and
>ip stuff.  Winsock.h is the WInsock specific header file for
>applications using the old Winsock 1.x API.  In that API,
>IP_ADD_MEMBERSHIP is defined as the value 5.

>However, the newer Winsock 2.x API, which is used by Cygwin under the
>hood as well, defines IP_ADD_MEMBERSHIP as the value 12.  So, if there's
>any chance that you're including the winsock.h header, remove it and
>only use Cygwin's header files, not the Winsock specifc header files.

Thanks for the idea. Yes, I read something similar in a post related to
multicast in this same forum. However, I am not using windows headers, since
I migrated my code from Ubuntu. I also tried defining the value of
IP_ADD_MEMBERSHIP myself, and it checks with value 12, just as you say.
However, I still get the error.

I do the binding right after the setsockopt, but the result is the same if I
do it before. In both cases, the setsockopt() returns an errno=22, and the
binding returns an errno=125. It is a real mistery, because I know the IP
interface I associate to the multicast group exists and works, since I use
it without a problem in unicast sockets in other programs.

I have the feeling the problem is in the struct ip_mreg Multic or in
sizeof(Multic), but I cannot figure out why or how to solve it. I will keep
looking into it. Just in case, I post the whole code here:

#include <string.h>
#include <stdio.h>
#include <netinet/in.h>
#include <sys/socket.h> 
#include <errno.h>
#include <sys/time.h>
#include <pthread.h>
#include <sys/types.h>
#include <unistd.h>


#define SIGALRM 14





void salir()
{
	exit(NULL);
}


int main (void)
{
	int Descriptor, Descriptor2, status;
	struct sockaddr_in Direccion, Direccion2;
	unsigned short Puerto;
	struct ip_mreq Multic;

	Descriptor=socket(AF_INET,SOCK_DGRAM,0);
	Puerto=12100;
	Direccion.sin_family=AF_INET;
	Direccion.sin_port=htons(Puerto);//Puerto->s_port;
	Direccion.sin_addr.s_addr=inet_addr("224.0.22.1");//("138.4.32.34");
	memset(&(Direccion.sin_zero),'\0',8);   

	Direccion2.sin_family=AF_INET;
	Direccion2.sin_port=htons(Puerto);//Puerto->s_port;

Direccion2.sin_addr.s_addr=htonl(INADDR_ANY);//inet_addr("138.4.32.34");//("138.4.32.34");
	memset(&(Direccion2.sin_zero),'\0',8);   

	status=bind(Descriptor,(struct sockaddr *)&Direccion, sizeof(struct
sockaddr));	
      if (status<0){
           printf("Fallo al realizar binding, codigo %i\n", errno);
	}
	


	Multic.imr_multiaddr.s_addr=inet_addr("224.0.22.1");
	Multic.imr_interface.s_addr=htonl(INADDR_ANY);//inet_addr("138.4.32.34");
	status= setsockopt(Descriptor, IPPROTO_IP, IP_ADD_MEMBERSHIP, &Multic,
sizeof(Multic));
      if (status<0){
           printf("Fallo al aÃadir el grupo de Multicast, codigo %i\n",
errno);
	}




	signal (SIGINT, salir);
	signal (SIGALRM, SIG_IGN);

	
	
	
	

	return 0;		
}


Maybe the error is in some other part. Thanks again for your insight and
your help.
Victor
-- 
View this message in context: http://www.nabble.com/Problem-Adding-Membership-Multicast-Errno-22-tp22119431p22123508.html
Sent from the Cygwin list mailing list archive at Nabble.com.


--
Unsubscribe info:      http://cygwin.com/ml/#unsubscribe-simple
Problem reports:       http://cygwin.com/problems.html
Documentation:         http://cygwin.com/docs.html
FAQ:                   http://cygwin.com/faq/


Index Nav: [Date Index] [Subject Index] [Author Index] [Thread Index]
Message Nav: [Date Prev] [Date Next] [Thread Prev] [Thread Next]