private void writeObject(ObjectOutputStream o) throws IOException { o.defaultWriteObject(); o.writeObject(path()); }
/** * Returns a human readable path. * On Linux, AF_UNIX sockets can be bound/connected in abstract namespace. * This is denoted by a leading NUL byte in the path. * In order to be properly displayed, this method returns a path prefixed * by '@' like netstat, lsof an similar tools. * @return The human readable path of this address. */ public String humanReadablePath() { String ret = path(); // Handle abstract namespace like netstat: replace NUL by '@' if (ret.indexOf('\000') == 0) { return ret.replace('\000', '@'); } return ret; }
@JRubyMethod public IRubyObject canonname(ThreadContext context) { if (socketAddress instanceof InetSocketAddress) { return context.runtime.newString(getInetSocketAddress().getAddress().getCanonicalHostName()); } else if (socketAddress instanceof UnixSocketAddress) { return context.runtime.newString(getUnixSocketAddress().path()); } throw context.runtime.newNotImplementedError("canonname not implemented for socket address: " + socketAddress); }
@JRubyMethod public IRubyObject canonname(ThreadContext context) { if (socketAddress instanceof InetSocketAddress) { return context.runtime.newString(getInetSocketAddress().getAddress().getCanonicalHostName()); } else if (socketAddress instanceof UnixSocketAddress) { return context.runtime.newString(getUnixSocketAddress().path()); } throw context.runtime.newNotImplementedError("canonname not implemented for socket address: " + socketAddress); }
@JRubyMethod public IRubyObject inspect_sockaddr(ThreadContext context) { if (socketAddress instanceof UnixSocketAddress) { String path = getUnixSocketAddress().path(); return context.runtime.newString(path.startsWith("/") ? path : "UNIX " + path); } int port = getInetSocketAddress().getPort(); if (getInetAddress() instanceof Inet6Address) { String host = ipv6_ip(); String hostPort = port == 0 ? host : "[" + host + "]:" + port; return context.runtime.newString(hostPort); } String portString = port == 0 ? "" : ":" + port; String host = getInetSocketAddress().getAddress().getHostAddress(); return context.runtime.newString(host + portString); }
@JRubyMethod public IRubyObject inspect_sockaddr(ThreadContext context) { if (socketAddress instanceof UnixSocketAddress) { String path = getUnixSocketAddress().path(); return context.runtime.newString(path.startsWith("/") ? path : "UNIX " + path); } int port = getInetSocketAddress().getPort(); if (getInetAddress() instanceof Inet6Address) { String host = ipv6_ip(); String hostPort = port == 0 ? host : "[" + host + "]:" + port; return context.runtime.newString(hostPort); } String portString = port == 0 ? "" : ":" + port; String host = getInetSocketAddress().getAddress().getHostAddress(); return context.runtime.newString(host + portString); }
@JRubyMethod public IRubyObject unix_path(ThreadContext context) { if (getAddressFamily() != AF_UNIX) { throw SocketUtils.sockerr(context.runtime, "need AF_UNIX address"); } return context.runtime.newString(getUnixSocketAddress().path()); }
@JRubyMethod(name = "getpeername") public IRubyObject getpeername(ThreadContext context) { Ruby runtime = context.runtime; InetSocketAddress sock = getInetRemoteSocket(); if (sock != null) return Sockaddr.pack_sockaddr_in(context, sock); UnixSocketAddress unix = getUnixRemoteSocket(); return Sockaddr.pack_sockaddr_un(context, unix.path()); }
@JRubyMethod public IRubyObject unix_path(ThreadContext context) { if (getAddressFamily() != AF_UNIX) { throw SocketUtils.sockerr(context.runtime, "need AF_UNIX address"); } return context.runtime.newString(getUnixSocketAddress().path()); }
@JRubyMethod(name = "getpeername") public IRubyObject getpeername(ThreadContext context) { Ruby runtime = context.runtime; InetSocketAddress sock = getInetRemoteSocket(); if (sock != null) return Sockaddr.pack_sockaddr_in(context, sock); UnixSocketAddress unix = getUnixRemoteSocket(); return Sockaddr.pack_sockaddr_un(context, unix.path()); }
@JRubyMethod public IRubyObject peeraddr(ThreadContext context) { final Ruby runtime = context.runtime; final String _path = getUnixRemoteSocket().path(); final RubyString path = (_path == null) ? RubyString.newEmptyString(runtime) : runtime.newString(_path); return runtime.newArray( runtime.newString("AF_UNIX"), path ); }
@JRubyMethod public IRubyObject peeraddr(ThreadContext context) { final Ruby runtime = context.runtime; final String _path = getUnixRemoteSocket().path(); final RubyString path = (_path == null) ? RubyString.newEmptyString(runtime) : runtime.newString(_path); return runtime.newArray( runtime.newString("AF_UNIX"), path ); }
protected IRubyObject getSocknameCommon(ThreadContext context, String caller) { if (getInetSocketAddress() != null) { return Sockaddr.pack_sockaddr_in(context, getInetSocketAddress()); } if (getUnixSocketAddress() != null) { return Sockaddr.pack_sockaddr_un(context, getUnixSocketAddress().path()); } return Sockaddr.pack_sockaddr_in(context, 0, "0.0.0.0"); }
protected IRubyObject getSocknameCommon(ThreadContext context, String caller) { if (getInetSocketAddress() != null) { return Sockaddr.pack_sockaddr_in(context, getInetSocketAddress()); } if (getUnixSocketAddress() != null) { return Sockaddr.pack_sockaddr_un(context, getUnixSocketAddress().path()); } return Sockaddr.pack_sockaddr_in(context, 0, "0.0.0.0"); }
@JRubyMethod public IRubyObject local_address(ThreadContext context) { Ruby runtime = context.runtime; InetSocketAddress address = getInetSocketAddress(); if (address != null) { SocketType socketType = SocketType.forChannel(getChannel()); return new Addrinfo(runtime, runtime.getClass("Addrinfo"), address, socketType.getSocketType(), socketType); } UnixSocketAddress unix = getUnixSocketAddress(); return Addrinfo.unix(context, runtime.getClass("Addrinfo"), runtime.newString(unix.path())); }
@JRubyMethod public IRubyObject local_address(ThreadContext context) { Ruby runtime = context.runtime; InetSocketAddress address = getInetSocketAddress(); if (address != null) { SocketType socketType = SocketType.forChannel(getChannel()); return new Addrinfo(runtime, runtime.getClass("Addrinfo"), address, socketType.getSocketType(), socketType); } UnixSocketAddress unix = getUnixSocketAddress(); return Addrinfo.unix(context, runtime.getClass("Addrinfo"), runtime.newString(unix.path())); }
@JRubyMethod(optional = 1) public IRubyObject getnameinfo(ThreadContext context, IRubyObject[] args) { Ruby runtime = context.runtime; RubyString hostname; InetSocketAddress inet = getInetSocketAddress(); if (inet != null) { hostname = runtime.newString(inet.getHostName()); } else { UnixSocketAddress unix = getUnixSocketAddress(); hostname = runtime.newString(unix.path()); } RubyString rubyService = null; if (args.length > 0) { int flags = args[0].convertToInteger().getIntValue(); if ((flags & NameInfo.NI_NUMERICSERV.intValue()) != 0) { rubyService = runtime.newString(Integer.toString(getPort())); } } if (rubyService == null) { Service service = Service.getServiceByPort(getPort(), protocol.getName()); rubyService = runtime.newString(service.getName()); } return runtime.newArray(hostname, rubyService); }
@JRubyMethod public IRubyObject remote_address(ThreadContext context) { Ruby runtime = context.runtime; InetSocketAddress address = getInetRemoteSocket(); if (address != null) { SocketType socketType = SocketType.forChannel(getChannel()); return new Addrinfo(runtime, runtime.getClass("Addrinfo"), address, socketType.getSocketType(), socketType); } UnixSocketAddress unix = getUnixRemoteSocket(); if (unix != null) { return Addrinfo.unix(context, runtime.getClass("Addrinfo"), runtime.newString(unix.path())); } throw runtime.newErrnoENOTCONNError(); }
@JRubyMethod public IRubyObject remote_address(ThreadContext context) { Ruby runtime = context.runtime; InetSocketAddress address = getInetRemoteSocket(); if (address != null) { SocketType socketType = SocketType.forChannel(getChannel()); return new Addrinfo(runtime, runtime.getClass("Addrinfo"), address, socketType.getSocketType(), socketType); } UnixSocketAddress unix = getUnixRemoteSocket(); if (unix != null) { return Addrinfo.unix(context, runtime.getClass("Addrinfo"), runtime.newString(unix.path())); } throw runtime.newErrnoENOTCONNError(); }