/*************************************** *************
* Function: Linux arm-Linux UPD multicast *
* Time: 2006-03-07 *
* Writing: Li Yinan *
**************************************** *************/
# Include <sys/types. h>
# Include <sys/socket. h>
# Include <netdb. h>
# Include <sys/STAT. h>
# Include <netinet/in. h>
# Include <stdio. h>
# Include <stdlib. h>
# Include <unistd. h>
Int Port = 6789; // Communication Port
Int main (void)
{
Int socket_descriptor;
Struct sockaddr_in address;
Socket_descriptor = socket (af_inet, sock_dgram, 0 );
If (socket_descriptor =-1)
{
Perror ("Opening socket ");
Exit (exit_failure );
}
Memset (& Address, 0, sizeof (struct sockaddr_in ));
Address. sin_family = af_inet;
Address. sin_addr.s_addr = inet_addr ("233.0.0.1 ");
Address. sin_port = htons (port );
While (1)
{
If (sendto (socket_descriptor, "test from broadcast", sizeof ("test from broadcast"), 0, (struct sockaddr *) & Address, sizeof (Address) <0)
{
Printf ("sendto/N ");
Exit (exit_failure );
}
Sleep (2 );
}
Exit (exit_success );
}