Socket, Bind, Connect: Remapping The Server

I am beginning to use the Perl commands SOCKET, BIND, and CONNECT to establish a connection to another website. What I do is set SOCKET appropriately, set BIND to my server name, and then set CONNECT to the website I want to connect to.  It all seems to work perfectly.

Now I have a CGI Perl script called Getgraphic.CGI.  My website has an IMG tag which calls this script (<img src="">).  Now I realize that a browser like Netscape must do the same procedure with the Socket, Bind, and Connect so as to make a connection to my CGI script.  Therefore when my CGI script begins to run a SOCKET path has been established to the client so that data can flow to and from.

What I would like to do is instead of my GetGraphic.CGI to output its image graphics I would like to "map" this existing socket connection to another server's CGI script for it to output its image graphics, all from within my GetGraphics.CGI.  Is there any way to do this?  Perhaps altering BIND (the command which took in my server name)?
Who is Participating?
stormeriderConnect With a Mentor Commented:
So what you want to do is to basically tunnel the traffic through your cgi? You could make a connection to where it needs to go and then grab the result, store it locally, and then send it to the connection being made to it. Or you could basically make a connection to the location, retrieve and print to the incoming location and not store it. Couple of different options there. Why are you doing this? You might also want to look at some port redirectors as well that do essentially this type of work.

ratboyAuthor Commented:
But if i make the call to that other server to get the picture then "my" IP address goes with it.  I want the clients ip address to fetch it instead. It's like i remapped the socket connection from me to the other server. Can these port redirectors do such things?
ratboyAuthor Commented:
I could use the Location:  command output from my CGI script which would do the trick perfectly, but I also want the Referer value to be set to a specific page; the CGI call can be made from multiple different pages but I want the Referer value to be set to a single, unchanging name.  How do I do that?

Sorry for the extra difficulties.  And thanks so far...
Get your problem seen by more experts

Be seen. Boost your question’s priority for more expert views and faster solutions

Port redirectors would mark the ip as well. In re: to the referrer, assuming you're using perl with the package,

if ($ENV{'HTTP_REFERER'} ne "") {

ratboyAuthor Commented:
To Stormerider:
  Unfortunately i don't see how that piece of Perl code can help me with that location and referrer problem. Can you explain to me in detail what you mean.

And for the port redirectors, you mean the IP Address will still be my own as opposed to the clients?
It should show it as originating from the client. If they do intensive logging, it should show that it routed through you, but that's unlikely.

Analyzing the code:
1.) If the page they are coming from ($ENV{'HTTP_REFERER'}) does not match the one you want (replace the one i put with your own, it was an example)
2.) Some subroutine to serve them a blank image, not the image they would get via the CGI
3.) Do whatever ordinary CGI cleanup you do
4.) Exit the CGI
5.) Needed for syntax.

This will block from anyone accessing this cgi who is not coming from that page.

ratboyAuthor Commented:
Truly I thank you Stormerider for being so patient with me.  Writing of the above message and comments have been a 30 second thing as I run in and out of the house.  Now I have more time to write what I want in more detail.

I have a website with 10 webpages on it (webpage 1 to 10).  What I would like to do is have a CGI script, called COCO.CGI, on webpage 1 which is called with <IMG src="cgi-bin/COCO.CGI">.  It takes in the HTTP_REFERER and REMOTE_ADDR and returns a graphical image if the HTTP_REFERER was set to webpage 1.

Now I would like to make a call to COCO.CGI from webpage 2 to 10 but unfortuantely the HTTP_REFERER will be set to webpage 2 to 10 instead of the required webpage 1.

This kind of problem sounds very trivial, even pointless/stupid but its something I need to figure out considering all those restrictions.

What I was thinking is to have a <IMG src="cgi-bin/MAPPER.CGI"> where MAPPER.CGI is a CGI script which is called from webpage 2 to 10.  Inside the script it will simply "redirect" (print "Location:\n\n";) the incoming call to the webpage 1 in hopes of 'triggering' the COCO.CGI.  Unfortunately the call to MAPPER.CGI, and so webpage1.htm, returns an error since the returned data is not a graphical image but an HTML file (due to the error, the HTM page isn't triggered and nor is COCO.CGI).  Now if I simply redirected to COCO.CGI instead of webpage1.htm, the HTTP_REFERER won't be set to webpage 1.  Tricky eh?

Now I'm probably over thinking the situation (I hope) and there's most likely an easy solution, but it just continues to elude me.  Any help you can provide in successfully "mapping" a call from one CGI script to another "while altering the HTTP_REFERER" to a new value would be greatly appreciated!

Thanks for your patience.  I'm crossing my fingers.   :>
Well, if this is the case, then I would save yourself a hell of a lot of grief and forget MAPPER.CGI. As far as I can tell, you don't need it. Basically what you want to do is along the lines of:

$http1 = "";
$http2 = "";
$http3 = "";
$http4 = "";
$http5 = "";

if ($ENV{'HTTP_REFERER'} eq $http1 {
} else if ($ENV{'HTTP_REFERER'} eq $http2) {
} else if ($ENV{'HTTP_REFERER'} eq $http3) {
} else if ($ENV{'HTTP_REFERER'} eq $http4) {
} else if ($ENV{'HTTP_REFERER'} eq $http5) {
} else <etc...> {

Does that help any?

ratboyAuthor Commented:
Great message Stormerider.   It does help!  Now just one last thing.  Those graphical images I send back to the client need to come from another server (my site is  and I need to fetch the graphics from  

If I use BIND/SOCKET/CONNECT then I'd be binding to my IP address and not the clients, unless I'm able to route BIND to the client and just send him/her the graphic directly from that server.  When I make this BIND/SOCKET/CONNECT call I can then set the Referer field to whatever I want.

So close to solving this problem. I can almost taste it. Any solutions with this added restricition?

Thanks for everything!
The only thing I can think of in regards to that, if the client IP has to be saved is to either route it through with a port redirector or use SSI. Rather than <IMG SRC=blah.cgi>, try
<!--#exec cgi="blah.cgi"--> and have it spit back <IMG SRC="">.

Make sense?
ratboyAuthor Commented:
Thanks a bunch Storemrider for everything!  You definitely deserve the points!

One last thing, what if the graphic that is returned is not an actual graphic file ( but is actually an output from a cgi script ( which outputs a graphical image.  The CGI script then checks IP # and Referer!

Thanks and here's your points!
ratboyAuthor Commented:
That's strange, the point worth was for 200 not 20.  Make sure you get the proper amount!  You deserve it.
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.