TCP/IP Programming Manual
 portNum = atoi (argv[argNum++]); /* convert string to PORT # */
 printf (" PortNum: %i\n", portNum);
 /* Name of this host */
 thishost = argv[argNum++];
 if ((temp = gethostbyname (thishost)) != (struct hostent*)NULL) {
 memmove ((char *)&in_addr_this.s_addr, (char *)temp->h_addr,
 (size_t)temp->h_length);
 }
 else {
 printf ("gethostbyname failed for %s, error = %d\n", thishost, h_errno);
 exit (0);
 }
 thisaddr = in_addr_this.s_addr;
 thisip = inet_ntoa (in_addr_this);
 printf ("Multicast Interface IP: %s\n", thisip);
 /* IP address of the multicast group to join */
 multiip = argv[argNum++];
 multiaddr0 = inet_addr (multiip); /* convert to binary format */
 /* Multicast TTL */
 ttlset = atoi(argv[argNum++]);
 printf ("Multicast TTL: %i\n",ttlset);
 /* Test loop count */
 loopCount = atoi (argv[argNum++]);
 /* Protocol is UDP */
 udproto = getprotobyname ("UDP");
 /* Open data input file */
 if ((fi = fopen (argv[argNum++],"r")) == NULL) {
 printf ("OPEN failed for the data input file\n");
 exit (0);
 }
 req_count = atoi (argv[argNum++]);
 if (req_count > BUFFER_LEN)
 req_count = BUFFER_LEN;
 printf ("Requested count : %i\n",req_count);
 xcount = fread (sendbuf,req_count,1,fi);
 if (xcount != 1) {
 printf ("Error reading Input file. Check if it's in subvol!\n");
 exit (0);
 }
 sendbuf[req_count-1] = '\0';
 /* Create socket */
 if ((fd1 = socket (AF_INET, SOCK_DGRAM, udproto->p_proto)) < 0){
 perror ("Socket Failure");
 exit (0);
 }
 /* Test Multicast I/F set and get */
 printf ("SETting Multicast I/F to %s or 0x%lx \n", thisip, thisaddr);
226 Sample Programs










