Skip to Content.
Sympa Menu

wg-multicast - Re: cli SAP announcement listener

Subject: All things related to multicast

List archive

Re: cli SAP announcement listener


Chronological Thread 
  • From: Nicholas J Humfrey <>
  • To: wg-multicast <>
  • Subject: Re: cli SAP announcement listener
  • Date: Tue, 25 Sep 2007 17:28:21 +0100

While it doesn't display the contents of the packets, Stig Vennas' mcfirst tool is also very good for testing for multicast connectivity. It is part of his ssmping set of tools:

http://www.venaas.no/multicast/ssmping/

It listens on a specified group/port and then displays information about the first packet it receives:

calx:~> mcfirst 224.2.127.254 9875
mcfirst joined (*,G) = (*,224.2.127.254)
Received 238 bytes from 132.246.2.28 after 75.839 ms (ttl/hops 238)
238 bytes (payload) and 1 packets received in 0 seconds

You can also tell it to receive a set number of packets, or for a set period of time.


nick.



On 25 Sep 2007, at 16:34, Ethan Sommer wrote:

As we've (Dan Oachs and I) been working on multicast routing, etc, I've often wanted to see if multicast was working to a particular host to which I only had ssh access (and sometimes only user level ssh access.)

After looking around, there didn't seem to be an easy way to test that.

Finally I got fed up and wrote a little program which joins the SAP announcement multicast group and outputs all the SAP announcements it sees. It can be run as a normal user (although you obviously won't be able open the firewall.)

Anyway, I thought some other people might find the program useful. I've included it below my signature.

Ethan

--
Ethan Sommer
Associate Director of Core Services
Gustavus Adolphus College
507-933-7042


/*
* listener.c -- joins a multicast group and echoes all data it receives from
* the group to its stdout...
*
* Antony Courtney, 25/11/94
* Modified by: Frédéric Bastien (25/03/04)
* to compile without warning and work correctly
*
* Modified by: Ethan Sommer to look for SAP Announcements (25/09/07)
* */

#include <sys/types.h>
#include <sys/socket.h>
#include <netinet/in.h>
#include <arpa/inet.h>
#include <time.h>
#include <string.h>
#include <stdio.h>


#define SAP_PORT 9875
#define SAP_GROUP "224.2.127.254"
#define MSGBUFSIZE 100000

main(int argc, char *argv[])
{
struct sockaddr_in addr;
int fd, nbytes,addrlen;
struct ip_mreq mreq;
char msgbuf[MSGBUFSIZE];
int x;

u_int yes=1; /*** MODIFICATION TO ORIGINAL */

/* create what looks like an ordinary UDP socket */
if ((fd=socket(AF_INET,SOCK_DGRAM,0)) < 0) {
perror("socket");
exit(1);
}


/**** MODIFICATION TO ORIGINAL */
/* allow multiple sockets to use the same PORT number */
if (setsockopt(fd,SOL_SOCKET,SO_REUSEADDR,&yes,sizeof(yes)) < 0) {
perror("Reusing ADDR failed");
exit(1);
}
/*** END OF MODIFICATION TO ORIGINAL */

/* set up destination address */
memset(&addr,0,sizeof(addr));
addr.sin_family=AF_INET;
addr.sin_addr.s_addr=htonl(INADDR_ANY); /* N.B.: differs from sender */
addr.sin_port=htons(SAP_PORT);
/* bind to receive address */
if (bind(fd,(struct sockaddr *) &addr,sizeof(addr)) < 0) {
perror("bind");
exit(1);
}
/* use setsockopt() to request that the kernel join a multicast group */
mreq.imr_multiaddr.s_addr=inet_addr(SAP_GROUP);
mreq.imr_interface.s_addr=htonl(INADDR_ANY);
if (setsockopt(fd,IPPROTO_IP,IP_ADD_MEMBERSHIP,&mreq,sizeof (mreq)) < 0) {
perror("setsockopt");
exit(1);
}
/* now just enter a read-print loop */
while (1) {
addrlen=sizeof(addr);
if ((nbytes=recvfrom(fd,msgbuf,MSGBUFSIZE,0,
(struct sockaddr *) &addr,&addrlen)) < 0) {
perror("recvfrom");
exit(1);
}
for (x=8;x<nbytes; x++) {
if (isprint(msgbuf[x])) putchar(msgbuf[x]);
else if (msgbuf[x]=='\r' || msgbuf[x]=='\n') putchar (msgbuf[x]);
else putchar('.');

}
printf("\n---\n");
}
}





Archive powered by MHonArc 2.6.16.

Top of Page