diff --git a/ChangeLog b/ChangeLog
index 24861a3..abe9afb 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,82 @@
+Thu Jan 31 13:54:44 2013  Shugo Maeda  <shugo@ruby-lang.org>
+
+	* 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.
+
+Wed Jan 30 15:26:37 2013  Shugo Maeda  <shugo@ruby-lang.org>
+
+	* ext/socket/unixsocket.c (rsock_init_unixsock): use rb_inspect()
+	  because rb_sys_fail_str() fails if its argument contains NUL.
+
+	* test/socket/test_unix.rb: related test.
+
+Tue Jan 29 09:26:20 2013  Shugo Maeda  <shugo@ruby-lang.org>
+
+	* ext/socket/socket.c (sock_s_pack_sockaddr_un): calculate the
+	  correct address length of an abstract socket.
+
+	* test/socket/test_unix.rb: related test.
+
+Sat Jan 26 08:29:33 2013  Shugo Maeda  <shugo@ruby-lang.org>
+
+	* ext/socket/raddrinfo (rsock_unix_sockaddr_len): renamed from
+	  rsock_unixpath_len, because it returns not the length of the path,
+	  but the length of a socket address for the path.
+
+Fri Jan 25 16:47:31 2013  Shugo Maeda  <shugo@ruby-lang.org>
+
+	* ext/socket/raddrinfo.c (rsock_unixpath_len, init_unix_addrinfo),
+	  ext/socket/unixsocket.c (unixsock_connect_internal,
+	  rsock_init_unixsock): calculate the correct address length of
+	  an abstract socket.  Without this fix, sizeof(struct sockaddr_un)
+	  is specified as the length of an abstract socket for bind(2) or
+	  connect(2), so the address of the socket is filled with extra NUL
+	  characters.  See unix(7) for details.
+
+	* ext/socket/lib/socket.rb (unix_server_socket): don't access the
+	  file system if the platform is Linux and path starts with NUL,
+	  which means that the socket is an abstract socket.
+
+	* test/socket/test_unix.rb: related test.
+
+Fri Apr 27 07:15:07 2012  Tanaka Akira  <akr@fsij.org>
+
+	* ext/socket/socket.c (sock_s_pack_sockaddr_un): support the longest
+	  path in sockaddr_un, really.
+	  reported by nagachika.
+	  http://d.hatena.ne.jp/nagachika/20120426/ruby_trunk_changes_35474_35476
+
+Thu Apr 26 12:28:06 2012  Tanaka Akira  <akr@fsij.org>
+
+	* ext/socket/raddrinfo.c (init_unix_addrinfo): support the longest
+	  path in sockaddr_un.
+	  (inspect_sockaddr): ditto.
+	  (addrinfo_mdump): ditto.
+	  (addrinfo_mload): ditto.
+	  (rsock_unixpath_str): new function.
+	  (rsock_unixpath): removed.
+	  (rsock_unixaddr): use rsock_unixpath_str.
+
+	* ext/socket/socket.c (sock_s_pack_sockaddr_un): support the longest
+	  path in sockaddr_un.
+	  (sock_s_unpack_sockaddr_un): ditto.
+	  (sock_s_gethostbyaddr): unused variable removed.
+
+	* ext/socket/unixsocket.c (rsock_init_unixsock): support the longest
+	  path in sockaddr_un.
+
+	* ext/socket/rubysocket.h (rsock_unixpath_str): declared.
+	  (rsock_unixpath): removed.
+
+	* test/socket/test_unix.rb: comment out test_nul because abstract unix
+	  sockets may contain NULs.
+
 Tue Jan 15 16:30:29 2013  KOSAKI Motohiro  <kosaki.motohiro@gmail.com>
 
 	* thread_pthread.c (gvl_init): Reset gvl.wait_yield explicitly when
