LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices



Reply
 
Search this Thread
Old 05-05-2005, 06:39 AM   #1
jayanth
LQ Newbie
 
Registered: Jul 2003
Distribution: Kubuntu 7.10 Gutsy Gibbon
Posts: 10

Rep: Reputation: 0
Programming a Transparent Proxy Server


Hi,

I am in the process of programming a transparent proxy server in C on Linux. I have to get some concepts clear.

Browser <--> Proxy <--> ISP

The proxy has two struct sockaddr_ins called proxaddr (which contains the IP address of the proxy - 127.0.0.1) and ispaddr (which contains the gateway IP address of the ISP). My doubt is, once my proxy receives responses from the ISP, how do I transfer it to the browser?

Please help.

Jayanth
 
Old 05-05-2005, 04:59 PM   #2
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 58
The browser should be expecting the response so you just write() to the socket it's connected on.
 
Old 05-06-2005, 01:20 AM   #3
jayanth
LQ Newbie
 
Registered: Jul 2003
Distribution: Kubuntu 7.10 Gutsy Gibbon
Posts: 10

Original Poster
Rep: Reputation: 0
Hi,

Thanks for that, itsme86!

Now I have another problem. I have this sockaddr_in struct called proxaddr with address 127.0.0.1 and the specified port. The browser communicates to this server using this struct (the socket on which the proxy listens is bound to this address). The problem is, I am not able to use the same address while receiving from the ISP. I get a bind() error here. How do I solve this problem?

Please help.

Jayanth
 
Old 05-06-2005, 05:28 PM   #4
itsme86
Senior Member
 
Registered: Jan 2004
Location: Oregon, USA
Distribution: Slackware
Posts: 1,246

Rep: Reputation: 58
You should only be bind()'ing one time, to the listening socket that the browser connects to. So you have that listening socket and you do something like select() on it to wait for the browser to connect. As soon as it connects, select() exits and you call accept() which will return the new socket for communication with the browser. Then you can read the data the browser sends on that new socket and parse the data for the request. Then you create a new socket using connect() to serve the request. Once connect() returns you send the request on behalf of the browser and then read() from that socket. When you get data from that one you then write() it to the socket for the browser.
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
Can't make proxy server transparent scjvsTP Linux - Networking 2 11-29-2005 01:10 PM
transparent squid proxy server alvi2 Linux - Networking 4 02-24-2005 02:18 PM
Using Transparent Proxing with Apache Proxy server adityanag Linux - Networking 1 01-02-2005 11:48 AM
network access control with transparent proxy server namin Linux - Networking 1 08-16-2004 03:11 PM
network access control with transparent proxy server namin Linux - Newbie 1 08-15-2004 06:51 PM


All times are GMT -5. The time now is 10:48 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration