Code Comments
Programming Forum and web based access to our favorite programming groups.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?
Post Follow-up to this messageIn 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 ***
Post Follow-up to this messageBarry 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?
Post Follow-up to this messageIn 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 ***
Post Follow-up to this messageOn 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/
Post Follow-up to this message> 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)?
Post Follow-up to this message
Show a Printable Version
Email This Page to Someone!
Receive updates to this thread
Powered by vBulletin
Copyright 2000-2006 Jelsoft Enterprises Limited.