From owner-freebsd-questions@FreeBSD.ORG Mon Jan 25 12:45:41 2010 Return-Path: Delivered-To: freebsd-questions@freebsd.org Received: from mx1.freebsd.org (mx1.freebsd.org [IPv6:2001:4f8:fff6::34]) by hub.freebsd.org (Postfix) with ESMTP id 40C9710656B3 for ; Mon, 25 Jan 2010 12:45:41 +0000 (UTC) (envelope-from sakncli@gmail.com) Received: from fg-out-1718.google.com (fg-out-1718.google.com [72.14.220.154]) by mx1.freebsd.org (Postfix) with ESMTP id CB5248FC40 for ; Mon, 25 Jan 2010 12:45:40 +0000 (UTC) Received: by fg-out-1718.google.com with SMTP id e12so156858fga.13 for ; Mon, 25 Jan 2010 04:45:39 -0800 (PST) DKIM-Signature: v=1; a=rsa-sha256; c=relaxed/relaxed; d=gmail.com; s=gamma; h=domainkey-signature:mime-version:received:date:message-id:subject :from:to:content-type; bh=mWG8T02EWwPYgPFaOB4PQZ9x4EOkLjxkePvGGU1kZB0=; b=IAOtw0JiW+P/L4uEWS0/1i7vXGiHwhIfIBKZlSLv8tWje+ybr+AWgIi5HaLjuhfB6a 8pDuo23Sdjr/N6Elblvm60xMGiXpnb2VOUmXOQPRvIvyUQfngMgSHKiRQg5A0IA4VHIG K1ivhpgMKVilCwlqxL8XoyNWXLTgc9R0+0NDg= DomainKey-Signature: a=rsa-sha1; c=nofws; d=gmail.com; s=gamma; h=mime-version:date:message-id:subject:from:to:content-type; b=hckihI6/WRQPeY6AhZo+aRdLXmAX5iccj+6eDrfT6Bxe5i6Af+xGw2n2ifQbxDUo4t QB3gPAv3vXYQqB2c9MfBAk+vbVcqc9Ocgu6VBsLCTKZ28QmscCSrq/ECZPvI4oWqwgEo KSf0CKpVHU8RebyX1d3j0j/hvGk2eNsTq8+oE= MIME-Version: 1.0 Received: by 10.86.6.23 with SMTP id 23mr10530639fgf.16.1264421796859; Mon, 25 Jan 2010 04:16:36 -0800 (PST) Date: Mon, 25 Jan 2010 14:16:36 +0200 Message-ID: <97371e801001250416s1109e3c5hae98cad0db876fe3@mail.gmail.com> From: yavuz To: freebsd-questions@freebsd.org Content-Type: text/plain; charset=ISO-8859-1 X-Content-Filtered-By: Mailman/MimeDel 2.1.5 Subject: writing divert sockets X-BeenThere: freebsd-questions@freebsd.org X-Mailman-Version: 2.1.5 Precedence: list List-Id: User questions List-Unsubscribe: , List-Archive: List-Post: List-Help: List-Subscribe: , X-List-Received-Date: Mon, 25 Jan 2010 12:45:41 -0000 Hi all, I have a problem while writing divert sockets. I found a simple application and modified it to compile in freebsd. Simple divert socket application only prints incomming packet and reinject packet to IP stack. My simple application and test codes are available at ( http://forums.freebsd.org/showthread.php?t=10589) I think I have a problem in reinject part, i.e writing packet back to ip stack. I have a server application listening on port 2000 and a client sends packet to port 2000. And I have a ipfw rule as: > ipfw add 1000 divert 2000 tcp from any to any 2000 In divert socket application a divert socket is created and bind to port 2000. Socket receives packet with no problem: > n=recvfrom( fd, packet, BUFSIZE, 0, (struct sockaddr_in *) sin, &sinlen); After receiving packet what I want to do is simply reinjecting packet. >n=sendto(fd, packet, n ,0, (struct sockaddr *) &sin, sinlen); Reinjecting packet is not working in my case. I miss some point:) please help me. In addition to the problem, I couldn't understand a point in man page of divert. "The port part of the socket address passed to the sendto(2) contains a tag that should be meaningful to the diversion module. In the case of ipfw(8) the tag is interpreted as the rule number after which rule processing should restart." If I change the port value of sending address to ipfw rule number, how can server receive the packet? (Assume the rule number is 1000 and server listens port 2000. ) Thanks in advance yavuzg