Solved

C++ local proxy on 127.0.0.1

Posted on 2010-09-03
5
645 Views
Last Modified: 2012-05-10
Hi Guys,

I need to create a local listener, almost something like a proxy in C++ on 127.0.0.1 with a predefined port ex. 1234. How would I approach this?

The application needs to listen for any data that gets passed to it from lets say Firefox (configured to proxy 127.0.0.1:1234) and forward that request to another location. Lets say if that request is www.google.com than it redirects it to a local search engine.

I found something in C# and HttpListener but nothing in C++ on how I could achieve this functionality.

Thank you for all your help. Any feedback will be appreciated.
0
Comment
Question by:xNejX
  • 3
5 Comments
 
LVL 40

Expert Comment

by:evilrix
ID: 33600627
You can do this without writing code... just add www.google.com to your local hosts file and set the IP address to be that of your local search engine. This will redirect the call as you require.
0
 
LVL 40

Expert Comment

by:evilrix
ID: 33600637
If you do want to do this as a C++ app you will need to know how to do socket programming. A good place to start is Beej's Guide to Network Programming.

http://www.beej.us/guide/bgnet/
0
 

Author Comment

by:xNejX
ID: 33600700
Thanks for the reply, I want and need to do it as an app. I am looking for a more specific guideline on where to focus on.

Thank you,
0
 
LVL 40

Accepted Solution

by:
evilrix earned 250 total points
ID: 33600758
>> I am looking for a more specific guideline on where to focus on.
Well the question is, do you have any idea how to write a socket based application? If not this will be non-trivial and guidelines are not really going to help you much, hence my recommendation to look at Beej's.

Once you understand how to open a socket, listen, accept connections, spawn a new thread to handle the connection, read from the socket, decode the protocol (http?) to identify what the requirement is, then (if necessary) spawn a new socket that connects to the destination and then handle the reading from the source socket and writing to the destination socket and vice versa (don't forget the communication is full-duplex) you'll be on your way. Like I said, this is non-trivial.

It might help if you can explain why you want to do this as there may be a better and simpler alternative.
0
 
LVL 86

Assisted Solution

by:jkr
jkr earned 250 total points
ID: 33600779
You migh tfind http://www.codeproject.com/KB/IP/simplehttpproxy.aspx ("A Simple HTTP Proxy with the ACE Library") interesting - the article comes with full source code.
0

Featured Post

Courses: Start Training Online With Pros, Today

Brush up on the basics or master the advanced techniques required to earn essential industry certifications, with Courses. Enroll in a course and start learning today. Training topics range from Android App Dev to the Xen Virtualization Platform.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Converting to C# also VS2015 5 125
object modeling - load and save functions 5 61
How to copy an image file into clipboard C/C++? 1 168
What is sub-make ? 2 58
In days of old, returning something by value from a function in C++ was necessarily avoided because it would, invariably, involve one or even two copies of the object being created and potentially costly calls to a copy-constructor and destructor. A…
IntroductionThis article is the second in a three part article series on the Visual Studio 2008 Debugger.  It provides tips in setting and using breakpoints. If not familiar with this debugger, you can find a basic introduction in the EE article loc…
The goal of the tutorial is to teach the user how to use functions in C++. The video will cover how to define functions, how to call functions and how to create functions prototypes. Microsoft Visual C++ 2010 Express will be used as a text editor an…
The viewer will learn additional member functions of the vector class. Specifically, the capacity and swap member functions will be introduced.

776 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question