/* * opt.c * * Parsing command line for Multicast Application * * function: options(argc, argv) * * Written by Philippe Dax (ENST) - (C) 1995 */ #include #include #include #include #include #include #include extern char *optarg; extern int optind, opterr, optopt; /* * global variables */ char * group; char * session; char * media; char * format; unsigned char ttl; unsigned short port; int multicast, unicast; int debug =0; void usage(char * progname) { fprintf(stderr, "Usage: %s [-d] [-h] \ [-S \"session-name\"] \ [-M \"media-name\"] \ [-f format-name] \ [-t ttl] \ group/port/ttl\n", progname); exit(1); } void options(int argc, char ** argv) { int c; char *s; while ((c = getopt(argc, argv, "hdt:S:M:f:")) != EOF) { switch(c) { case 'S': /* Session name */ session = optarg; break; case 'M': /* Media name */ media = optarg; break; case 'f': /* Format name */ format = optarg; break; case 't': /* ttl scope value */ ttl = atoi(optarg); break; case 'd': /* debugging */ debug = 1; break; case 'h': default : usage(argv[0]); } } if (optind == argc) usage(argv[0]); group = argv[optind]; s = strchr(group, '/'); if (*s) { *s = '\0'; port = atoi(s+1); if (!port || port > 65535) { fprintf(stderr, "Bad port number\n"); exit(1); } } if (IN_MULTICAST(group)) { multicast = 1; unicast = 0; } else { multicast = 0; unicast = 1; } s = strchr(s+1, '/'); if (*s) { ttl = atoi(s+1); ttl = (ttl <= 255) ? ttl : 255; ttl = (ttl != 0) ? ttl : 1; } if (debug) fprintf(stderr, "group/port/ttl: %s/%d/%d\n", group, port, ttl); }