Solved

C++ local proxy on 127.0.0.1

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

Why You Should Analyze Threat Actor TTPs

After years of analyzing threat actor behavior, it’s become clear that at any given time there are specific tactics, techniques, and procedures (TTPs) that are particularly prevalent. By analyzing and understanding these TTPs, you can dramatically enhance your security program.

Join & Write a Comment

Often, when implementing a feature, you won't know how certain events should be handled at the point where they occur and you'd rather defer to the user of your function or class. For example, a XML parser will extract a tag from the source code, wh…
Go is an acronym of golang, is a programming language developed Google in 2007. Go is a new language that is mostly in the C family, with significant input from Pascal/Modula/Oberon family. Hence Go arisen as low-level language with fast compilation…
The viewer will learn how to clear a vector as well as how to detect empty vectors in C++.
The viewer will be introduced to the member functions push_back and pop_back of the vector class. The video will teach the difference between the two as well as how to use each one along with its functionality.

747 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

Need Help in Real-Time?

Connect with top rated Experts

9 Experts available now in Live!

Get 1:1 Help Now