Skip site navigation (1)Skip section navigation (2)
Date:      Mon, 8 Dec 1997 18:12:49 +0200 (EET)
From:      Ruslan Ermilov <ru@ucb.crimea.ua>
To:        fwang2@unity.ncsu.edu (Feiyi Wang)
Cc:        hackers@freebsd.org
Subject:   Re: help: divert sockets question
Message-ID:  <199712081612.SAA11172@relay.ucb.crimea.ua>
In-Reply-To: <Pine.SOL.3.96.971208095136.16834B-100000@loki.csc.ncsu.edu> from Feiyi Wang at "Dec 8, 97 09:54:53 am"

next in thread | previous in thread | raw e-mail | index | archive | help
Hi!

I did it the same way. It doesn't work for me ;-(

In general, I have a packet received trhu udp from remote machine,
and I need to write it as incoming on a local machine.

Usually, you read the packet from divert socket first using recvfrom(),
then optionally modify it, and then write it back using sendto().

My case is differ, because I just need to write a packet as incoming,
not reading it from divert socket first.

Does it make sense?

Once Feiyi Wang wrote:
> Hi, 
> 
> It will work. Here is the way I did it
> 
> -- snip --
> 
> 
> /* this is readIncoming() */
> 
>  inbytes = recvfrom( fd,
>                       inPacketBuf,
>                       sizeof inPacketBuf,
>                       0,
>                       (struct sockaddr*) &inPacketAddr,
>                       &addrsize);
> 
> 
> /* this is writeIncoming() */
> 
> writeIncoming(int fd)
> {
>   int wrote;
>   wrote = sendto( fd,
>                   inPacketBuf,
>                   inPacketLen,
>                   0,
>                   (struct sockaddr *) &inPacketAddr,
>                   sizeof inPacketAddr);
> 
>   if ( wrote != inPacketLen ) 
>     fprintf(stderr, "failed to write packet back\n");
>   else
>     return wrote;
> }
> 
> 
> 
> On Mon, 8 Dec 1997, Ruslan Ermilov wrote:
> 
> > Hi, Hackers!
> > 
> > I'm in process of writing a small `iptunnel' program
> > which lets me tunnel IP traffic thru UDP.
> > 
> > My program uses two sockets: UDP and divert.
> > 
> > It reads IP-packet from divert socket and
> > sends it to the remote machine thru UDP.
> > Remote machine then reads it from UDP and
> > reinjects the IP-packet by writing it to the
> > divert socket.
> > 
> > And vice versa.
> > 
> > It works greatly!
> > 
> > Problem:
> > 
> > I want to reinject received thru UDP IP-packet
> > as incoming. `man ipdivert' says that I should
> > use sendto() syscall with a destination address
> > equal to IP address of some my local interface.
> > 
> > I did it and it doesn't works.
> > 
> > It seems to me like a kernel is just dropping such a packet.
> > But no error returned from sendto(), no packets travel
> > thru the firewall.
> > 
> > Can anyone point me a way to write packet as incoming?
> > Should I change some IP-packet fields?
> > 
> > TIA,
> > -- 
> > Ruslan A. Ermilov	System Administrator
> > ru@ucb.crimea.ua	United Commercial Bank
> > +380-652-247647 	Simferopol, Crimea
> > 2426679 		ICQ Network, UIN
> > 
> 
> 


-- 
Ruslan A. Ermilov	System Administrator
ru@ucb.crimea.ua	United Commercial Bank
+380-652-247647 	Simferopol, Crimea
2426679 		ICQ Network, UIN



Want to link to this message? Use this URL: <https://mail-archive.FreeBSD.org/cgi/mid.cgi?199712081612.SAA11172>