Code Comments

Programming Forum and web based access to our favorite programming groups.
For Programmers: Free Programming Magazines | New: Database administration forum
Registration is free! Edit your profileCalendarFind other membersFrequently Asked QuestionsSearch -> 
Post New Thread











Thread
Author

interface to interface
Can I write a program to read packet from one interface and output
packet to another interface?
I wonder if os identify the two IP belong to interface in local
machine, transmitting the packet in IP layer,and no packet goes out
the interface.
Is it possible to happen?

Report this thread to moderator Post Follow-up to this message
Old Post
Joseph
10-19-04 09:01 AM


Re: interface to interface
In article <7d4caedb.0410181756.627370d@posting.google.com>,
te0543@giga.net.tw (Joseph) wrote:

> Can I write a program to read packet from one interface and output
> packet to another interface?

If you can write a program to read from one interface, and you can write
a program to write to the other interface, what could possibly prevent
one program from doing both?  You just write something like:

while (read(sock1, ...) > 0)
write(sock2, ...);

> I wonder if os identify the two IP belong to interface in local
> machine, transmitting the packet in IP layer,and no packet goes out
> the interface.
> Is it possible to happen?

It may depend on the implementation, but on most Unix systems if you
send to a destination that's on the local system, it won't send it onto
the network.  It will simply loop it around in the kernel.

What does this have to do with your first question?

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***

Report this thread to moderator Post Follow-up to this message
Old Post
Barry Margolin
10-19-04 09:01 AM


Re: interface to interface
Barry Margolin <barmar@alum.mit.edu> wrote in message news:<barmar-3FDE84.02440119102004@co
mcast.dca.giganews.com>...
> In article <7d4caedb.0410181756.627370d@posting.google.com>,
>  te0543@giga.net.tw (Joseph) wrote:
> 
>
> If you can write a program to read from one interface, and you can write
> a program to write to the other interface, what could possibly prevent
> one program from doing both?  You just write something like:
>
> while (read(sock1, ...) > 0)
>   write(sock2, ...);
> 
>
> It may depend on the implementation, but on most Unix systems if you
> send to a destination that's on the local system, it won't send it onto
> the network.  It will simply loop it around in the kernel.
>
> What does this have to do with your first question?

If 192.168.100.1 belong to interface1,192.168.100.2 belongs to
interface2.
Interface1 and interface2 are both on net1.
If I want to read packet from interface1,write to interface2,os may
loop around in the kernel,right?

Report this thread to moderator Post Follow-up to this message
Old Post
Joseph
10-19-04 02:05 PM


Re: interface to interface
In article <7d4caedb.0410190251.253fde27@posting.google.com>,
te0543@giga.net.tw (Joseph) wrote:

> Barry Margolin <barmar@alum.mit.edu> wrote in message
> news:<barmar-3FDE84.02440119102004@comcast.dca.giganews.com>... 
>
> If 192.168.100.1 belong to interface1,192.168.100.2 belongs to
> interface2.
> Interface1 and interface2 are both on net1.
> If I want to read packet from interface1,write to interface2,os may
> loop around in the kernel,right?

When you say "write to interface2", I thought you meant "send a packet
out from interface2 to another system".

Now I don't know what you mean.  You don't write to an interface, you
send to a destination IP addresses.  If that destination happens to be
the local system, it will loop around.  It doesn't matter where you
originally read from.

--
Barry Margolin, barmar@alum.mit.edu
Arlington, MA
*** PLEASE post questions in newsgroups, not directly to me ***

Report this thread to moderator Post Follow-up to this message
Old Post
Barry Margolin
10-19-04 02:05 PM


Re: interface to interface
On Tue, 19 Oct 2004 03:51:28 -0700, Joseph wrote:

> If 192.168.100.1 belong to interface1,192.168.100.2 belongs to
> interface2.
> Interface1 and interface2 are both on net1.
> If I want to read packet from interface1,write to interface2,os may
> loop around in the kernel,right?

If, by packet, you mean data. Then you can still do it with a read+write
loop ... you just need to also do a bind() on each socket, to bind them to
the IP on each interface.
If you really do mean packet, then you can use a RAW socket see:

http://www.faqs.org/faqs/internet/tcp-ip/raw-ip-faq/

--
James Antill -- james@and.org
Need an efficient and powerful string library for C?
http://www.and.org/vstr/


Report this thread to moderator Post Follow-up to this message
Old Post
James Antill
10-19-04 08:58 PM


Re: interface to interface
>  If, by packet, you mean data. Then you can still do it with a read+write
> loop ... you just need to also do a bind() on each socket, to bind them to
> the IP on each interface.
>  If you really do mean packet, then you can use a RAW socket see:
>
> http://www.faqs.org/faqs/internet/tcp-ip/raw-ip-faq/

Can't I use fd1=open("/dev/if1"),fd2=open("/dev/if2") and read(fd1),write(fd
2)?

Report this thread to moderator Post Follow-up to this message
Old Post
Joseph
10-21-04 01:57 PM


Sponsored Links




Last Thread Next Thread Next
Search this forum -> 
Post New Thread

Unix Programming archive

Show a Printable Version Send to friend Email This Page to Someone! subscribe to this thread Receive updates to this thread
Computer Consultants
Programming Jobs
Visual Basic Controls
SQL Server Programming
Webservices
Java Security
Visual Studio
C# Programming
Visual J++
Software engineering
Open source Software
Perl Programming
PHP Programming
ASP Programming
ASP .NET Programming
Visual Basic Programming
Windows Scripting Host
Java Programming
Java Help
Java Beans
VBScript
Cobol
MAC Applications
Unix Programming
Forum Jump:
All times are GMT. The time now is 06:00 PM.

 
Free MCSE Braindumps | Real Estate Topics

Programming forum archive

Copyrights CodeComments.com 2004 - 2006

Powered by vBulletin Copyright 2000-2006 Jelsoft Enterprises Limited.