Path: csiph.com!x330-a1.tempe.blueboxinc.net!usenet.pasdenom.info!news.albasani.net!newsfeed.freenet.ag!news2.euro.net!newsfeed.xs4all.nl!newsfeed5.news.xs4all.nl!xs4all!post.news.xs4all.nl!not-for-mail Return-Path: X-Original-To: python-list@python.org Delivered-To: python-list@mail.python.org X-Spam-Status: OK 0.008 X-Spam-Evidence: '*H*': 0.98; '*S*': 0.00; '(i.e.,': 0.03; 'socket': 0.05; 'option,': 0.07; 'python': 0.07; '"""': 0.09; '(there': 0.09; 'subject:Problem': 0.09; '"from': 0.16; 'addr': 0.16; 'capturing': 0.16; 'header)': 0.16; 'nodes': 0.16; 'received:10.2': 0.16; 'sock': 0.16; 'case.': 0.16; 'header:In- Reply-To:1': 0.22; 'specified': 0.22; '(and': 0.22; '(without': 0.23; 'instead': 0.26; 'looks': 0.28; 'load': 0.28; 'supports': 0.29; 'mode': 0.29; 'interface.': 0.29; '---': 0.31; 'mirror': 0.31; 'transport': 0.31; 'types.': 0.31; 'data,': 0.31; 'to:addr :python-list': 0.32; "i've": 0.33; 'relatively': 0.33; 'using': 0.34; 'actually': 0.34; 'print': 0.35; 'header:User-Agent:1': 0.35; 'like:': 0.35; 'rather': 0.36; '(with': 0.36; 'raw': 0.37; 'either': 0.37; 'but': 0.38; 'received:org': 0.38; 'skip:s 30': 0.39; 'to:addr:python.org': 0.39; 'add': 0.39; 'similar': 0.40; 'would': 0.40; 'contacting': 0.66; 'broadcast': 0.68; 'address),': 0.84; 'client-side': 0.84; 'listens': 0.84; 'schrieb': 0.84; 'similar.': 0.84; 'sniffer': 0.84 DKIM-Signature: v=1; a=rsa-sha256; c=simple/simple; d=modelnine.org; s=modelnine1012; t=1303311236; bh=g7s68ICw+71Fq48cBAVriso/D3jcB5OTEWff1ALeFg8=; h=Message-ID:Date:From:MIME-Version:To:Subject:References: In-Reply-To:Content-Type:Content-Transfer-Encoding; b=LO8roq9RMqB069glF69Ow6X2INzW2JGREx80lPX4JBxuLxAEYJp8mFsNCAwi1R+IN jXrmJoDAsAQQVRuPMdjcyy5g3UHtmqPgh5hDZGDncqWp0o9tgK34KLFBoLJRM8fVTe TEGA1Igu97MxzDPkb2IELPSf+qNiUQut/bEqMFu4= Date: Wed, 20 Apr 2011 16:53:53 +0200 From: Heiko Wundram User-Agent: Mozilla/5.0 (Windows; U; Windows NT 6.1; de; rv:1.9.2.15) Gecko/20110303 Thunderbird/3.1.9 MIME-Version: 1.0 To: python-list@python.org Subject: Re: Problem receiving UDP broadcast packets. References: <4dae172e$0$65870$e4fe514c@news.xs4all.nl> <4dae1d82$0$81483$e4fe514c@news.xs4all.nl> In-Reply-To: X-Enigmail-Version: 1.1.1 Content-Type: text/plain; charset=ISO-8859-1 Content-Transfer-Encoding: 7bit X-BeenThere: python-list@python.org X-Mailman-Version: 2.1.12 Precedence: list List-Id: General discussion list for the Python programming language List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , Newsgroups: comp.lang.python Message-ID: Lines: 41 NNTP-Posting-Host: 82.94.164.166 X-Trace: 1303311238 news.xs4all.nl 34849 [::ffff:82.94.164.166]:40494 X-Complaints-To: abuse@xs4all.nl Xref: x330-a1.tempe.blueboxinc.net comp.lang.python:3715 Am 20.04.2011 16:30, schrieb Grant Edwards: >> If you need to see the packets regardless, either use a promiscuous mode >> sniffer (i.e., tcpdump, but that's relatively easy to mirror in Python >> using SOCK_RAW, capturing packets at the ethernet level), or add a route >> on your system for the 192.168.x.x network on the same interface. > > I've thought about the SOCK_RAW option, but the CPU load of looking > all received Ethernet packets in user-space would be a big down-side. Not necessarily: instead of using UDP datagrams to send the data, use ethernet datagrams (without any IP/UDP header) with your own ethernet-type (there is a range of "local" types that you can use for your own local use-case), and then simply create a RAW socket that only listens on packets that have the specified ethernet types. We use something similar at work for a high-availability application. The server-side looks something like: """ PKT_TYPE = 0x1234 # My very own ethertype. sock = socket(AF_PACKET,SOCK_DGRAM,htons(PKT_TYPE)) sock.bind(("ethxyz",PKT_TYPE)) while True: data, (_, _, _, _, addr) = sock.recvfrom(1500) print "I got:", repr(data), "from etheraddr:", addr """ The client-side looks similar. Because you're using UDP broacast, you have unreliable transport anyway, and if the client-side supports sending ethernet datagrams (with a broadcast address), I'd rather advise to use that for your use case. This makes you independent of IP configuration (and as I can see, you're actually not interested in the "routing" that IP gives you, but rather interested in contacting all nodes on a local ethernet; why not use ethernet directly?). -- --- Heiko.