Skip site navigation (1)Skip section navigation (2)
Date:      Wed, 11 May 2005 23:00:24 -0400
From:      Chuck Swiger <cswiger@mac.com>
To:        Daniel Valencia <fetrovsky@yahoo.com>
Cc:        freebsd-net@freebsd.org
Subject:   Re: sending MAC packets --- again
Message-ID:  <4282C6C8.7010209@mac.com>
In-Reply-To: <20050512021758.99519.qmail@web53905.mail.yahoo.com>
References:  <20050512021758.99519.qmail@web53905.mail.yahoo.com>

next in thread | previous in thread | raw e-mail | index | archive | help
Daniel Valencia wrote:
[ ...pcap delays... ]
> Has anyone in this list had any experience with
> libpcap over fbsd that can point me into the right
> direction?

Sure.  Are you trying to use non-blocking mode of PCAP by any chance?  I found 
that to be fairly busted on FreeBSD and would drop lots of packets, just as 
you've described.  PCAP timeouts in blocking mode also seem to not work very 
well, in the sense that the timeout starts after the first packet is received.

I've got a code snippet handy:

/* This routine obtains a list of all of the network interfaces on the machine
  * for each interface found, check to see whether the interface is UP and
  * whether the user wants this interface to be used.  If so, open the packet
  * capture interface and add this (struct interface) to IFL.
  */
void
init_interfaces() {
     struct ifaddrs *if_ptr;
     char *name;
     u_int flags;
     struct interface *new;
[ ... ]

     LIST_INIT(&IFL);

     if (getifaddrs(&ifap) == -1) {
         fatal(strerror(errno));
         /*NOTREACHED*/
     }

     /* iterate over the list of interfaces on the machine */
     for (if_ptr = ifap; if_ptr; if_ptr = if_ptr->ifa_next) {
         name = if_ptr->ifa_name;
         flags = if_ptr->ifa_flags;
         /* check that the interface is UP before we try to use it */
         if (!(flags & IFF_UP)) continue;

         switch (if_ptr->ifa_addr->sa_family) {
           case AF_INET:
             /* check whether the user specified this interface */
             if (check_interface(name)) {
                 new = calloc(1, sizeof(struct interface));
                 if (!new) fatal("can't calloc() interface structure");
                 new->name = name;
                 new->addr = (struct sockaddr_in *)if_ptr->ifa_addr;
[ ... ]
                 new->pcap_fd = pcap_open_live(name, CAPSIZE, 1, 50, errbuf);
                 if (new->pcap_fd == 0) {
                     logwarn("init_interfaces(): error calling 
pcap_open_live():\n");
                     fatal(errbuf);
                     /*NOTREACHED*/
                 }

#if 0  /* XXX: non-blocking mode seems to drop lots of packets, don't use */
                 if (pcap_setnonblock(new->pcap_fd, 1, errbuf) == -1) {
                     loginfo("init_interfaces(): pcap_setnonblock failed!\n");
                     fatal(errbuf);
                 }
#endif
[ ... ]

-- 
-Chuck



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?4282C6C8.7010209>