#include #include #include #include "uicimult.h" #define HOSTARG 1 #define PORTARG 2 #define NUMARGS 3 #define TTLARG 3 #define MAXLINE 1024 int main(int argc, char *argv[]) { u_short port; char line[MAXLINE]; int nbytes; char ttl = 1 ; int s ; if (argc < NUMARGS) { fprintf(stderr, "Usage: %s Host(dotted IP address) Port [TTL]\n", argv[0]); exit(1); } if (argc >= 4) { ttl = (int)atoi(argv[TTLARG]) ; } port = (u_short)atoi(argv[PORTARG]); if (u_joinMULTRecv(argv[HOSTARG], port,ttl) == -1) { perror("Receiver failed to join multicast group --- "); fprintf(stderr, "%s: host = %s, port = %d\n", argv[0], argv[HOSTARG], port); exit(1); } while (1) { if ((nbytes = u_recvMULT(line, MAXLINE-1)) == -1) { perror("Receiver failed to get line --- "); exit(1); } line[nbytes] = '\0'; fprintf(stderr, "received %d bytes: %s\n", nbytes, line); fputs(line,stdout); } }