Solved

C++ local proxy on 127.0.0.1

Posted on 2010-09-03
5
653 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
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 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

Errors will happen. It is a fact of life for the programmer. How and when errors are detected have a great impact on quality and cost of a product. It is better to detect errors at compile time, when possible and practical. Errors that make their wa…
Written by John Humphreys C++ Threading and the POSIX Library This article will cover the basic information that you need to know in order to make use of the POSIX threading library available for C and C++ on UNIX and most Linux systems.   [s…
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 how to clear a vector as well as how to detect empty vectors in C++.

717 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