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, and our_inet_addr().

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 const* 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", AddressString(fromAddress).val(), packetSize);
00053 
00054     // Ignore the first 8 bytes (SAP header).
00055     if (packetSize < 8) {
00056       *env << "Ignoring short packet from " << AddressString(fromAddress).val() << "%s!\n";
00057       continue;
00058     }
00059 
00060     // convert "application/sdp\0" -> "application/sdp\0x20"
00061     // or all other nonprintable characters to blank, except new line
00062     unsigned idx = 8;
00063     while (idx < packetSize) {
00064       if (packet[idx] < 0x20 && packet[idx] != '\n') packet[idx] = 0x20;
00065       idx++;
00066     }
00067 
00068     packet[packetSize] = '\0'; // just in case
00069     printf("%s", (char*)(packet+8));
00070   }
00071 
00072   return 0; // only to prevent compiler warning
00073 }


Variable Documentation

unsigned const maxPacketSize = 65536 [static]

Definition at line 25 of file sapWatch.cpp.

Referenced by main(), startReplicaUDPSink(), and SubsessionIOState::useFrameForHinting().

unsigned char packet[maxPacketSize+1] [static]

Definition at line 26 of file sapWatch.cpp.


Generated on Mon Apr 29 13:30:52 2013 for live by  doxygen 1.5.2