From owner-freebsd-net@FreeBSD.ORG Wed Jul 4 15:37:26 2012 Return-Path: Delivered-To: net@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [69.147.83.52]) by hub.freebsd.org (Postfix) with ESMTP id E0A571065673; Wed, 4 Jul 2012 15:37:26 +0000 (UTC) (envelope-from ndenev@gmail.com) Received: from mail-bk0-f54.google.com (mail-bk0-f54.google.com [209.85.214.54]) by mx1.freebsd.org (Postfix) with ESMTP id 407BC8FC15; Wed, 4 Jul 2012 15:37:26 +0000 (UTC) Received: by bkcje9 with SMTP id je9so2389988bkc.13 for ; Wed, 04 Jul 2012 08:37:25 -0700 (PDT) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=20120113; h=subject:mime-version:content-type:from:in-reply-to:date:cc :content-transfer-encoding:message-id:references:to:x-mailer; bh=yf7DTsb8CcTu8H6gdrPLO7LRSbThzBsazbAiMP5KEd0=; b=CU6d1JgWK4BfZalBteeZPMSaK3nA6y4y36ElIAUK0HLAtuI0fcUR+gaL2NkJ1DUs47 XenmVJfXmxoHdt1wvQMP2fVYUn8mJBrqHQLKSV60b44XnknLjv1k1NOYztkLFv7lNHNW YOmTebdapHyiE2OofOoGPbGUXEpHzzRZB9kJFgoKA+CZGpCcLEYf59RzrvehUFzokKFI bG14O9Pa3UPqctD7YBzb1QxncrFS3j1rdz7qF7zZ25N6p4tnA+awSSVeHZ/inN1JP1d8 +elDj+xsf3JTZbXo0E/J4A2Ns6OLTr0UYbEQ4jWZkvU7zJfhkP8G8vsrKzZ1CYgPRntL 0f3A== Received: by 10.204.148.74 with SMTP id o10mr12241881bkv.111.1341416245053; Wed, 04 Jul 2012 08:37:25 -0700 (PDT) Received: from ndenevsa.sf.moneybookers.net (g1.moneybookers.com. [217.18.249.148]) by mx.google.com with ESMTPS id n5sm19221863bkv.14.2012.07.04.08.37.23 (version=TLSv1/SSLv3 cipher=OTHER); Wed, 04 Jul 2012 08:37:23 -0700 (PDT) Mime-Version: 1.0 (Apple Message framework v1278) Content-Type: text/plain; charset=us-ascii From: Nikolay Denev In-Reply-To: <4FF45C81.3030907@gmail.com> Date: Wed, 4 Jul 2012 18:37:21 +0300 Content-Transfer-Encoding: quoted-printable Message-Id: <07EA7CC9-19CF-4EFE-A9E2-6A94DCA3F1AC@gmail.com> References: <4FF45C81.3030907@gmail.com> To: Budnev Vladimir X-Mailer: Apple Mail (2.1278) Cc: freebsd-questions@freebsd.org, net@freebsd.org Subject: Re: how to correctly distinguish broadcast udp packets vs unicast (socket, pcap or bpf)? X-BeenThere: freebsd-net@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: Networking and TCP/IP with FreeBSD List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Wed, 04 Jul 2012 15:37:27 -0000 On Jul 4, 2012, at 6:08 PM, Budnev Vladimir wrote: > Good day to all. >=20 > What is the correct way to distinguish udp packets that obtained by = application and were send on 255.255.255.255 ip addr from those that = were send to unicast ip? >=20 > Seems it is impossible with read/recvfrom so we'v made that with = libpcap. It coul be done with directly bpf api without pcap wrapper but = i'm not sure about how big pcap overhead is. >=20 > The questions is if we have about 1Gb incoming traffic and using pcap = filter for specific port how big is impact of using pcap in such = situation? Is it possbile to estimate? Target traffic is about 1Mbit and = while testing CPU is about 1-2% but i'm not sure about all the = conditions. >=20 > recfrom recieves all the data without loss in such condition, is it = possible that pcap because of its filtering nature(i dont know in = details how bpf is realized deep in kernel:( ) will add big overhead = while listening? >=20 >=20 > _______________________________________________ > freebsd-net@freebsd.org mailing list > http://lists.freebsd.org/mailman/listinfo/freebsd-net > To unsubscribe, send any mail to "freebsd-net-unsubscribe@freebsd.org" If I'm understanding your question correctly you can lookup the ip(4) = manual page : If the IP_RECVDSTADDR option is enabled on a SOCK_DGRAM socket, the = recvmsg call will return the destination IP address for a UDP datagram. = The msg_control field in the msghdr structure points to a buffer that contains a cmsghdr structure followed by the IP address. The = cmsghdr fields have the following values: You can use this in you application and get the destination address of = the packets be it unicast IP or the broadcast address.=