Hi all,
I am trying to capture read events on tun0 device on freeBSD 5.5 using
libevent library v1.2. But the event_dispatch() function returns with
an error "Operation not supported by device".
Is /dev/tun0 device supported by libevent 1.2?
Thanks,
Sachin
I have attached my code below:
#include <sys/errno.h>
#include <sys/types.h>
#include <sys/time.h>
#include <sys/socket.h>
#include <sys/ioctl.h>
#include <sys/param.h>
#include <sys/linker.h>
#include <sys/module.h>
#include <sys/uio.h>
#include <unistd.h>
#include <net/if.h>
#include <net/if_tun.h>
#include <fcntl.h>
#include <stdlib.h>
#include <stdio.h>
#include <string.h>
#include <event.h>
void call_back(int i, short s, void *arg)
{
printf("In call back\n");
}
int myInit(void)
{
int unit, fd;
struct event id;
char name[FILENAME_MAX];
fd = open("/dev/tun0", O_RDWR);
if (fd < 0) {
}
else {
int rc, mode;
mode = IFF_BROADCAST | IFF_MULTICAST;
rc = ioctl(fd, TUNSIFMODE, &mode);
if (rc < 0) {
fprintf(stderr,
"coudn't set tunnel mode to broadcast: %s\n",
strerror(errno));
return rc;
}
event_set(&id, fd, EV_READ|EV_PERSIST, call_back,(void *) &fd);
//rc = event_add(&id, NULL);
if (rc < 0) {
fprintf(stderr, "error from tun event_add: %s\n",
strerror(errno));
return errno;
}
return fd;
}
}
int main(int argc, char **argv)
{
struct event timeout;
struct timeval tv;
int rv;
event_init();
myInit();
evtimer_set(&timeout, call_back, &timeout);
timerclear(&tv);
tv.tv_sec = 1;
event_add(&timeout, &tv);
rv = event_dispatch();
if(rv < 0) {
fprintf(stderr, "Unexpected exit: %s\n", strerror(errno));
}
}
_______________________________________________
Libevent-users mailing list
[email protected]
http://monkey.org/mailman/listinfo/libevent-users