tcpdump mailing list archives

Problems with select (the other way around...)


From: Ricardo Balbinot <rbalbinot () gmail com>
Date: Fri, 15 May 2009 20:43:39 -0300

Hi,

I have seen lots of messages around the list, but I do have a strange
problem.. in the code below, the select NEVER returns that the pcap
descriptor can be read...

It returns a timeout normally, and if I just use the pcap_dispatch function,
it works out just fine.. the problem is that I want ti use pcap_dispatch
ONLY if the descriptor shows that it can be read without blocking... any
ideas?

handle_fd = pcap_get_selectable_fd(args->dev_handle);
    if (handle_fd == -1) {
        LOG4CXX_WARN(thread_log,"problem with select");
        while (true) {
            if (args->should_end) {
                break;
            }

pcap_dispatch(args->dev_handle,-1,processPacket,(u_char*)(&thread_log));
        }
    } else {
        LOG4CXX_WARN(thread_log,"");
        while (true) {
            if (args->should_end) {
                break;
            }
            tv.tv_sec = 1;
            tv.tv_usec = 0;
            FD_ZERO(&rfds);
            FD_SET(handle_fd,&rfds);
            retval = select(1, &rfds, NULL, NULL, &tv);
            switch (retval) {
                case -1:
                    LOG4CXX_ERROR(thread_log,"Error.");
                    break;
                case 0:
                    //LOG4CXX_TRACE(thread_log,"Timeout.");
                    continue;
                default:
                    LOG4CXX_TRACE(thread_log,"Capture.");

pcap_dispatch(args->dev_handle,-1,processPacket,(u_char*)(&thread_log));
            }
        }
    }

So.. the code never reaches the capture, cause select never returns the
descriptor as readable...

I dont know if this is just a noob question, but any help would be greatly
appreciated :)

Best regards,

Ricardo Balbinot
-
This is the tcpdump-workers list.
Visit https://cod.sandelman.ca/ to unsubscribe.


Current thread: