summaryrefslogtreecommitdiff
path: root/ext/socket
diff options
context:
space:
mode:
authorshugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-01-31 04:59:31 +0000
committershugo <shugo@b2dd03c8-39d4-4d8f-98ff-823fe69b080e>2013-01-31 04:59:31 +0000
commit4ccfb2743f38d54eeecc5a229b3a8edf2eb84f3c (patch)
tree1cfe1c98bc6e86ad2c05505275110e5af9241410 /ext/socket
parent1ff38a5bbf2baa5fa6646fffdc81ed3611be805b (diff)
* ext/socket/raddrinfo.c (rsock_unix_sockaddr_len): return
sizeof(sa_familiy_t) if path is empty. see "Autobind Feature" in unix(7) for details. * ext/socket/lib/socket.rb (unix_socket_abstract_name?): treat an empty path as an abstract name. * test/socket/test_unix.rb: related test. git-svn-id: svn+ssh://ci.ruby-lang.org/ruby/trunk@38994 b2dd03c8-39d4-4d8f-98ff-823fe69b080e
Diffstat (limited to 'ext/socket')
-rw-r--r--ext/socket/lib/socket.rb2
-rw-r--r--ext/socket/raddrinfo.c6
2 files changed, 6 insertions, 2 deletions
diff --git a/ext/socket/lib/socket.rb b/ext/socket/lib/socket.rb
index 981b937..540b018 100644
--- a/ext/socket/lib/socket.rb
+++ b/ext/socket/lib/socket.rb
@@ -819,7 +819,7 @@ class Socket < BasicSocket
private
def unix_socket_abstract_name?(path)
- /linux/ =~ RUBY_PLATFORM && /\A\0/ =~ path
+ /linux/ =~ RUBY_PLATFORM && /\A(\0|\z)/ =~ path
end
end
diff --git a/ext/socket/raddrinfo.c b/ext/socket/raddrinfo.c
index 79943c7..a730a1b 100644
--- a/ext/socket/raddrinfo.c
+++ b/ext/socket/raddrinfo.c
@@ -446,7 +446,11 @@ socklen_t
rsock_unix_sockaddr_len(VALUE path)
{
#ifdef __linux__
- if (RSTRING_PTR(path)[0] == '\0') {
+ if (RSTRING_LEN(path) == 0) {
+ /* autobind; see unix(7) for details. */
+ return (socklen_t) sizeof(sa_family_t);
+ }
+ else if (RSTRING_PTR(path)[0] == '\0') {
/* abstract namespace; see unix(7) for details. */
return (socklen_t) offsetof(struct sockaddr_un, sun_path) +
RSTRING_LEN(path);