2
votes

Any reccomendations of a libary which I can call from my Linux (C) app to send simple log messages to anyone who happens to be listening on the network, using Multicast UDP?

2
What have you found when searching e.g. Google? Have you tried any of those?Some programmer dude
Options seem to be log4cpp or syslog, which dont seem to quite fit / are too heavy. Alternatively, I could write my own, but only QT 4.8 has multicast, and I dont fancy having to hack out loads of socket code myself.James Bennet
Would syslog not fit ? You'd decouple the log delivery from your app - all you do is call 1 function - and configure syslog to deliver the logs whereever - e.g. a multicast destination.nos

2 Answers

2
votes

You don't need a library to send a multicast packet. Sending a UDP message to a multicast socket is only marginally more complicated than sending one to a unicast address.

In particular you'll need to use setsockopt to set the IP_MULTICAST_TTL of your packets.

The receiving side is slightly harder - you have to join a particular multicast group using setsockopt with IP_ADD_MEMBERSHIP to be able to receive the messages sent to it.

These options are all documented in man 7 ip .

0
votes

As you asked "Any reccomendations of a libary" I consider you dont want just the standard c library because I never see anyone ask if someone recommends c library to c development. So obviously you dont need any thing more than c library but my answer fits your question perfectly or, maybe, the question is not so good.

You can use the excellent ZeroMQ and EPGM protocol (encapsulated inside UDP)

zmq_pgm - ØMQ reliable multicast transport using PGM

in the server side

void *context = zmq_init(1);
assert(context);
void *broadcast = zmq_socket(context, ZMQ_PUB);
assert(broadcast);
rc = zmq_bind(broadcast, "epgm://192.168.0.123:5555");
assert(rc==0);
rc = s_send(broadcast, "Hello world!");
assert(rc==0);

in client side:

void *context = zmq_init(1);
assert(context);
void *watch = zmq_socket(context, ZMQ_SUB);
assert(watch);    
rc = zmq_connect(watch, "epgm://192.168.0.123:5555");
assert(rc==0);
char *message = s_receive(watch);
assert(message);