TCP/IP Programming Manual
/* Close the socket */
FILE_CLOSE_ (fd1);
}
UDP Program for Receiving Multicast Packets
The following programming example shows how to use the socket routines in an application that
implements multicast for receiving:
#pragma nolist
#include "inh"
#include "sckconfh"
#include "socketh"
#include <errnoh>
#include <routeh>
#include <paramh>
#include <ioctlh>
#include <stdioh>
#include <stringh>
#include <memoryh>
#include <stdlibh>
#include <cextdecs(DEBUG,FILE_GETINFO_,AWAITIOX,SETMODE)>
#include <fcntlh>
#include <ctypeh>
#pragma list
#define BUFFER_LEN 10000
#define PORT_LEN 4
#define HOST_LEN 4
#define DELAYTIME 200
#define MAGIC_NUMBER 0x00D71101L
int main (int argc, char **argv)
{
struct protoent *udproto;
struct sockaddr_in sin, this, to, from;
struct hostent *temp;
struct in_addr in_addr_gmulti, in_addr_multi0, in_addr_mult;
struct in_addr in_addr_this;
struct ip_mreq multi_req;
int x, i, j, k, fd1, req_count, xcount;
int len, fromlen;
int portNum, argNum = 1, error;
int getsize, ssockerr = 0;
FILE *fi;
char hostchar[HOST_LEN+1];
char ttlset, ttlget, loopbkset, loopbkget;
char *multiip, *ascptr, *thishost, *thisip;
char recvbuf[BUFFER_LEN];
unsigned long thisaddr, multiaddr, multiaddr0;
if (argc != 7) {
printf("usage: rcvmcl [NO]DEBUG tcpip_process port this_host");
printf(" multicast_ip ttl\n");
exit (0);
}
if (!strcmp (argv[argNum++],"DEBUG"))
DEBUG();
/* TCPIP^PROCESS^NAME parameter */
printf ("\nClient Process: %s\n", argv[argNum]);
socket_set_inet_name (argv[argNum++]);
228 Sample Programs