Hi Yeah I forgot to mention the LOCAL_CREDS. It does not return the PID of the client process but i guess it could be expanded to include that instead of adding another option for that. On Sun, Jul 9, 2017 at 11:47 AM, Stefan Ehmann <shoesoft_at_gmx.net> wrote: > On 09.07.2017 10:03, Johannes Lundberg wrote: > >> Hi >> >> Without altering the client code (i.e. adding sendmsg(credentials)), is >> there anyway of getting the client PID (or path to binary) using the file >> descriptor returned by accept() on the server side? >> >> Similar to Linux's getsockopt with SO_PEERCRED option. >> > > You want the LOCAL_CREDS socket option from unix(4). > > There's also a FreeBSD sample in the UNIX network programming book. Source > is available from http://unpbook.com/src.html > > With the following two changes it seems to work for me: > unixstrserv02.c: set LOCAL_CREDS > readcred.c: disable CONTROL_LEN check > > $ ./unixstrserv02 > PID of sender = 1001 > real user ID = 1001 > real group ID = 1001 > effective user ID = 1001 > 3 groups: 0 5 920 >Received on Sun Jul 09 2017 - 07:52:39 UTC
This archive was generated by hypermail 2.4.0 : Wed May 19 2021 - 11:41:12 UTC