How to find the other point of a Unix domain socket on Mac OS X to write/read it?

5,122

It is possible for an AF_UNIX socket to be unbound to a filename, to be "unnamed", (or also "abstract" in which case is has a name but it has nothing to do with the filesystem) at least in Linux. It is unlikely that OS X is different. For details, see the man page for the socket function bind (or look in the dev docs).

Anyway, if OS X has the equivalent of the /proc filesystem you could possibly get a handle on the socket by going through the list of file descriptors of the target process. YMMV. Oops, it does not have a procfs. See this about Mac specific workarounds.

Share:
5,122

Related videos on Youtube

yves Baumes
Author by

yves Baumes

Updated on September 18, 2022

Comments

  • yves Baumes
    yves Baumes over 1 year

    I listed open file for a process (a daemon) on my box which runs Mac OS X 10.5 :

    >lsof  -p 89
    COMMAND PID     USER   FD   TYPE    DEVICE  SIZE/OFF     NODE NAME
    ...
    xxxxx   89 xxxxxxxx    9u  unix 0x34f8990       0t0          ->0x34f8880
    

    I 'd like to find a way to open this socket and write in it. (that's my obsession this time ..)

    How to find the i-node/name of the underlying file in order to reach that socket? Is there a way to address programatically this adress 0x34f888 from a shell script? If not so, how to do programatically ?

    As a comment, I've launched the netstat command and get this result:

    > netstat -u
    Active LOCAL (UNIX) domain sockets
    Address  Type   Recv-Q Send-Q    Inode     Conn     Refs  Nextref Addr
    ...
     34f8990 stream      0      0        0  34f8880        0        0
    ...
     34f8880 stream      0      0        0  34f8990        0        0
    ...
    

    I am not a network/socket guru. Hope this could give more information

    PS: to be honest I've posted this question on StackOverflow first (sorry, I don't think to ServerFault a first sight for now) but no one seems to give answer . :/ same question on SO

    • Alnitak
      Alnitak about 15 years
      this is really a programming question - please address the question there and not here.
  • yves Baumes
    yves Baumes about 15 years
    What is the "mto manifest" ? Btw I was surprised to see in the netstat output that that socket does not have any i-node associated with . How to find it so ?
  • jj33
    jj33 about 15 years
    as someone who makes that kind of typo all the time, I'll answer =). "the mto" == "them to".
  • ConcernedOfTunbridgeWells
    ConcernedOfTunbridgeWells about 15 years
    There, fixed. =8^o