Solved

Question about sockets

Posted on 2006-11-02
9
223 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
 
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
Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

 
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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn 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 demonstrates using Microsoft Excel pivot tables, how to reverse engineer competitors' marketing strategies through backlinks.
Migrating to Microsoft Office 365 is becoming increasingly popular for organizations both large and small. If you have made the leap to Microsoft’s cloud platform, you know that you will need to create a corporate email signature for your Office 365…

867 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

Need Help in Real-Time?

Connect with top rated Experts

18 Experts available now in Live!

Get 1:1 Help Now