UNIX Socket FAQ

A forum for questions and answers about network programming on Linux and all other Unix-like systems

You are not logged in.

  • Index
  • » C
  • » get absolute path of socket

#1 2009-07-04 11:01 PM

thinking
Member
Registered: 2005-09-15
Posts: 103

Re: get absolute path of socket

hi all

given is a file named 'socket' which is of type S_IFSOCK (from a unix domain socket)

now i try to stat the file just with the given file name 'socket'
stat returns ENOTDIR OR ENOENT cause it expects an absolute path
i tried realpath to convert 'socket' to an absolute path which results in ENOENT (i think because of the socket type of the file)
so the only way i see is: creating an absolute path by myself using a few if-statements and trial&error code to try path's like '/socket' OR cwd()'/socket'
but this is just trying which i dont like and its not very portable

so the question is:
did i miss something on my trys on realpath/stat OR how do i get the absolute path of a socket file without trying around?

thx all

Offline

#2 2009-07-05 12:34 AM

i3839
Oddministrator
From: Amsterdam
Registered: 2003-06-07
Posts: 2,239

Re: get absolute path of socket

stat() doesn't expect an absolute path, a relative path also works.

But you have either the fd, or a pathname. If you have a fd you don't
need the path, most of the time. If you have the path you should be able
to open the file/socket or do anything else.

Or do you have a unix domain socket fd created by socketpair() or an
abstract namespace unix domain socket, and try to use its path? That
won't work as there is no corresponding file path.

Offline

#3 2009-07-05 05:30 PM

RobSeace
Administrator
From: Boston, MA
Registered: 2002-06-12
Posts: 3,839
Website

Re: get absolute path of socket

Yeah, if you're getting ENOENT, then you must not actually be in the same directory
as the socket file, or else it really has a different name than you think it does...

But, why do you want to stat() it, anyway?  You can't really get much useful stat info
out of a socket file...  I suppose owner/group/perms might be useful, but that's about
it...  And, it really only matters on some systems...  (Some systems ignore perms for
socket files...)

Offline

  • Index
  • » C
  • » get absolute path of socket

Board footer

Powered by FluxBB