00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020 #include "Groupsock.hh"
00021 #include "GroupsockHelper.hh"
00022 #include "BasicUsageEnvironment.hh"
00023 #include <stdio.h>
00024
00025 static unsigned const maxPacketSize = 65536;
00026 static unsigned char packet[maxPacketSize+1];
00027
00028 int main(int argc, char** argv) {
00029
00030 TaskScheduler* scheduler = BasicTaskScheduler::createNew();
00031 UsageEnvironment* env = BasicUsageEnvironment::createNew(*scheduler);
00032
00033
00034
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;
00041
00042 Groupsock inputGroupsock(*env, sessionAddress, port, ttl);
00043
00044
00045
00046
00047
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
00055 if (packetSize < 8) {
00056 *env << "Ignoring short packet from " << AddressString(fromAddress).val() << "%s!\n";
00057 continue;
00058 }
00059
00060
00061
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';
00069 printf((char*)(packet+8));
00070 }
00071
00072 return 0;
00073 }