Unix Programming - interface to interface

This is Interesting: Free IT Magazines  
Home > Archive > Unix Programming > October 2004 > interface to interface





You are viewing an archived Text-only version of the thread. To view this thread in it's original format and/or if you want to reply to this thread please [click here]

Author interface to interface
Joseph

2004-10-18, 8:48 pm

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?
Barry Margolin

2004-10-19, 2:48 am

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 ***
Joseph

2004-10-19, 7:50 am

Barry Margolin <barmar@alum.mit.edu> wrote in message news:<barmar-3FDE84.02440119102004@comcast.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?
Barry Margolin

2004-10-19, 7:50 am

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 ***
James Antill

2004-10-19, 5:51 pm

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/

Joseph

2004-10-21, 7:48 am

> 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(fd2)?
Sponsored Links






Free braindumps | Software forum | Database administration forum

Copyright 2003 - 2008 webservertalk.com