Code: Select all
IPADDR BroadcastIP;
WORD BroadcastPort;
IPADDR ip6_multicast;
void InitMulticast()
{
if ( !ip6_multicast.IsMultiCast() )
ip6_multicast = IPADDR::AsciiToIp6( "224.0.100.100" );
if ( use_multicast )
{
BroadcastIP = ip6_multicast;
BroadcastPort = MULTICAST_PORT;
}
else
{
BroadcastIP.SetFromIP4( IPADDR4::GlobalBroadCast() );
BroadcastPort = BROADCAST_PORT;
}
}
void UdpSend( char *buf, int len, IPADDR &ip_addr, WORD port )
{
IPADDR ip = ( ip_addr.IsNull() ) ? BroadcastIP : ip_addr;
UDPPacket pkt;
pkt.SetSourcePort(port);
pkt.SetDestinationPort(port);
pkt.AddData((PBYTE)buf, (WORD) len);
pkt.Send(ip);
}