Project

General

Profile

Actions

Feature #4645

closed

Pass existing buffer to getsockopt

Added by candlerb (Brian Candler) over 13 years ago. Updated almost 7 years ago.

Status:
Feedback
Assignee:
-
Target version:
-
[ruby-core:35999]

Description

There are cases when you need to pass a pre-initialized buffer to
getsockopt, but ruby currently doesn't support this.

For an example, see the API used by iptables to manipulate the firewall
rulesets (below). You have to set the table name in the buffer passed to
getsockopt; the call then modifies the remainder of the buffer.

So I propose that BasicSocket#getsockopt be enhanced to allow an optional
third parameter, which is an existing String buffer, used both to pass
data and receive the result.

Does this sound reasonable?

Regards, Brian.

-------- 8< ----------------------------------------------
/* extract from iptables-1.4.4/libiptc/libiptc.c */

struct xtc_handle *
TC_INIT(const char *tablename)
{
STRUCT_GETINFO info;
socklen_t s;
int sockfd;
...
s = sizeof(info);

    strcpy(info.name, tablename);
    if (getsockopt(sockfd, TC_IPPROTO, SO_GET_INFO, &info, &s) < 0) {
            close(sockfd);
            return NULL;
    }

    DEBUGP("valid_hooks=0x%08x, num_entries=%u, size=%u\n",
            info.valid_hooks, info.num_entries, info.size);

...

Actions

Also available in: Atom PDF

Like0
Like0Like0Like0Like0