LinuxQuestions.org
Latest LQ Deal: Latest LQ Deals
Go Back   LinuxQuestions.org > Forums > Non-*NIX Forums > Programming
User Name
Password
Programming This forum is for all programming questions.
The question does not have to be directly related to Linux and any language is fair game.

Notices


Reply
  Search this Thread
Old 04-10-2013, 07:19 AM   #1
Mans
LQ Newbie
 
Registered: Apr 2013
Posts: 2

Rep: Reputation: Disabled
Can I prevent a socket from being redirected?


Hello all,

I have a problem. A client/server program I am writing (in C) uses sockets for internal communication. Normally this works fine, there is however one case that causes a serious problem.

On one system I need to run the client part of my program from a perl script. When I do so the socket my client opens to the server gets captured by the perl script and the data dumped to stdout. With the obvious result that my program stops working.
  • It is not an option to run my program without the perl script, unfortunately.
  • It is a serious time delay and cost involved in getting the perl script changed; that is if it can even be done.

Ideally I would like to be able to prevent my socket from being redirected to stdout. While I'm not new to programming, I am new to Linux programming and would appreciate any input regarding this. Can it be done (easily)? Either by some construct in my code, environment variables, options set on the socket, whatever.. I would hate to have to create a bash fork that refuses to redirect sockets.

If you feel that you need more information before you can give a relevant answer, please just ask.

Best regards,
Mans
 
Old 04-10-2013, 07:35 AM   #2
NevemTeve
Senior Member
 
Registered: Oct 2011
Location: Budapest
Distribution: Debian/GNU/Linux, AIX
Posts: 4,856
Blog Entries: 1

Rep: Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869Reputation: 1869
> On one system I need to run the client part of my program from a perl script. When I do so the socket my client opens to the server gets captured by the perl script and the data dumped to stdout. With the obvious result that my program stops working.

Could you please explain this? You have a binary program that connects (connect(2) to a remote server via TCP -- but if you start your program from a Perl-script (with function system?), somehow its connections to the server gets kidnapped?! A bit hard to believe.
 
Old 04-15-2013, 01:25 AM   #3
Mans
LQ Newbie
 
Registered: Apr 2013
Posts: 2

Original Poster
Rep: Reputation: Disabled
Quote:
Could you please explain this? You have a binary program that connects (connect(2) to a remote server via TCP -- but if you start your program from a Perl-script (with function system?), somehow its connections to the server gets kidnapped?! A bit hard to believe.
Sure! I do have a binary program which first opens a socket (socket(2); PF_INET, SOCK_STREAM) and then connects (connect(2); 127.0.0.1, dynamic ports) to the server. The server in this instance is not remote, it is local on the same machine. I must admit I have not tried having it on a remote machine.

What function the perl script uses to start the binary is currently unknown, it's huge and I haven't gotten to the bottom of it yet. It is object oriented and pretty hard to follow... Just to be clear, it's not any perl script that causes this bahavior - if I write a short, script that does more or less nothing but start my binary it works fine - it's this particular perl script that does something weird and I need to figure out what and how to stop it.

I know it is a bit hard to believe. I know I wouldn't unless I was sitting here staring at the results. Actually I'd even say more than a bit hard, but then I often see "the power of redirection on the command line" as an example of why *nix is so wonderful, I can only assume it is this power being wielded here without thought of the end result. I might assume wrong though, but the fact is - commands that should only pass between client and server are dumped to stdout and the perl script's log file and never reach the server.
 
Old 04-15-2013, 01:35 AM   #4
pan64
LQ Addict
 
Registered: Mar 2012
Location: Hungary
Distribution: debian/ubuntu/suse ...
Posts: 21,779

Rep: Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304Reputation: 7304
probably you need to show us that perl script, or find the relevant part. There can be a proxy or ?? you can try lsof or strace to check what that perl program tries to do. Actually you have no chance to check what is going on at the other side of the socket, but you may have a chance to check if it was a socket or a terminal (isatty)
 
  


Reply


Thread Tools Search this Thread
Search this Thread:

Advanced Search

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off



Similar Threads
Thread Thread Starter Forum Replies Last Post
127.0.0.1 gets redirected liou Linux - Networking 6 12-11-2009 12:55 AM
iptables - why am I still being redirected? michaelsanford Linux - Networking 1 05-23-2005 03:52 PM
GPG and redirected input Vookimedlo Linux - Software 1 04-30-2005 04:32 PM
Is a Domain being redirected? rigel_kent Programming 0 02-14-2005 06:43 AM
my domain is getting redirected to a different ip. QS_Shorty Linux - Newbie 3 02-10-2004 08:22 PM

LinuxQuestions.org > Forums > Non-*NIX Forums > Programming

All times are GMT -5. The time now is 02:58 AM.

Main Menu
Advertisement
My LQ
Write for LQ
LinuxQuestions.org is looking for people interested in writing Editorials, Articles, Reviews, and more. If you'd like to contribute content, let us know.
Main Menu
Syndicate
RSS1  Latest Threads
RSS1  LQ News
Twitter: @linuxquestions
Open Source Consulting | Domain Registration