Skip to content

Access the child connection file descriptor #22

@smuellerDD

Description

@smuellerDD

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.

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions