From owner-freebsd-questions Thu Nov 13 17:09:00 1997 Return-Path: Received: (from root@localhost) by hub.freebsd.org (8.8.7/8.8.7) id RAA10321 for questions-outgoing; Thu, 13 Nov 1997 17:09:00 -0800 (PST) (envelope-from owner-freebsd-questions) Received: from awfulhak.demon.co.uk (awfulhak.demon.co.uk [158.152.17.1]) by hub.freebsd.org (8.8.7/8.8.7) with ESMTP id RAA10309 for ; Thu, 13 Nov 1997 17:08:55 -0800 (PST) (envelope-from brian@awfulhak.org) Received: from gate.lan.awfulhak.org (localhost [127.0.0.1]) by awfulhak.demon.co.uk (8.8.7/8.8.7) with ESMTP id BAA25757; Fri, 14 Nov 1997 01:02:40 GMT (envelope-from brian@gate.lan.awfulhak.org) Message-Id: <199711140102.BAA25757@awfulhak.demon.co.uk> X-Mailer: exmh version 2.0zeta 7/24/97 To: Archie Cobbs cc: fwang2@eos.ncsu.edu (Feiyi Wang), questions@FreeBSD.ORG Subject: Re: Another divert socket question In-reply-to: Your message of "Thu, 13 Nov 1997 10:34:36 PST." <199711131834.KAA19531@bubba.whistle.com> Mime-Version: 1.0 Content-Type: text/plain; charset=us-ascii Date: Fri, 14 Nov 1997 01:02:40 +0000 From: Brian Somers Sender: owner-freebsd-questions@FreeBSD.ORG X-Loop: FreeBSD.org Precedence: bulk I left this in my "unread" list hoping you'd answer Archie ! Thanks ;-) I definitely couldn't have said it better ! > Feiyi Wang writes: > > In divert man page, it is said that: "Normally, packets read as incoming > > should be written as incoming; similiarly for outgoing packets. When > > reading and then writing back packets, passing the same socket address > > supplied by recvfrom(2) unmodified to sendto(2) simplifies things". > > > > I am a bit confused here: when I do recvfrom(2), the socket address I am > > getting is actually a source (struct socketaddr*), if I pass it > > unmodified to sendto(2) as detination, it seems contradict to my usual > > sense of "read as incoming, write as incoming". Am I missing something > > here? > > The root of your question is the hackerous nature of divert sockets :-) > You have to forget your usual understanding of the meaning of sendto() > and recvfrom(). Just think of them as read() and write() with room for > an extra argument. The extra argument simply specifies whether the > packet is an "incoming" packet (ie, received on an interface but not > yet routed) or an "outgoing" packet (ie, ready to be forwarded out a > specific interface). > > > I do tried this way, it seemed not work. To make my question clear, here > > is what I am trying to do - A routing daemon (gated) is listening proto > > 89 via "normal raw socket". I first use "ipfw" divert all ip packets > > with proto 89 to another port, which got a divert socket binded, after > > packet checking ok, I want to re-inject it into the incoming stream > > without affecting gated daemon. > > > > Can it be done? Now reading is ok, but when I write back, but gated > > daemon seems never receive the packets. > > You should be able to do this by passing the exact same sockaddr > structure you got from recvfrom() to sendto(). If gated is not > getting the packets, make sure your packet is legal, ie., has > a correct IP header checksum, etc (otherwise it will get dropped). > > -Archie > > ___________________________________________________________________________ > Archie Cobbs * Whistle Communications, Inc. * http://www.whistle.com -- Brian , , Don't _EVER_ lose your sense of humour....