Go Premium for a chance to win a PS4. Enter to Win

x
?
Solved

Question about sockets

Posted on 2006-11-02
9
Medium Priority
?
236 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
8 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
Prepare for your VMware VCP6-DCV exam.

Josh Coen and Jason Langer have prepared the latest edition of VCP study guide. Both authors have been working in the IT field for more than a decade, and both hold VMware certifications. This 163-page guide covers all 10 of the exam blueprint sections.

 
LVL 35

Accepted Solution

by:
Duncan Roe earned 1000 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 35

Expert Comment

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

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

Keep up with what's happening at Experts Exchange!

Sign up to receive Decoded, a new monthly digest with product updates, feature release info, continuing education opportunities, and more.

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…
This Micro Tutorial will teach you how to add a cinematic look to any film or video out there. There are very few simple steps that you will follow to do so. This will be demonstrated using Adobe Premiere Pro CS6.
Look below the covers at a subform control , and the form that is inside it. Explore properties and see how easy it is to aggregate, get statistics, and synchronize results for your data. A Microsoft Access subform is used to show relevant calcul…

824 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