Solved

Question about sockets

Posted on 2006-11-02
9
227 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
[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
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
Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 
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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

The purpose of this article is to fix the unknown display problem in Linux Mint operating system. After installing the OS if you see Display monitor is not recognized then we can install "MESA" utilities to fix this problem or we can install additio…
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 video Micro Tutorial shows how to password-protect PDF files with free software. Many software products can do this, such as Adobe Acrobat (but not Adobe Reader), Nuance PaperPort, and Nuance Power PDF, but they are not free products. This vide…
Do you want to know how to make a graph with Microsoft Access? First, create a query with the data for the chart. Then make a blank form and add a chart control. This video also shows how to change what data is displayed on the graph as well as form…

729 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