Solved

Question about sockets

Posted on 2006-11-02
9
224 Views
Last Modified: 2010-04-22
Hello i have a program that uses a tcp socket to connect to a server, i want to send packets using that socket but from another program, i've tryed opening the socket file descriptor listed in /proc/<pid>/fd but that didn't worked for sockets (it worked on normal files). Is there a way to do this?
0
Comment
Question by:zionz
9 Comments
 
LVL 3

Expert Comment

by:loki982
ID: 17863830
look in <sys/socket.h> for the send function
it just might do the trick for ya
man 2 send
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 17864657
Sorry - there's no way to take over file descriptor of another process(open file or socket).
opening /proc/PID/fd/number opens new instance of file in fact (it's symlink).
OK - there is possibility to transfer opened file descriptor from one process to another, but they have to cooperate(process have to be willing to give it's opened socket to another) - can they in Your example?
0
 
LVL 1

Expert Comment

by:a2h0mi
ID: 17865304
Hi

A simple way is to fork your process and as the child-process you can communicate with parent-process over sockets.

regards,
a2h0mi
0
Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

 
LVL 34

Accepted Solution

by:
Duncan Roe earned 250 total points
ID: 17871257
The /proc symbolic link for a socket looks like:
   lrwx------  1 dunc users 64 2006-10-21 10:31 10 -> socket:[1225]
When you try to open it, it fails:
   10:54:37$ cat 10
   cat: 10: No such device or address
It really is the open() call that fails (from strace):
   open("10", O_RDONLY|O_LARGEFILE)        = -1 ENXIO (No such device or address)
If the fd is a symlink to a real file then of course it works.

You need to modify the program that has the socket with the server. Make sure the socket fd has close_on_exec flag *not* set. Now any program you fork and exec has access to the socket. Any recieved data item can only be recieved by one process - the other misses out. So there needs to be co-operation in that regard.
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 18044607
since no input from author: delete/no refund.
0
 
LVL 34

Expert Comment

by:Duncan Roe
ID: 18048631
Is that the rule?
0
 
LVL 34

Expert Comment

by:Duncan Roe
ID: 18048639
I mean, if it was the rule then Venabili  could just have recommened it straight off
0
 
LVL 43

Expert Comment

by:ravenpl
ID: 18051868
duncan_roe: what You want? It's just my suggestion. If You have another, bring it here.
0

Featured Post

Master Your Team's Linux and Cloud Stack!

The average business loses $13.5M per year to ineffective training (per 1,000 employees). Keep ahead of the competition and combine in-person quality with online cost and flexibility by training with Linux Academy.

Question has a verified solution.

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

Have you ever been frustrated by having to click seven times in order to retrieve a small bit of information from the web, always the same seven clicks, scrolling down and down until you reach your target? When you know the benefits of the command l…
The purpose of this article is to demonstrate how we can upgrade Python from version 2.7.6 to Python 2.7.10 on the Linux Mint operating system. I am using an Oracle Virtual Box where I have installed Linux Mint operating system version 17.2. Once yo…
Nobody understands Phishing better than an anti-spam company. That’s why we are providing Phishing Awareness Training to our customers. According to a report by Verizon, only 3% of targeted users report malicious emails to management. With compan…
The Email Laundry PDF encryption service allows companies to send confidential encrypted  emails to anybody. The PDF document can also contain attachments that are embedded in the encrypted PDF. The password is randomly generated by The Email Laundr…

777 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