Solved

C++ local proxy on 127.0.0.1

Posted on 2010-09-03
5
647 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

Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Title # Comments Views Activity
getting a fire fox page (view page source ) in c++ 6 42
C++ to C# code conversion issue 4 111
Issues with C++ Class 19 101
Beginner to Unreal Engine 4 5 94
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…
C++ Properties One feature missing from standard C++ that you will find in many other Object Oriented Programming languages is something called a Property (http://www.experts-exchange.com/Programming/Languages/CPP/A_3912-Object-Properties-in-C.ht…
The viewer will learn how to use the return statement in functions in C++. The video will also teach the user how to pass data to a function and have the function return data back for further processing.
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.

808 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