diff --git a/ext/socket/basicsocket.c b/ext/socket/basicsocket.c
index b997043..6f942e3 100644
--- a/ext/socket/basicsocket.c
+++ b/ext/socket/basicsocket.c
@@ -358,11 +358,13 @@ bsock_getsockname(VALUE sock)
 {
     struct sockaddr_storage buf;
     socklen_t len = (socklen_t)sizeof buf;
+    socklen_t len0 = len;
     rb_io_t *fptr;
 
     GetOpenFile(sock, fptr);
     if (getsockname(fptr->fd, (struct sockaddr*)&buf, &len) < 0)
 	rb_sys_fail("getsockname(2)");
+    if (len0 < len) len = len0;
     return rb_str_new((char*)&buf, len);
 }
 
@@ -387,11 +389,13 @@ bsock_getpeername(VALUE sock)
 {
     struct sockaddr_storage buf;
     socklen_t len = (socklen_t)sizeof buf;
+    socklen_t len0 = len;
     rb_io_t *fptr;
 
     GetOpenFile(sock, fptr);
     if (getpeername(fptr->fd, (struct sockaddr*)&buf, &len) < 0)
 	rb_sys_fail("getpeername(2)");
+    if (len0 < len) len = len0;
     return rb_str_new((char*)&buf, len);
 }
 
@@ -475,11 +479,13 @@ bsock_local_address(VALUE sock)
 {
     struct sockaddr_storage buf;
     socklen_t len = (socklen_t)sizeof buf;
+    socklen_t len0 = len;
     rb_io_t *fptr;
 
     GetOpenFile(sock, fptr);
     if (getsockname(fptr->fd, (struct sockaddr*)&buf, &len) < 0)
 	rb_sys_fail("getsockname(2)");
+    if (len0 < len) len = len0;
     return rsock_fd_socket_addrinfo(fptr->fd, (struct sockaddr *)&buf, len);
 }
 
@@ -507,11 +513,13 @@ bsock_remote_address(VALUE sock)
 {
     struct sockaddr_storage buf;
     socklen_t len = (socklen_t)sizeof buf;
+    socklen_t len0 = len;
     rb_io_t *fptr;
 
     GetOpenFile(sock, fptr);
     if (getpeername(fptr->fd, (struct sockaddr*)&buf, &len) < 0)
 	rb_sys_fail("getpeername(2)");
+    if (len0 < len) len = len0;
     return rsock_fd_socket_addrinfo(fptr->fd, (struct sockaddr *)&buf, len);
 }
 
diff --git a/ext/socket/init.c b/ext/socket/init.c
index 0a23658..54452e4 100644
--- a/ext/socket/init.c
+++ b/ext/socket/init.c
@@ -448,6 +448,7 @@ VALUE
 rsock_s_accept_nonblock(VALUE klass, rb_io_t *fptr, struct sockaddr *sockaddr, socklen_t *len)
 {
     int fd2;
+    socklen_t len0 = len ? *len : 0;
 
     rb_secure(3);
     rb_io_set_nonblock(fptr);
@@ -466,6 +467,7 @@ rsock_s_accept_nonblock(VALUE klass, rb_io_t *fptr, struct sockaddr *sockaddr, s
 	}
         rb_sys_fail("accept(2)");
     }
+    if (len && len0 < *len) *len = len0;
     rb_update_max_fd(fd2);
     make_fd_nonblock(fd2);
     return rsock_init_sock(rb_obj_alloc(klass), fd2);
@@ -481,7 +483,12 @@ static VALUE
 accept_blocking(void *data)
 {
     struct accept_arg *arg = data;
-    return (VALUE)accept(arg->fd, arg->sockaddr, arg->len);
+    int ret;
+    socklen_t len0 = 0;
+    if (arg->len) len0 = *arg->len;
+    ret = accept(arg->fd, arg->sockaddr, arg->len);
+    if (arg->len && len0 < *arg->len) *arg->len = len0;
+    return (VALUE)ret;
 }
 
 VALUE
