51 lines
1.1 KiB
C++
51 lines
1.1 KiB
C++
#include "connection.hpp"
|
|
|
|
|
|
#include <chrono>
|
|
#include <stdexcept>
|
|
#include <string>
|
|
#include <sys/types.h>
|
|
#include <sys/socket.h>
|
|
#include <netdb.h>
|
|
|
|
|
|
/*
|
|
int main(int argc, char* argv[]) {
|
|
// create an IPv6 socket based on datagram (UDP)
|
|
const int serverSocket = socket(
|
|
AF_INET6,
|
|
SOCK_DGRAM,
|
|
0
|
|
);
|
|
|
|
// get the broadcast address
|
|
addrinfo broadcastAddressConfig = {};
|
|
broadcastAddressConfig.ai_family = AF_INET6;
|
|
broadcastAddressConfig.ai_socktype = SOCK_DGRAM;
|
|
broadcastAddressConfig.ai_protocol = IPPROTO_UDP;
|
|
|
|
addrinfo *broadcastAddress;
|
|
if(!getaddrinfo(
|
|
"ff02::1", // multicast address
|
|
"5650", // our port
|
|
&broadcastAddressConfig,
|
|
&broadcastAddress
|
|
))
|
|
throw std::runtime_error("Could not get the address.");
|
|
|
|
const std::string message = "Salut !";
|
|
|
|
// broadcast the message
|
|
if (sendto(
|
|
serverSocket,
|
|
message.c_str(),
|
|
message.size(),
|
|
0,
|
|
broadcastAddress->ai_addr,
|
|
broadcastAddress->ai_addrlen
|
|
) == -1)
|
|
throw std::runtime_error("Could not broadcast the message.");
|
|
|
|
return 0;
|
|
}
|
|
*/
|