LinuxQuestions.org
Download your favorite Linux distribution at LQ ISO.
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-17-2004, 04:02 AM   #1
sudheernair
LQ Newbie
 
Registered: Apr 2004
Posts: 7

Rep: Reputation: 0
Lightbulb using a socket decriptor opened by anoter process


when i start using( send data) the socket descriptor that another process had opened and passed it to current program i got bad descriptor error. any idea how to transfer the permissions or security clearance for an file descriptor.
Thanks Sudheer
 
Old 04-17-2004, 06:21 AM   #2
Hko
Senior Member
 
Registered: Aug 2002
Location: Groningen, The Netherlands
Distribution: Debian
Posts: 2,536

Rep: Reputation: 111Reputation: 111
How did you pass it to the other process?
 
Old 04-17-2004, 08:47 PM   #3
TedMaul
LQ Newbie
 
Registered: Jan 2004
Location: UK
Distribution: LFS
Posts: 15

Rep: Reputation: 0
If you're using unix-domain sockets to pass the fd, there's some arcane feature you can use to do this. I can't remember the details, but `man 7 unix` should give you a brief overview.
 
Old 04-17-2004, 09:57 PM   #4
aluser
Member
 
Registered: Mar 2004
Location: Massachusetts
Distribution: Debian
Posts: 557

Rep: Reputation: 43
To clarify, it sounds like the OP was just sending the int for the file descriptor over a regular pipe or socket. This isn't enough information: that integer is not unique between processes.

So you have to use this crazy feature of unix domain sockets with sendmsg() so the kernel can effectively dup() your descriptor for the other process.. Cool feature, a little weird though.
 
Old 04-19-2004, 01:17 AM   #5
sudheernair
LQ Newbie
 
Registered: Apr 2004
Posts: 7

Original Poster
Rep: Reputation: 0
I passed it through shared memory. now let me try your suggessions. thank you all for replaying.
Sudheer
 
Old 04-19-2004, 10:15 AM   #6
sudheernair
LQ Newbie
 
Registered: Apr 2004
Posts: 7

Original Poster
Rep: Reputation: 0
okay, i tried dup2 and fcntl functions but it didn't work. if the process that created the socket discriptor calls these function then further communication on the duplicate descriptor works. But if it is with the another process then fails.
Sudheer
 
Old 04-19-2004, 11:20 AM   #7
TedMaul
LQ Newbie
 
Registered: Jan 2004
Location: UK
Distribution: LFS
Posts: 15

Rep: Reputation: 0
Well, yes - that's as expected. If you call dup() or dup2(), all it does it duplicate the fd for the calling process. To use that fd in another process, you have to pass it through a unix-domain socket, using SCM_RIGHTS.
 
  


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
is a socket already opened? fcntl(); Thinking Programming 1 09-19-2005 10:47 AM
Process ID of a socket shadowmas Programming 2 06-28-2005 11:13 PM
Gettting ENOTCONN when sending data, but the socket was opened. trevelluk Programming 3 05-12-2005 11:43 AM
using a socket descriptor opened by another process sudheernair Programming 0 04-16-2004 07:29 AM
share socket between two process Vikash Singh Linux - Networking 0 10-10-2003 08:21 AM

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

All times are GMT -5. The time now is 01:24 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