#include #include #include #include #include "uicimult.h" #define HOSTARG 1 #define PORTARG 2 #define NUMARGS 3 #define TTLARG 3 #define MAXLINE 256 int main(int argc, char *argv[]) { u_short port; char ttl = 1 ; int s ; char line[MAXLINE] = "hello world"; int n = 0 ; char host[MAXLINE] ; size_t len ; s = gethostname(host, sizeof(host)); 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]) ; } if (argc >= 5) { sprintf(line,"%s: %s",host,argv[4]) ; } port = (u_short)atoi(argv[PORTARG]); if (u_joinMULTSend(argv[HOSTARG], port,ttl ) == -1) { perror("Sender failed to join multicast group --- "); fprintf(stderr, "%s: host = %s, port = %d\n", argv[0], argv[HOSTARG], port); exit(1); } while (1) { if (argc < 5) { n++ ; sprintf(line,"%s: %d",host,n) ; printf("%s: %d\n",host,n) ; } if (u_sendMULT(line, strlen(line)) == -1) { perror("Sender failed to send line --- "); exit(1); } sleep(1) ; } }