#include <fcntl.h>
#include <sys/ioctl.h>
#include <sys/poll.h>
+#include <syslog.h>
#include "utils.h"
static void usage(FILE *out)
{
- fprintf(out, "usage: mctap [-h] [-D TAPNAME] MCASTGROUP PORT\n");
+ fprintf(out, "usage: mctap [-hd] [-D TAPNAME] MCASTGROUP PORT\n");
}
static __attribute__ ((unused)) char *formataddress(struct sockaddr *arg, socklen_t arglen)
ret = poll(pfds, 2, -1);
if(ret < 0) {
if(errno != EINTR) {
- fprintf(stderr, "mctap: poll: %s\n", strerror(errno));
+ syslog(LOG_ERR, "mctap: poll: %s", strerror(errno));
exit(1);
}
continue;
ret = read(sock, buf, sizeof(buf));
if(ret < 0) {
if((errno != EINTR) && (errno != EAGAIN)) {
- fprintf(stderr, "mctap: mcast packet: %s\n", strerror(errno));
+ syslog(LOG_ERR, "mctap: mcast packet: %s", strerror(errno));
exit(1);
}
} else {
ret = read(tap, buf, sizeof(buf));
if(ret < 0) {
if((errno != EINTR) && (errno != EAGAIN)) {
- fprintf(stderr, "mctap: mcast packet: %s\n", strerror(errno));
+ syslog(LOG_ERR, "mctap: mcast packet: %s", strerror(errno));
exit(1);
}
} else {
struct in_addr group;
int port;
char *tapname;
+ int daemonize;
struct sockaddr_in dst;
tapname = "mctap";
- while((c = getopt(argc, argv, "hD:")) >= 0) {
+ daemonize = 0;
+ while((c = getopt(argc, argv, "hD:d")) >= 0) {
switch(c) {
case 'D':
tapname = optarg;
break;
+ case 'd':
+ daemonize = 1;
+ break;
case 'h':
usage(stdout);
return(0);
fprintf(stderr, "mctap: could not create TAP device: %s\n", strerror(errno));
exit(1);
}
+ openlog(sprintf2("mctap-%s", tapname), LOG_PID, LOG_DAEMON);
+
+ if(daemonize)
+ daemon(0, 0);
memset(&dst, 0, sizeof(dst));
dst.sin_family = AF_INET;