TCP/IP Programming Manual
UDP Program for Sending Multicast Packets
The following programming example shows how to use the socket routines in an application that
implements multicast for sending:
/*#pragma nolist*/
#include "inh"
#include "socketh"
#include "sckconfh"
#include <errnoh>
#include <routeh>
#include <paramh>
#include <ioctlh>
#include <stdioh>
#include <stringh>
#include <memoryh>
#include <stdlibh>
#include <cextdecs(DEBUG,FILE_GETINFO_,AWAITIOX,SETMODE,DELAY)>
#include <fcntlh>
#include <ctypeh>
#include <timeh>
#pragma list
#define BUFFER_LEN 10000
#define PORT_LEN 4
#define HOST_LEN 4
#define MAGIC_NUMBER 0x00D71101L
int main (int argc, char **argv)
{
struct protoent *udproto;
struct sockaddr_in sin, this, to;
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 = BUFFER_LEN , xcount, loopCount;
int len, tolen;
int portNum = 0, argNum = 1, bytesready, error;
int getsize, ssockerr = 0;
long dtime;
time_t timenow;
FILE *fi;
char hostchar[HOST_LEN+1];
char ttlset, ttlget, loopbkset, loopbkget;
char *chr = "-", *multiip, *ascptr, *thishost, *thisip;
char sendbuf[BUFFER_LEN];
unsigned long thisaddr, multiaddr, multiaddr0;
if (argc != 10) {
printf("usage: sndmulw [NO]DEBUG tcpip_process port this_host");
printf(" multicast_ip ttl loopCount data_file send_size\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++]);
/* Port number */
Programs Using AF_INET Sockets 225