[ruby-core:35999] [Ruby 1.9 - Feature #4645][Open] Pass existing buffer to getsockopt

3 views
Skip to first unread message

Brian Candler

unread,
May 4, 2011, 5:11:20 AM5/4/11
to ruby...@ruby-lang.org

Issue #4645 has been reported by Brian Candler.

----------------------------------------
Feature #4645: Pass existing buffer to getsockopt
http://redmine.ruby-lang.org/issues/4645

Author: Brian Candler
Status: Open
Priority: Normal
Assignee:
Category:
Target version:


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);
...

--
http://redmine.ruby-lang.org

Akira Tanaka

unread,
Jun 13, 2011, 3:59:26 AM6/13/11
to ruby...@ruby-lang.org

Issue #4645 has been updated by Akira Tanaka.


I think it is reasonable.

It also makes us possible to specify the buffer size.
Currently the buffer size for getsockopt is fixed. (256 bytes)

However I'd like to see actual good example for this feature.
It is great for the method document.

I searched Linux kernel for ".getsockopt" and "copy_from_user".
I guess SCTP_STATUS or IP_MSFILTER can be a candidate.

Is there better example?

Motohiro KOSAKI

unread,
Aug 7, 2011, 10:55:49 AM8/7/11
to ruby...@ruby-lang.org

Issue #4645 has been updated by Motohiro KOSAKI.

Status changed from Open to Feedback


----------------------------------------
Feature #4645: Pass existing buffer to getsockopt
http://redmine.ruby-lang.org/issues/4645

Author: Brian Candler
Status: Feedback

mame (Yusuke Endoh)

unread,
Nov 9, 2012, 4:09:45 AM11/9/12
to ruby...@ruby-lang.org

Issue #4645 has been updated by mame (Yusuke Endoh).

Target version set to next minor


----------------------------------------
Feature #4645: Pass existing buffer to getsockopt
https://bugs.ruby-lang.org/issues/4645#change-32697

Author: candlerb (Brian Candler)
Status: Feedback
Priority: Normal
Assignee:
Category:
Target version: next minor
http://bugs.ruby-lang.org/

Reply all
Reply to author
Forward
0 new messages