From owner-freebsd-net@FreeBSD.ORG Sat May 21 16:56:55 2005 Return-Path: Delivered-To: freebsd-net@freebsd.org Received: from mx1.FreeBSD.org (mx1.freebsd.org [216.136.204.125]) by hub.freebsd.org (Postfix) with ESMTP id 7493A16A4CE for ; Sat, 21 May 2005 16:56:55 +0000 (GMT) Received: from smtpout.mac.com (smtpout.mac.com [17.250.248.87]) by mx1.FreeBSD.org (Postfix) with ESMTP id 29E8343D48 for ; Sat, 21 May 2005 16:56:54 +0000 (GMT) (envelope-from cswiger@mac.com) Received: from mac.com (smtpin01-en2 [10.13.10.146]) id j4LGusJs010940; Sat, 21 May 2005 09:56:54 -0700 (PDT) Received: from [192.168.1.101] (pool-68-161-53-96.ny325.east.verizon.net [68.161.53.96]) (authenticated bits=0)j4LGuqfU002760; Sat, 21 May 2005 09:56:53 -0700 (PDT) In-Reply-To: <20050521162738.29477.qmail@web53905.mail.yahoo.com> References: <20050521162738.29477.qmail@web53905.mail.yahoo.com> Mime-Version: 1.0 (Apple Message framework v622) Content-Type: text/plain; charset=US-ASCII; format=flowed Message-Id: <1e68f176b1351a2d8e697ee599ca2c2f@mac.com> Content-Transfer-Encoding: 7bit From: Charles Swiger Date: Sat, 21 May 2005 12:56:49 -0400 To: Daniel Valencia X-Mailer: Apple Mail (2.622) cc: freebsd-net@freebsd.org Subject: Re: sending MAC packets --- again, and again X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.1 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Sat, 21 May 2005 16:56:55 -0000 On May 21, 2005, at 12:27 PM, Daniel Valencia wrote: > [ ...pcap reading code stalling... ] > > Is this normal pcap behaviour, or is it some > FreeBSD-specific behaviour, or is it just me? It's unfortunately normal. You're running into this (from "man pcap"): NOTE: when reading a live capture, pcap_dispatch() will not necessarily return when the read times out; on some platforms, the read timeout isn't supported, and, on other platforms, the timer doesn't start until at least one packet arrives. This means that the read timeout should NOT be used in, for example, an interactive application, to allow the packet capture loop to ``poll'' for user input periodically, as there's no guarantee that pcap_dispatch() will return after the timeout expires. You can help prompt the pcap timeout to work better by *sending* a packet just before you try to sniff packets. However, in the end you'll probably find yourself either going multithreaded or using alarm() and a signal handler to periodicly wake the program up to pay attention to other things if the pcap sniffing goes into long hibernation. Or maybe both. :-) But then, the standard calls for getting hostnames (getaddrinfo, gethostbyname) block, too, so you maybe you'll throw DNS lookup code into another thread anyway, or else end up crafting your own DNS resolver code since you're already sniffing the packets.... -- -Chuck