LinuxQuestions.org
LinuxAnswers - the LQ Linux tutorial section.
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 11-12-2010, 05:55 AM   #1
FatalKeystroke
LQ Newbie
 
Registered: Oct 2010
Distribution: Debian Squeeze x86_64, #!crunchbang 9.04
Posts: 26

Rep: Reputation: 1
Socket "File Descriptor", Where is it?


Does anyone know WHERE in the Linux directory structure sockets can be found?

Whenever I look up how to use sockets in C++, I get examples that tell how to use them in C. I understand the two are compatible, but I am currently forced to create a socket "file descriptor" and access it using the integer returned. Is there anyway to get the path to this file (It is a real file right?) so that I can access it with C++'s <fstream> library instead?
 
Old 11-12-2010, 06:04 AM   #2
Sergei Steshenko
Senior Member
 
Registered: May 2005
Posts: 4,481

Rep: Reputation: 453Reputation: 453Reputation: 453Reputation: 453Reputation: 453
Quote:
Originally Posted by FatalKeystroke View Post
Does anyone know WHERE in the Linux directory structure sockets can be found?

Whenever I look up how to use sockets in C++, I get examples that tell how to use them in C. I understand the two are compatible, but I am currently forced to create a socket "file descriptor" and access it using the integer returned. Is there anyway to get the path to this file (It is a real file right?) so that I can access it with C++'s <fstream> library instead?
Why do you need the file in the first place ? I.e. read/write operations you do with file descriptor, not with file.

...

Anyway:

Code:
sergei@amdam2:~> file /var/run/avahi-daemon/socket
/var/run/avahi-daemon/socket: socket
- have a look at the output of 'netstat'.
 
Old 11-12-2010, 07:04 AM   #3
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,094
Blog Entries: 2

Rep: Reputation: 111Reputation: 111
It's not a real file. What I usually do is have a small socket class that overloads the << >> operators so you can use it like a stream. You could probably do something similar and just inherit from the fstream classes.
 
Old 11-12-2010, 07:38 AM   #4
wje_lq
Member
 
Registered: Sep 2007
Location: Mariposa
Distribution: Debian lenny, Slackware 12
Posts: 808

Rep: Reputation: 178Reputation: 178
... and do check out the stringstream class.
 
Old 11-12-2010, 07:39 AM   #5
FatalKeystroke
LQ Newbie
 
Registered: Oct 2010
Distribution: Debian Squeeze x86_64, #!crunchbang 9.04
Posts: 26

Original Poster
Rep: Reputation: 1
Ok, I was thinking it was maybe a file in /proc/<PID> or something. If I just have to overload the insertion/extraction operators, that's fine. I was just wondering if perhaps there was an actual file that the "file descriptor" pointed to.
If not, it's no big deal, the question was mainly from curiosity, not from actual necessity.
 
Old 11-12-2010, 10:10 PM   #6
estabroo
Senior Member
 
Registered: Jun 2008
Distribution: debian, ubuntu, sidux
Posts: 1,094
Blog Entries: 2

Rep: Reputation: 111Reputation: 111
Well you are right in that aspect, there will be a proc entry for the file descriptor, don't know if you can open socket ones but you certainly can the other ones so it is worth trying to see.

/proc/<pid>/fd/n

if you do an ls -l of the fd directory you can see which ones are socket based ones
 
  


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
Reuse socket fails "Address already in use" or "Connection refused" dec10 Programming 3 05-15-2010 12:14 PM
How to get reference to "sock" structure related to particular socket descriptor abhishek@LQ Linux - Networking 1 05-24-2009 11:07 AM
File Descriptor does not become "ready" for read after select() Winnie Wilson Linux - Newbie 0 02-03-2009 10:59 AM
rmmod results in "bad file descriptor" wpbgent Linux - Newbie 1 07-29-2008 09:57 AM
help : the file descriptor was blocked in "select()" ..... makelinux Programming 1 06-09-2008 01:41 PM


All times are GMT -5. The time now is 02:13 AM.

Main Menu
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
identi.ca: @linuxquestions
Facebook: linuxquestions Google+: linuxquestions
Open Source Consulting | Domain Registration