diff --git a/ext/socket/lib/socket.rb b/ext/socket/lib/socket.rb
index d311eed..66ff548 100644
--- a/ext/socket/lib/socket.rb
+++ b/ext/socket/lib/socket.rb
@@ -716,12 +716,14 @@ class Socket < BasicSocket
   #   }
   #
   def self.unix_server_socket(path)
-    begin
-      st = File.lstat(path)
-    rescue Errno::ENOENT
-    end
-    if st && st.socket? && st.owned?
-      File.unlink path
+    if !unix_socket_abstract_name?(path)
+      begin
+        st = File.lstat(path)
+      rescue Errno::ENOENT
+      end
+      if st && st.socket? && st.owned?
+        File.unlink path
+      end
     end
     s = Addrinfo.unix(path).listen
     if block_given?
@@ -729,13 +731,23 @@ class Socket < BasicSocket
         yield s
       ensure
         s.close if !s.closed?
-        File.unlink path
+        if !unix_socket_abstract_name?(path)
+          File.unlink path
+        end
       end
     else
       s
     end
   end
 
+  class << self
+    private
+
+    def unix_socket_abstract_name?(path)
+      /linux/ =~ RUBY_PLATFORM && /\A(\0|\z)/ =~ path
+    end
+  end
+
   # creates a UNIX socket server on _path_.
   # It calls the block for each socket accepted.
   #
diff --git a/ext/socket/raddrinfo.c b/ext/socket/raddrinfo.c
index 2229269..80e59a0 100644
--- a/ext/socket/raddrinfo.c
+++ b/ext/socket/raddrinfo.c
@@ -421,20 +421,46 @@ rsock_ipaddr(struct sockaddr *sockaddr, int norevlookup)
 }
 
 #ifdef HAVE_SYS_UN_H
-const char*
-rsock_unixpath(struct sockaddr_un *sockaddr, socklen_t len)
+VALUE
+rsock_unixpath_str(struct sockaddr_un *sockaddr, socklen_t len)
 {
-    if (sockaddr->sun_path < (char*)sockaddr + len)
-        return sockaddr->sun_path;
+    char *s, *e;
+    s = sockaddr->sun_path;
+    e = (char *)sockaddr + len;
+    while (s < e && *(e-1) == '\0')
+        e--;
+    if (s <= e)
+        return rb_str_new(s, e-s);
     else
-        return "";
+        return rb_str_new2("");
 }
 
 VALUE
 rsock_unixaddr(struct sockaddr_un *sockaddr, socklen_t len)
 {
     return rb_assoc_new(rb_str_new2("AF_UNIX"),
-                        rb_str_new2(rsock_unixpath(sockaddr, len)));
+                        rsock_unixpath_str(sockaddr, len));
+}
+
+socklen_t
+rsock_unix_sockaddr_len(VALUE path)
+{
+#ifdef __linux__
+    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);
+    }
+    else {
+#endif
+	return (socklen_t) sizeof(struct sockaddr_un);
+#ifdef __linux__
+    }
+#endif
 }
 #endif
 
