Skip to Content.
Sympa Menu

wg-multicast - example of proper use of igmp v3 SSM setsockopt on Linux 2.6 kernel?

Subject: All things related to multicast

List archive

example of proper use of igmp v3 SSM setsockopt on Linux 2.6 kernel?


Chronological Thread 
  • From: Alan Crosswell <>
  • To: wg-multicast <>
  • Subject: example of proper use of igmp v3 SSM setsockopt on Linux 2.6 kernel?
  • Date: Tue, 16 Nov 2004 16:58:25 -0500

Does anyone have a working example of doing an (S,G) join on Linux 2.6? I'm trying this and getting the always-helpful "Invalid argument" error. Before I add printf's to the kernel I thought I'd ask.... Is there a better list to ask this on?

The following code snippet is derived from rtpqual.c:

int openSSM(source, name, port)
char *source;
char *name;
int port;
{
struct group_source_req greq;
struct sockaddr_in sin;
struct hostent *hp;
int fd, one=1;

bzero(&greq, sizeof(struct group_source_req));
bzero(&sin, sizeof(struct sockaddr_in));

greq.gsr_interface = 1; /* default intf XXXX */

if (isdigit(*name)) {
sin.sin_addr.s_addr = inet_addr(name);
}
else if (hp = gethostbyname(name)) {
bcopy(hp->h_addr, (char *)&sin.sin_addr.s_addr, hp->h_length);
}
else {
printf("I Don't understand session name %s\n",name);
exit(1);
}
sin.sin_family = AF_INET;
sin.sin_port = port;

if (!IN_MULTICAST(ntohl(sin.sin_addr.s_addr))) {
printf("%s is not a multicast session\n", name);
exit(1);
}
greq.gsr_group.sin_addr.s_addr = sin.sin_addr.s_addr;
// greq.gsr_interface.s_addr = INADDR_ANY;
if (isdigit(*source)) {
greq.gsr_source.sin_addr.s_addr = inet_addr(source);
}
else if (hp = gethostbyname(source)) {
bcopy(hp->h_addr, (char *)&greq.gsr_source.sin_addr.s_addr, hp->h_length);
}
else {
printf("I Don't understand source name %s\n",source);
exit(1);
}

NOERROR(fd = socket(AF_INET, SOCK_DGRAM, 0), "socket");
NOERROR(setsockopt(fd, SOL_SOCKET, SO_REUSEADDR, &one, sizeof(one)),
"SO_REUSEADDR");

if (bind(fd, &sin, sizeof(sin)) == -1) {
perror("Warning - Using INADDR_ANY because");
sin.sin_addr.s_addr = INADDR_ANY;
NOERROR(bind(fd, &sin, sizeof(sin)), "bind");
}

NOERROR(setsockopt(fd, IPPROTO_IP, MCAST_JOIN_SOURCE_GROUP, &greq,
sizeof(greq)),
"MCAST_JOIN_SOURCE_GROUP");

return(fd);
}



Archive powered by MHonArc 2.6.16.

Top of Page