-
Notifications
You must be signed in to change notification settings - Fork 87
Description
When a new connection is made, the accept() system call returns a file descriptor that is used to perform all subsequent communication for a given session.
That FD is maintained in:
struct _ServerConnection
{
int fd;
...
Now, this structure is private and thus no advertised API.
However, I would like to access this FD as I would like to use it to use it with getsockopt().
Currently I have to copy the structure definitions of struct _ServerConnection and struct _ServerRequest into my code and resolve it using the closure data as follows:
int func(void *closure_data)
{
ServerRequest *server_request = closure_data;
ServerConnection *conn = server_request->conn;
struct ucred cred;
socklen_t len = sizeof(cred);
if (getsockopt(conn->fd, SOL_SOCKET, SO_PEERCRED, &cred, &len) < 0)
...
This is a hack that I would like to avoid. Is there a way to access the FD using the API? If not, I would be willing to write a patch. But I am not sure how such a patch would look like as there are 2 options:
-
make the FD available, i.e. return the FD number
-
provide wrapper API calls around getsockopt (e.g. one API call to obtain SO_PEERCRED, one for another call).
I would lean towards the first option.