testProgs/sapWatch.cpp File Reference

#include "Groupsock.hh"
#include "GroupsockHelper.hh"
#include "BasicUsageEnvironment.hh"
#include <stdio.h>

Include dependency graph for sapWatch.cpp:

Go to the source code of this file.

Functions

int main (int argc, char **argv)

Variables

static unsigned const maxPacketSize = 65536
static unsigned char packet [maxPacketSize+1]


Function Documentation

int main ( int  argc,
char **  argv 
)

Definition at line 28 of file sapWatch.cpp.

References BasicUsageEnvironment::createNew(), BasicTaskScheduler::createNew(), env, Groupsock::handleRead(), maxPacketSize, our_inet_addr(), and our_inet_ntoa().

00028                                 {
00029   // Begin by setting up our usage environment:
00030   TaskScheduler* scheduler = BasicTaskScheduler::createNew();
00031   UsageEnvironment* env = BasicUsageEnvironment::createNew(*scheduler);
00032 
00033 
00034   // Create a 'groupsock' for the input multicast group,port:
00035   char* sessionAddressStr = "224.2.127.254";
00036   struct in_addr sessionAddress;
00037   sessionAddress.s_addr = our_inet_addr(sessionAddressStr);
00038 
00039   const Port port(9875);
00040   const unsigned char ttl = 0; // we're only reading from this mcast group
00041 
00042   Groupsock inputGroupsock(*env, sessionAddress, port, ttl);
00043 
00044   // Start reading and printing incoming packets
00045   // (Because this is the only thing we do, we can just do this
00046   // synchronously, in a loop, so we don't need to set up an asynchronous
00047   // event handler like we do in most of the other test programs.)
00048   unsigned packetSize;
00049   struct sockaddr_in fromAddress;
00050   while (inputGroupsock.handleRead(packet, maxPacketSize,
00051                                    packetSize, fromAddress)) {
00052     printf("\n[packet from %s (%d bytes)]\n",
00053            our_inet_ntoa(fromAddress.sin_addr), packetSize);
00054 
00055     // Ignore the first 8 bytes (SAP header).
00056     if (packetSize < 8) {
00057       *env << "Ignoring short packet from "
00058            << our_inet_ntoa(fromAddress.sin_addr) << "%s!\n";
00059       continue;
00060     }
00061 
00062     // convert "application/sdp\0" -> "application/sdp\0x20"
00063     // or all other nonprintable characters to blank, except new line
00064     unsigned idx = 8;
00065     while (idx < packetSize) {
00066       if (packet[idx] < 0x20 && packet[idx] != '\n') packet[idx] = 0x20;
00067       idx++;
00068     }
00069 
00070     packet[packetSize] = '\0'; // just in case
00071     printf((char*)(packet+8));
00072   }
00073 
00074   return 0; // only to prevent compiler warning
00075 }


Variable Documentation

unsigned const maxPacketSize = 65536 [static]

Definition at line 25 of file sapWatch.cpp.

unsigned char packet[maxPacketSize+1] [static]

Definition at line 26 of file sapWatch.cpp.


Generated on Tue Oct 7 15:39:23 2008 for live by  doxygen 1.5.2