Identify program that connects to a Unix Domain Socket

前端 未结 3 1559
星月不相逢
星月不相逢 2021-02-07 17:37

I have a program that is listening to a Unix Domain Socket.

When a client connects to the socket I\'d like to find out which program connected and then decide if I allow

3条回答
  •  感情败类
    2021-02-07 18:12

    Perhaps getpeername or getsockname could help. and I think that the permission of your unix socket are useful (not sure of that). And you might read the link inside /proc/self/fd/12 if your accept-ed socket is 12.

    EDIT

    using ancillary data for credentials and sendmsg is much better, as suggested by cnicutar below.

提交回复
热议问题