@@ -763,19 +789,22 @@ static void
 init_unix_addrinfo(rb_addrinfo_t *rai, VALUE path, int socktype)
 {
     struct sockaddr_un un;
+    socklen_t len;
 
     StringValue(path);
 
-    if (sizeof(un.sun_path) <= (size_t)RSTRING_LEN(path))
-        rb_raise(rb_eArgError, "too long unix socket path (max: %dbytes)",
-            (int)sizeof(un.sun_path)-1);
+    if (sizeof(un.sun_path) < (size_t)RSTRING_LEN(path))
+        rb_raise(rb_eArgError,
+            "too long unix socket path (%"PRIuSIZE" bytes given but %"PRIuSIZE" bytes max)",
+            (size_t)RSTRING_LEN(path), sizeof(un.sun_path));
 
     MEMZERO(&un, struct sockaddr_un, 1);
 
     un.sun_family = AF_UNIX;
     memcpy((void*)&un.sun_path, RSTRING_PTR(path), RSTRING_LEN(path));
 
-    init_addrinfo(rai, (struct sockaddr *)&un, (socklen_t)sizeof(un),
+    len = rsock_unix_sockaddr_len(path);
+    init_addrinfo(rai, (struct sockaddr *)&un, len,
 		  PF_UNIX, socktype, 0, Qnil, Qnil);
 }
 #endif
@@ -996,9 +1025,11 @@ inspect_sockaddr(VALUE addrinfo, VALUE ret)
           case AF_UNIX:
           {
             struct sockaddr_un *addr = (struct sockaddr_un *)&rai->addr;
-            char *p, *s, *t, *e;
+            char *p, *s, *e;
             s = addr->sun_path;
             e = (char*)addr + rai->sockaddr_len;
+            while (s < e && *(e-1) == '\0')
+                e--;
             if (e < s)
                 rb_str_cat2(ret, "too-short-AF_UNIX-sockaddr");
             else if (s == e)
@@ -1006,28 +1037,17 @@ inspect_sockaddr(VALUE addrinfo, VALUE ret)
             else {
                 int printable_only = 1;
                 p = s;
-                while (p < e && *p != '\0') {
+                while (p < e) {
                     printable_only = printable_only && ISPRINT(*p) && !ISSPACE(*p);
                     p++;
                 }
-                t = p;
-                while (p < e && *p == '\0')
-                    p++;
-                if (printable_only && /* only printable, no space */
-                    t < e && /* NUL terminated */
-                    p == e) { /* no data after NUL */
-		    if (s == t)
-			rb_str_cat2(ret, "empty-path-AF_UNIX-sockaddr");
-		    else if (s[0] == '/') /* absolute path */
-			rb_str_cat2(ret, s);
-		    else
-                        rb_str_catf(ret, "AF_UNIX %s", s);
+                if (printable_only) { /* only printable, no space */
+                    if (s[0] != '/') /* relative path */
+                        rb_str_cat2(ret, "AF_UNIX ");
+                    rb_str_cat(ret, s, p - s);
                 }
                 else {
                     rb_str_cat2(ret, "AF_UNIX");
-                    e = (char *)addr->sun_path + sizeof(addr->sun_path);
-                    while (s < e && *(e-1) == '\0')
-                        e--;
                     while (s < e)
                         rb_str_catf(ret, ":%02x", (unsigned char)*s++);
                 }
@@ -1201,7 +1221,7 @@ addrinfo_mdump(VALUE self)
         struct sockaddr_un *su = (struct sockaddr_un *)&rai->addr;
         char *s, *e;
         s = su->sun_path;
-        e = (char*)s + sizeof(su->sun_path);
+        e = (char*)su + rai->sockaddr_len;
         while (s < e && *(e-1) == '\0')
             e--;
         sockaddr = rb_str_new(s, e-s);
@@ -1298,12 +1318,14 @@ addrinfo_mload(VALUE self, VALUE ary)
       case AF_UNIX:
       {
         struct sockaddr_un uaddr;
-        memset(&uaddr, 0, sizeof(uaddr));
+        MEMZERO(&uaddr, struct sockaddr_un, 1);
         uaddr.sun_family = AF_UNIX;
 
         StringValue(v);
-        if (sizeof(uaddr.sun_path) <= (size_t)RSTRING_LEN(v))
-            rb_raise(rb_eSocket, "too long AF_UNIX path");
+        if (sizeof(uaddr.sun_path) < (size_t)RSTRING_LEN(v))
+            rb_raise(rb_eSocket,
+                "too long AF_UNIX path (%"PRIuSIZE" bytes given but %"PRIuSIZE" bytes max)",
+                (size_t)RSTRING_LEN(v), sizeof(uaddr.sun_path));
         memcpy(uaddr.sun_path, RSTRING_PTR(v), RSTRING_LEN(v));
         len = (socklen_t)sizeof(uaddr);
         memcpy(&ss, &uaddr, len);
diff --git a/ext/socket/rubysocket.h b/ext/socket/rubysocket.h
index 4c0efdb..ab05270 100644
--- a/ext/socket/rubysocket.h
+++ b/ext/socket/rubysocket.h
@@ -233,8 +233,9 @@ VALUE rsock_make_hostent(VALUE host, struct addrinfo *addr, VALUE (*ipaddr)(stru
 int rsock_revlookup_flag(VALUE revlookup, int *norevlookup);
 
 #ifdef HAVE_SYS_UN_H
-const char* rsock_unixpath(struct sockaddr_un *sockaddr, socklen_t len);
+VALUE rsock_unixpath_str(struct sockaddr_un *sockaddr, socklen_t len);
 VALUE rsock_unixaddr(struct sockaddr_un *sockaddr, socklen_t len);
+socklen_t rsock_unix_sockaddr_len(VALUE path);
 #endif
 
 int rsock_socket(int domain, int type, int proto);
diff --git a/ext/socket/socket.c b/ext/socket/socket.c
index 4613892..bfe2edb 100644
--- a/ext/socket/socket.c
+++ b/ext/socket/socket.c
@@ -954,13 +954,12 @@ sock_s_gethostbyaddr(int argc, VALUE *argv)
 {
     VALUE addr, family;
     struct hostent *h;
-    struct sockaddr *sa;
     char **pch;
     VALUE ary, names;
     int t = AF_INET;
 
     rb_scan_args(argc, argv, "11", &addr, &family);
-    sa = (struct sockaddr*)StringValuePtr(addr);
+    StringValue(addr);
     if (!NIL_P(family)) {
 	t = rsock_family_arg(family);
     }
@@ -1371,18 +1370,17 @@ static VALUE
 sock_s_pack_sockaddr_un(VALUE self, VALUE path)
 {
     struct sockaddr_un sockaddr;
-    char *sun_path;
     VALUE addr;
 
+    StringValue(path);
     MEMZERO(&sockaddr, struct sockaddr_un, 1);
     sockaddr.sun_family = AF_UNIX;
-    sun_path = StringValueCStr(path);
-    if (sizeof(sockaddr.sun_path) <= strlen(sun_path)) {
-        rb_raise(rb_eArgError, "too long unix socket path (max: %dbytes)",
-            (int)sizeof(sockaddr.sun_path)-1);
+    if (sizeof(sockaddr.sun_path) < (size_t)RSTRING_LEN(path)) {
+        rb_raise(rb_eArgError, "too long unix socket path (%"PRIuSIZE" bytes given but %"PRIuSIZE" bytes max)",
+            (size_t)RSTRING_LEN(path), sizeof(sockaddr.sun_path));
     }
-    strncpy(sockaddr.sun_path, sun_path, sizeof(sockaddr.sun_path)-1);
-    addr = rb_str_new((char*)&sockaddr, sizeof(sockaddr));
+    memcpy(sockaddr.sun_path, RSTRING_PTR(path), RSTRING_LEN(path));
+    addr = rb_str_new((char*)&sockaddr, rsock_unix_sockaddr_len(path));
     OBJ_INFECT(addr, path);
 
     return addr;
@@ -1404,7 +1402,6 @@ static VALUE
 sock_s_unpack_sockaddr_un(VALUE self, VALUE addr)
 {
     struct sockaddr_un * sockaddr;
-    const char *sun_path;
     VALUE path;
 
     sockaddr = (struct sockaddr_un*)SockAddrStringValuePtr(addr);
@@ -1420,13 +1417,7 @@ sock_s_unpack_sockaddr_un(VALUE self, VALUE addr)
 	rb_raise(rb_eTypeError, "too long sockaddr_un - %ld longer than %d",
 		 RSTRING_LEN(addr), (int)sizeof(struct sockaddr_un));
     }
-    sun_path = rsock_unixpath(sockaddr, RSTRING_LENINT(addr));
-    if (sizeof(struct sockaddr_un) == RSTRING_LEN(addr) &&
-        sun_path == sockaddr->sun_path &&
-        sun_path + strlen(sun_path) == RSTRING_PTR(addr) + RSTRING_LEN(addr)) {
-        rb_raise(rb_eArgError, "sockaddr_un.sun_path not NUL terminated");
-    }
-    path = rb_str_new2(sun_path);
+    path = rsock_unixpath_str(sockaddr, RSTRING_LENINT(addr));
     OBJ_INFECT(path, addr);
     return path;
 }
diff --git a/ext/socket/unixsocket.c b/ext/socket/unixsocket.c
index 26822e5..313428d 100644
--- a/ext/socket/unixsocket.c
+++ b/ext/socket/unixsocket.c
@@ -13,6 +13,7 @@
 #ifdef HAVE_SYS_UN_H
 struct unixsock_arg {
     struct sockaddr_un *sockaddr;
+    socklen_t sockaddrlen;
     int fd;
 };
 
@@ -21,13 +22,14 @@ unixsock_connect_internal(VALUE a)
 {
     struct unixsock_arg *arg = (struct unixsock_arg *)a;
     return (VALUE)rsock_connect(arg->fd, (struct sockaddr*)arg->sockaddr,
-			        (socklen_t)sizeof(*arg->sockaddr), 0);
+			        arg->sockaddrlen, 0);
 }
 
 VALUE
 rsock_init_unixsock(VALUE sock, VALUE path, int server)
 {
     struct sockaddr_un sockaddr;
+    socklen_t sockaddrlen;
     int fd, status;
     rb_io_t *fptr;
 
@@ -39,19 +41,21 @@ rsock_init_unixsock(VALUE sock, VALUE path, int server)
 
     MEMZERO(&sockaddr, struct sockaddr_un, 1);
     sockaddr.sun_family = AF_UNIX;
-    if (sizeof(sockaddr.sun_path) <= (size_t)RSTRING_LEN(path)) {
-        rb_raise(rb_eArgError, "too long unix socket path (max: %dbytes)",
-            (int)sizeof(sockaddr.sun_path)-1);
+    if (sizeof(sockaddr.sun_path) < (size_t)RSTRING_LEN(path)) {
+        rb_raise(rb_eArgError, "too long unix socket path (%ldbytes given but %dbytes max)",
+            RSTRING_LEN(path), (int)sizeof(sockaddr.sun_path));
     }
     memcpy(sockaddr.sun_path, RSTRING_PTR(path), RSTRING_LEN(path));
+    sockaddrlen = rsock_unix_sockaddr_len(path);
 
     if (server) {
-        status = bind(fd, (struct sockaddr*)&sockaddr, (socklen_t)sizeof(sockaddr));
+        status = bind(fd, (struct sockaddr*)&sockaddr, sockaddrlen);
     }
     else {
 	int prot;
 	struct unixsock_arg arg;
 	arg.sockaddr = &sockaddr;
+	arg.sockaddrlen = sockaddrlen;
 	arg.fd = fd;
         status = (int)rb_protect(unixsock_connect_internal, (VALUE)&arg, &prot);
 	if (prot) {
@@ -62,7 +66,7 @@ rsock_init_unixsock(VALUE sock, VALUE path, int server)
 
     if (status < 0) {
 	close(fd);
-	rb_sys_fail(sockaddr.sun_path);
+	rb_sys_fail_str(rb_inspect(path));
     }
 
     if (server) {
@@ -118,7 +122,7 @@ unix_path(VALUE sock)
 	socklen_t len = (socklen_t)sizeof(addr);
 	if (getsockname(fptr->fd, (struct sockaddr*)&addr, &len) < 0)
 	    rb_sys_fail(0);
-	fptr->pathv = rb_obj_freeze(rb_str_new_cstr(rsock_unixpath(&addr, len)));
+	fptr->pathv = rb_obj_freeze(rsock_unixpath_str(&addr, len));
     }
     return rb_str_dup(fptr->pathv);
 }
@@ -445,11 +449,13 @@ unix_peeraddr(VALUE sock)
     rb_io_t *fptr;
     struct sockaddr_un addr;
     socklen_t len = (socklen_t)sizeof addr;
+    socklen_t len0 = len;
 
     GetOpenFile(sock, fptr);
 
     if (getpeername(fptr->fd, (struct sockaddr*)&addr, &len) < 0)
 	rb_sys_fail("getpeername(2)");
+    if (len0 < len) len = len0;
     return rsock_unixaddr(&addr, len);
 }
 
diff --git a/test/socket/test_unix.rb b/test/socket/test_unix.rb
index b4c4592..3559eb8 100644
--- a/test/socket/test_unix.rb
+++ b/test/socket/test_unix.rb
@@ -324,8 +324,11 @@ class TestSocket_UNIXSocket < Test::Unit::TestCase
     assert_raise(ArgumentError) { UNIXServer.new("a" * 300) }
   end
 
-  def test_nul
-    assert_raise(ArgumentError) { Socket.sockaddr_un("a\0b") }
+  def test_abstract_namespace
+    return if /linux/ !~ RUBY_PLATFORM
+    addr = Socket.pack_sockaddr_un("\0foo")
+    assert_match(/\0foo\z/, addr)
+    assert_equal("\0foo", Socket.unpack_sockaddr_un(addr))
   end
 
   def test_dgram_pair
@@ -507,4 +510,69 @@ class TestSocket_UNIXSocket < Test::Unit::TestCase
     }
   end
 
+  def test_abstract_unix_server
+    return if /linux/ !~ RUBY_PLATFORM
+    name = "\0ruby-test_unix"
+    s0 = nil
+    UNIXServer.open(name) {|s|
+      assert_equal(name, s.local_address.unix_path)
+      s0 = s
+      UNIXSocket.open(name) {|c|
+        sock = s.accept
+        begin
+          assert_equal(name, c.remote_address.unix_path)
+        ensure
+          sock.close
+        end
+      }
+    }
+    assert(s0.closed?)
+  end
+
+  def test_abstract_unix_socket_econnrefused
+    return if /linux/ !~ RUBY_PLATFORM
+    name = "\0ruby-test_unix"
+    assert_raise(Errno::ECONNREFUSED) do
+      UNIXSocket.open(name) {}
+    end
+  end
+
+  def test_abstract_unix_server_socket
+    return if /linux/ !~ RUBY_PLATFORM
+    name = "\0ruby-test_unix"
+    s0 = nil
+    Socket.unix_server_socket(name) {|s|
+      assert_equal(name, s.local_address.unix_path)
+      s0 = s
+      Socket.unix(name) {|c|
+        sock, = s.accept
+        begin
+          assert_equal(name, c.remote_address.unix_path)
+        ensure
+          sock.close
+        end
+      }
+    }
+    assert(s0.closed?)
+  end
+
+  def test_autobind
+    return if /linux/ !~ RUBY_PLATFORM
+    s0 = nil
+    Socket.unix_server_socket("") {|s|
+      name = s.local_address.unix_path
+      assert_match(/\A\0[0-9a-f]{5}\z/, name)
+      s0 = s
+      Socket.unix(name) {|c|
+        sock, = s.accept
+        begin
+          assert_equal(name, c.remote_address.unix_path)
+        ensure
+          sock.close
+        end
+      }
+    }
+    assert(s0.closed?)
+  end
+
 end if defined?(UNIXSocket) && /cygwin/ !~ RUBY_PLATFORM
